mysql table edit form not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moran1409
Forum Newbie
Posts: 13
Joined: Wed Feb 23, 2011 12:45 pm

mysql table edit form not working

Post 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...
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: mysql table edit form not working

Post by DigitalMind »

I can't see any code where you're trying to insert new data.
BTW your code is perfect for SQL injections.
moran1409
Forum Newbie
Posts: 13
Joined: Wed Feb 23, 2011 12:45 pm

Re: mysql table edit form not working

Post 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
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: mysql table edit form not working

Post by DigitalMind »

$id is undefined. I think you wanted to use $_POST['id'] instead.
moran1409
Forum Newbie
Posts: 13
Joined: Wed Feb 23, 2011 12:45 pm

Re: mysql table edit form not working

Post 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
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: mysql table edit form not working

Post by DigitalMind »

$_POST[id]?
moran1409
Forum Newbie
Posts: 13
Joined: Wed Feb 23, 2011 12:45 pm

Re: mysql table edit form not working

Post 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...
moran1409
Forum Newbie
Posts: 13
Joined: Wed Feb 23, 2011 12:45 pm

Re: mysql table edit form not working

Post by moran1409 »

any help please?????
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: mysql table edit form not working

Post 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]
moran1409
Forum Newbie
Posts: 13
Joined: Wed Feb 23, 2011 12:45 pm

Re: mysql table edit form not working

Post by moran1409 »

i added it still doesn't work
Post Reply