CrownVictoriaCop Posted October 20, 2009 Share Posted October 20, 2009 Hello, Here's what I'm trying to do. Build a page where a user enters a MySQL row number in. Then, a new page appears with an HTML form where the user can edit the information in that row. Like for example, there's an input field for name, address, phone, etc. How would I possibly do this? I tried looking online, but nothing is working for me. Anthony Link to comment https://forums.phpfreaks.com/topic/178300-edit-mysql-row-using-php-and-html-form/ Share on other sites More sharing options...
Garethp Posted October 20, 2009 Share Posted October 20, 2009 Search: <form action="Show.php"> Row Number: <input type="text" name="Row"> <input type="submit"> </form> Show.php" <?php //Database Login Details here if(isset($_POST['Row'])) { $Row = mysql_real_escape_string($_POST['Row']); $Search = mysql_select("SELECT * FROM `table` WHERE `ID`='$Row'"); $Search = mysql_fetch_assoc($Search); echo "<form action=\"\" method=\"post\"> ID: <input type=\"text\" name=\"RowID\"><br>"; foreach($Search as $k=>$v) { echo "$k: <input type=\"text\" name=\"$k\" value=\"$v\"><br>"; } echo "<input type=\"submit\" value=\"Edit\">"; } if(isset($_POST['RowID'])) { $RowID = mysql_real_escape_string($_POST['RowID']); foreach($_POST as $k=>$v) { if($k == "submit" || $k == "RowID") { continue; } $k = mysql_real_escape_string($k); $v = mysql_real_escape_string($v); mysql_query("UPDATE `table` SET `$k`='$v' WHERE ID='$RowID'"); } } ?> Just enter your login details, and if it doesn't work, under $Search = mysql_fetch_assoc($Search); add $Search=$Search[0]; as a test I haven't tested this, and I probably won't Link to comment https://forums.phpfreaks.com/topic/178300-edit-mysql-row-using-php-and-html-form/#findComment-940182 Share on other sites More sharing options...
Gayner Posted October 20, 2009 Share Posted October 20, 2009 mysql_Realescape that.. Link to comment https://forums.phpfreaks.com/topic/178300-edit-mysql-row-using-php-and-html-form/#findComment-940193 Share on other sites More sharing options...
Garethp Posted October 20, 2009 Share Posted October 20, 2009 Where am I missing an escape? I thought I used real escape on all my inputs Link to comment https://forums.phpfreaks.com/topic/178300-edit-mysql-row-using-php-and-html-form/#findComment-940200 Share on other sites More sharing options...
CrownVictoriaCop Posted October 20, 2009 Author Share Posted October 20, 2009 Nothing shows up on the results page. [code]<?php $dbhost = 'localhost'; $dbuser = 'safetyfi_secure'; $dbpass = 'hidden'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'safetyfi_students'; mysql_select_db($dbname); if(isset($_POST['Row'])) { $Row = mysql_real_escape_string($_POST['Row']); $Search = mysql_select("SELECT * FROM Students WHERE `ID`='$Row'"); $Search = mysql_fetch_assoc($Search); echo "<form action=\"\" method=\"post\"> ID: <input type=\"text\" name=\"RowID\"><br>"; foreach($Search as $k=>$v) { echo "$k: <input type=\"text\" name=\"$k\" value=\"$v\"><br>"; } echo "<input type=\"submit\" value=\"Edit\">"; } if(isset($_POST['RowID'])) { $RowID = mysql_real_escape_string($_POST['RowID']); foreach($_POST as $k=>$v) { if($k == "submit" || $k == "RowID") { continue; } $k = mysql_real_escape_string($k); $v = mysql_real_escape_string($v); mysql_query("UPDATE `table` SET `$k`='$v' WHERE ID='$RowID'"); } } ?> Link to comment https://forums.phpfreaks.com/topic/178300-edit-mysql-row-using-php-and-html-form/#findComment-940365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.