Page 1 of 1

mysql table edit form not working

Posted: Sat Feb 26, 2011 9:51 am
by moran1409
hi all, I'm trying to edit mysql table data from the browser using these:

edit_form.php:

Code: Select all

	      <?
	      include "db.inc.php";//database connection
	      $order = "SELECT * FROM prices where id_number='$id'";
	      $result = mysql_query($order);
	      $row = mysql_fetch_array($result);
	      ?>
	      <form method="post" action="edit_data.php">
	      <input type="hidden" name="id" value="<? echo "$row[id_number]"?>">
	        <tr>       
	          <td>Product</td>
	          <td>
	            <input type="text" name="product"
	        size="20" value="<? echo "$row[product]"?>">
	          </td>
	        </tr>
	        <tr>
	          <td>Price</td>
	          <td>
	            <input type="text" name="price" size="40"
	          value="<? echo "$row[price]"?>">
	          </td>
	        </tr>
	        <tr>
	          <td align="right">
	            <input type="submit"
	          name="submit value" value="Edit">
	          </td>
	        </tr>
	      </form>
edit_data.php:

Code: Select all

	include "db.inc.php";
	$order = "UPDATE prices SET product='$_POST[product]', price='$_POST[price]' WHERE id_number='$id'";
	mysql_query($order);
	header("location:edit.php");
edit.php:

Code: Select all

	      include"db.inc.php";//database connection
	      $order = "SELECT * FROM prices";
	      $result = mysql_query($order);
	      while ($row=mysql_fetch_array($result)){
	        echo ("<tr><td>$row[id_number]</td>");
	        echo ("<td>$row[product]</td>");
	        echo ("<td>$row[price]</td>");
	        echo ("<td><a href=\"edit_form.php?id=$row[id_number]\">Edit</a></td></tr>");
	      }
this is the table:

CREATE TABLE IF NOT EXISTS `prices` (
`id_number` int(3) NOT NULL,
`product` varchar(30) DEFAULT NULL,
`price` int(6) DEFAULT NULL,
PRIMARY KEY (`id_number`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

everything is displayed correctly but when i try to insert new data it's not changing anything...

Re: mysql table edit form not working

Posted: Sat Feb 26, 2011 11:00 am
by DigitalMind
I can't see any code where you're trying to insert new data.
BTW your code is perfect for SQL injections.

Re: mysql table edit form not working

Posted: Sun Feb 27, 2011 8:39 am
by moran1409
the user should put the changes in the edit_form and the mysql data should change accordingly... it doesn't!!!
i need help

Re: mysql table edit form not working

Posted: Sun Feb 27, 2011 9:40 am
by DigitalMind
$id is undefined. I think you wanted to use $_POST['id'] instead.

Re: mysql table edit form not working

Posted: Sun Feb 27, 2011 12:16 pm
by moran1409
$id is undefined. I think you wanted to use $_POST['id'] instead.
this causes a parse error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in D:\Project Db\xampplite\htdocs\photo\edit_data.php on line 4

Re: mysql table edit form not working

Posted: Sun Feb 27, 2011 1:33 pm
by DigitalMind
$_POST[id]?

Re: mysql table edit form not working

Posted: Sun Feb 27, 2011 2:47 pm
by moran1409
edit.php is the first one it calls edit_form and edit_form calls edit_data,
look at edit.php: id=$row[id_number]
id is defined not posted by the user that is not the problem...

Re: mysql table edit form not working

Posted: Mon Feb 28, 2011 9:58 am
by moran1409
any help please?????

Re: mysql table edit form not working

Posted: Mon Feb 28, 2011 1:52 pm
by DigitalMind
moran1409 wrote:edit.php is the first one it calls edit_form and edit_form calls edit_data,
look at edit.php: id=$row[id_number]
id is defined not posted by the user that is not the problem...
in that case use $_GET[id]

Re: mysql table edit form not working

Posted: Mon Feb 28, 2011 2:55 pm
by moran1409
i added it still doesn't work