Pradeep_Chinna Posted August 2, 2013 Share Posted August 2, 2013 After clicking edit link(see one.jpg), it is going to edit_form.php(see one.jpg) and taking ID also but NOT displaying anything in my textfields. PLEASE HELP ME OUT... main code in edit.php: echo ("<td><a href=\"edit_form.php?number=$row[iD]\">Edit</a></td></tr>");edit_form.php: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Form Edit Data</title> </head> <body> <table border="1"> <tr> <td align=center>Form Edit Employees Data</td> </tr> <tr> <td> <table> <?php error_reporting(0); // Connect to the database $con = mysql_connect("localhost","admin",""); // Make sure we connected succesfully if(! $con) { die('Connection Failed'.mysql_error()); } // Select the database to use mysql_select_db("test",$con); $order = "SELECT * FROM budget where ID= '$number' "; $result = mysql_query($order); $row = mysql_fetch_array($result); ?> <form method="post" action="edit_data.php"> <input type="hidden" name="ID" value="<?php echo "$row[iD]" ?>"> <tr> <td>AMOUNT</td> <td> <input type="text" name="amount" size="20" value="<?php echo "$row[AMOUNT]"?>"> </td> </tr> <tr> <td>PUPOSE</td> <td> <input type="text" name="purpose" size="40" value="<?php echo "$row[PURPOSE]"?>"> </td> </tr> <tr> <td>DATE</td> <td> <input type="text" name="date" size="40" value="<?php echo "$row[DATE]"?>"> </td> </tr> <tr> <td>NAME</td> <td> <input type="text" name="name" size="20" value=" <?php echo "$row[NAME]"?> "> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit value" value="Edit"> </td> </tr> </form> </table> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/280743-editing-date/ Share on other sites More sharing options...
PravinS Posted August 2, 2013 Share Posted August 2, 2013 you need to use $_GET as you are passing variable through query string add below code at the top in edit_form.php page $number = trim($_GET['number']); Quote Link to comment https://forums.phpfreaks.com/topic/280743-editing-date/#findComment-1443087 Share on other sites More sharing options...
PaulRyan Posted August 2, 2013 Share Posted August 2, 2013 In future, please use the code tags. Try this: <?PHP $con = mysql_connect('127.0.0.1', 'root', ''); if(!$con) { die('Connection Failed: '.mysql_error()); } else { mysql_select_db('test', $con); } //### Assign get variable, if it exists $rowID = isset($_GET['number']) ? (int)$_GET['number'] : FALSE ; //### If the number doesn't exist, display error if(empty($rowID)) { echo 'No row selected to edit.'; exit; } //### Select row from database table $dbQuery = "SELECT * FROM `budget` WHERE `ID` = {$rowID}"; $dbResult = mysql_query($dbQuery) or die(mysql_error()); //### Check if a row was returned if(!mysql_num_rows($dbResult)) { echo 'No row was returned.'; exit; } else { $row = mysql_fetch_assoc($dbResult); } ?> <form method="post" action="edit_data.php"> <input type="hidden" name="ID" value="<?PHP echo $row['ID']; ?>"> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td> AMOUNT </td> <td> <input type="text" name="amount" size="20" value="<?PHP echo $row['AMOUNT']; ?>"> </td> </tr> <tr> <td> PUPOSE </td> <td> <input type="text" name="purpose" size="40" value="<?PHP echo $row['PURPOSE']; ?>"> </td> </tr> <tr> <td> DATE </td> <td> <input type="text" name="date" size="40" value="<?PHP echo $row['DATE']; ?>"> </td> </tr> <tr> <td> NAME </td> <td> <input type="text" name="name" size="20" value="<?PHP echo $row['NAME']; ?>"> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit value" value="Edit"> </td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/280743-editing-date/#findComment-1443123 Share on other sites More sharing options...
cyberRobot Posted August 2, 2013 Share Posted August 2, 2013 Note that you should validate the number before running the query to prevent SQL injections. If the validation fails, show an error message and avoid running the query. For example, you can make sure you have a number by doing something like the following: <?php $_GET['number'] = trim($_GET['number']); if(!ctype_digit((string)$_GET['number'])) { echo 'Unknown number'; exit(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/280743-editing-date/#findComment-1443132 Share on other sites More sharing options...
Pradeep_Chinna Posted August 3, 2013 Author Share Posted August 3, 2013 I got it Thanks alot everyone Quote Link to comment https://forums.phpfreaks.com/topic/280743-editing-date/#findComment-1443310 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.