views:

50

answers:

1

Thanks for all your help, I now have add, update, and delete functions on my database manipulation program. But I'm having difficulty on searching for records in mysql database. Please help me in correcting my codes, and if you know a site that I can use as my reference please do tell. Thanks, here is my search code:

         <?php
      $con = mysql_connect("localhost","root","");
      if (!$con)
   {
     die('Could not connect: ' . mysql_error());
   }

      mysql_select_db("koro", $con);

     mysql_query("UPDATE student 
    WHERE IDNUMBER ='$_POST[INAME]'");

    while ($row = mysql_fetch_array($query)) 
    { 
      $variable1=$row["IDNUMBER"]; 
      $variable2=$row["LNAME"]; 
      $variable3=$row["FNAME"]; 
      $variable3=$row["MNAME"]; 
      $variable3=$row["GRADEYR"]; 
      $variable3=$row["ADDRESS"]; 
          } 

       mysql_close($con);

      ?>

And here is the html form that I'm using, and I think this is where the problem is. I don't have any idea on how to put the results in the text box.

+2  A: 

Check the documentation for mysql_query: it returns TRUE or FALSE for UPDATE queries. If you want the new values, follow the UPDATE with a select.

More importantly, your code is vulnerable to SQL injection. The best solution is to switch from the outdated mysql driver to PDO.

Unpacking an array into separate variables (as you do) is unnecessary. It's also problematic: notice how you've mistyped the last few names as $variable3.

Also, don't use "or die" (except in very limited circumstances).

outis
+1 for advocating the use of PDO.
fireeyedboy