jamesyrawr Posted October 29, 2010 Share Posted October 29, 2010 here are the three pages i am using to alter information stored in my database editrow.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <table> <tr> <td align="center">EDIT DATA</td> </tr> <tr> <td> <table border="1"> <?php include"include/connect.php";//database connection $order = "SELECT * FROM products"; $result = mysql_query($order); while ($row=mysql_fetch_array($result)){ print " <td>" . $row["prod_id"] . "</td>"; print " <td>" . $row["prod_name"]. "</td>"; print " <td>" . $row["prod_price"] . "</td>"; print " <td>" . $row["prod_desc"]. "</td>"; print " <td>" . $row["prod_colour"] . "</td>"; print ("<td><a href=\"editform.php?id=$row[prod_id]\">Edit</a></td></tr>"); } ?> </table> </td> </tr> </table> </body> </html> then editform.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <table border=1> <tr> <td align=center>Form Edit Employees Data</td> </tr> <tr> <td> <table> <?php include "include/connect.php";//database connection $id = $_GET['id']; $order = "SELECT * FROM products WHERE prod_id='$id'"; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> <form method="post" action="include/updatedata.php"> <input type="hidden" name="prodid" value="<? echo "$row[prod_id]"?>"> <tr> <td>Name</td> <td> <input type="text" name="prodname" size="20" value="<?php echo "$row[prod_name]"?>"> </td> </tr> <tr> <td>Address</td> <td> <input type="text" name="prodprice" size="40" value="<?php echo "$row[prod_price]"?>"> </td> </tr> <tr> <td>Address</td> <td> <input type="text" name="proddesc" size="40" value="<?php echo "$row[prod_desc]"?>"> </td> </tr> <tr> <td>Address</td> <td> <input type="text" name="prodcolour" size="40" value="<?php echo "$row[prod_colour]"?>"> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit value" value="Edit"> </td> </tr> </form> </table> </td> </tr> </table> </body> </html> now here it all goes weird i get this error Notice: Undefined index: $id in C:\wamp\www\uniwork\include\updatedata.php on line 4 but without it it doesnt know how to get the information from the previous form. include/updatedata.php <?php //edit_data.php include "connect.php"; $id=$_GET['$id']; $order = "UPDATE products SET prod_name='prodname', prod_price='prodprice', prod_desc='proddesc', prod_colour='prodcolour' WHERE prod_id='$id'"; mysql_query($order); header("location:updatedata.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/ Share on other sites More sharing options...
Yucky Posted October 29, 2010 Share Posted October 29, 2010 It should be $_GET['id'], not $_GET['$id']; Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/#findComment-1128212 Share on other sites More sharing options...
jamesyrawr Posted October 30, 2010 Author Share Posted October 30, 2010 it still doesn't seem to have fixed it thanks though Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/#findComment-1128219 Share on other sites More sharing options...
Yucky Posted October 30, 2010 Share Posted October 30, 2010 Should have spotted this earlier, sorry. <form method="post" action="include/updatedata.php"> Change it to: <form method="get" action="include/updatedata.php"> $_GET takes values from the requested address. For example, updatedata.php?id=1 would set $_GET['id'] to 1. Submitting a form using post would set the values in the $_POST global array. $_REQUEST is a combination of both, although I steer clear of it. Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/#findComment-1128225 Share on other sites More sharing options...
jamesyrawr Posted October 30, 2010 Author Share Posted October 30, 2010 ahh thanks learned something there but now im getting this error Parse error: parse error in C:\wamp\www\uniwork\include\updatedata.php on line 4 in this piece of code <?php //edit_data.php include "connect.php"; $prod $_GET['id']; $order = "UPDATE products SET prod_name='prodname', prod_price='prodprice', prod_desc='proddesc', prod_colour='prodcolour' WHERE prod_id='$prod'"; mysql_query($order); header("location:updatedata.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/#findComment-1128247 Share on other sites More sharing options...
Goldeneye Posted October 30, 2010 Share Posted October 30, 2010 $prod $_GET['id']; should be... $prod = $_GET['id']; Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/#findComment-1128257 Share on other sites More sharing options...
jamesyrawr Posted October 30, 2010 Author Share Posted October 30, 2010 thanks but it seems to be one error after another after making the adjustment i get this Notice: Undefined index: id in C:\wamp\www\uniwork\include\updatedata.php on line 4 Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/#findComment-1128259 Share on other sites More sharing options...
Pikachu2000 Posted October 30, 2010 Share Posted October 30, 2010 Since the query can't run properly without the value of $_GET['id'], use a conditional to check if $_GET['id'] is set before allowing it to. if( isset($_GET['id']) ) { include "connect.php"; $prod = $_GET['id']; // if $_GET['id'] is expected to always be an integer, use $prod = (int) $_GET['id']; $order = "UPDATE products SET prod_name='prodname', prod_price='prodprice', prod_desc='proddesc', prod_colour='prodcolour' WHERE prod_id='$prod'"; mysql_query($order); header("location:updatedata.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/217254-can-someone-help-me-get-this-code-working-please/#findComment-1128265 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.