Welcome! Log In Create A New Profile

Advanced

Assignment 2 Update HELP

Posted by WPJones123 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Assignment 2 Update HELP
February 27, 2012 09:14AM
Hi,

I am having problems in updating data in mysql. I have tried to update only the "prise" under products but with no luck. I am missing the plot here.
I tried to echo the prise value to see what actually is in it but that also comes up empty. Once i click on the update button my web page is refreshed with the old data.


Please help

Kind Regards
Warren


Language: PHP
  1. <?php
  2. //error_reporting(0);
  3. include ("connect.php");
  4. $id=$_GET[';prod_id';];
  5. $query = "SELECT * FROM PRODUCT WHERE prod_id=';$id';"; // read data from user table and sort by prod_id
  6. $result = mysql_query($query)
  7.  
  8. or die("Query failed: " . mysql_error()); //Check if connect in has been made and that database ex
  9.  
  10.  
  11. if ($row = mysql_fetch_array($result))
  12. {
  13. $prod_id=$row[';prod_id';];
  14. $prod_name=$row[';prod_name';];
  15. $prod_desc=$row[';prod_desc';];
  16. $prise=$row[';prise';];
  17.  
  18. echo "<form method=';POST';>";
  19. echo "Product ID :";
  20. echo "<td>","<input type=\"text\" name=\"prod_desc\" value=\"$prod_id\">","</td>";
  21. echo "<tr>","<td>","Product Name :","</td>";
  22. echo "<td>","<input type=\"text\" name=\"prod_name\" value=\"$prod_name\">","</td>";
  23. echo "<tr>","<td>","Description :","</td>","<td>","<input type=\"text\" name=\"prod_desc\" value=\"$prod_desc\">","</td>";
  24. echo "<tr>","<td>","Prise : ","</td>","<td>","<input type=\"text\" name=\"prise\" value=\"$prise\">","</td>";
  25. echo "<td>","<div align=';center';><input type=';submit'; name=';submit'; value=';Submit'; /></div></td></form>";
  26. echo "</table>";
  27.  
  28. if(isset($_POST[';submit';]))
  29. {
  30. $sql = ("UPDATE product SET prise=';$prise'; WHERE prod_id=';$prod_id'; ");
  31. //header(';location:test.php';);
  32. }
  33.  
  34.  
  35. mysql_close($db_connect);
  36.  
  37. }
  38. ?>
avatar Re: Assignment 2 Update HELP
February 27, 2012 11:06AM
Just read properly the tutorial letter on update, delete and edit so you will see where you did wrong;
because you must identify the row id when you send the information other ways is not going to work.
Re: Assignment 2 Update HELP
February 27, 2012 11:48AM
Just had a quick look at your code...

But you are simply setting your $sql variable with the string value of your update statement. You are not yet executing the update statement from your $sql variable.

You did it correctly for your select statement though....

Also trapping and displaying the result of your update statement execution could help you to locate any errors in your update statement.... like case sensitive issues for example.

---------------------------------------------------------------------
Live life...
---------------------------------------------------------------------
Sorry, you do not have permission to post/reply in this forum.