|  | Posted by ZafT on 06/15/09 11:55 
Hi all - thanks in advance for any help.
 I am trying to write a simple update script.  In fact, I am re-using code
 that I've used before (successfully) but I can't figure out why it is not
 working.  The script completes without any errors, but does not actually
 update the database.
 
 Also, the "check for same name" query works fine, and will return the proper
 error if a duplicate is found.
 
 Thanks again!
 Shane
 
 Here is the code - pretty simple...
 
 <?PHP
 require('header.php');
 require('config.php');
 
 mysql_connect($dbserver,$username,$password)
 or die( "Unable to connect");
 @mysql_select_db($database)
 or die( "Unable to select database");
 
 $id=$_POST['id'];
 $name=$_POST['name'];
 $description=$_POST['description'];
 $show=$_POST['show'];
 
 ?>
 
 <TABLE width=500 cellpadding="15">
 <TR>
 <TD>
 
 <H1><font face="verdana">Edit Project</H1>
 <font face="verdana">
 
 <?php
 
 echo "$id <BR>";
 echo "$name <BR>";
 echo "$description <BR>";
 echo "$show <BR>";
 
 $query="SELECT * FROM project WHERE name = '$name'";
 $result=mysql_query($query);
 $num=mysql_numrows($result);
 
 //echo $num;
 
 //Check to see if there is already a project with the name
 //we are trying to change to.  Ignore if the id is the same
 //since this just means there was no name change.
 
 if($num > 0){
 $conflictid=mysql_result($result,0,"id");
 if(!($id==$conflictid)){
 die("Error: There is already a project with that
 name in the database. Please try again.");
 }
 else{
 
 $query="UPDATE project SET name='$name',
 description='$description',
 show='$show'
 WHERE id=$id";
 mysql_query($query);
 
 echo "Record Updated";
 
 }
 
 }
 
 else{
 
 $query="UPDATE project SET name='$name',
 description='$description',
 show='$show'
 WHERE id=$id";
 mysql_query($query);
 
 echo "Record Updated";
 
 }
 
 mysql_close();
 ?>
 
 </TD>
 </TR>
 </TABLE>
 <?php
 require('footer.php');
 ?>
  Navigation: [Reply to this message] |