RickChase Posted April 21, 2003 Share Posted April 21, 2003 I have a simple form running that I am succesfully using UPDATE to update the info in the database, but in my form (on my web page) I would like to see what is currently there before I edit or update that info. I tried this... [php:1:6649a61417] <? $db = mysql_connect(\"localhost\", \"\", \"\"); mysql_select_db(\"top_ten\",$db); $sql = \"SELECT * FROM rick\"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); $one = $myrow[\"one\"]; ?> [/php:1:6649a61417] and then in my form, I just tried to assign the value of the input field using the info I just retrieved from the db... <input type=text name=one maxlength=50 size=50 value=\"<? $one ?>\" > Unfortunatelly, this did not work. Also I should point out that my form action is another php file that handles the UPDATE. And like I said, the UPDATE works great, I\'d just like to be able to see what\'s in there before I edit or update it. Thanks for looking, Rick Link to comment https://forums.phpfreaks.com/topic/378-update-works-but-i-want-to-see-whats-in-there-first/ Share on other sites More sharing options...
shivabharat Posted April 21, 2003 Share Posted April 21, 2003 <? $db = mysql_connect("localhost", "", ""); mysql_select_db("top_ten",$db); $sql = "SELECT * FROM rick"; // u have to give a where if u want to match this query will get all the data from the table; //use select one from rick where <condition> $result = mysql_query($sql); do { $one = $myrow["one"]; echo "<input type=text name=one maxlength=50 size=50 value=\'$one\' > " } while ($myrow = mysql_fetch_array($result)); Link to comment https://forums.phpfreaks.com/topic/378-update-works-but-i-want-to-see-whats-in-there-first/#findComment-1280 Share on other sites More sharing options...
RickChase Posted April 21, 2003 Author Share Posted April 21, 2003 Ok, I got this figured out. Here is what my finished code looks like for anyone else who would like to do something similar... [php:1:c05af3bd96]<?php $db = mysql_connect(\"localhost\", \"\", \"\"); mysql_select_db(\"top_ten\",$db); $sql=\"SELECT * FROM rick\"; $result=mysql_query($sql,$db); $row = mysql_fetch_array($result); $one = $row[\"one\"]; $two = $row[\"two\"]; $three = $row[\"three\"]; echo \"<font face=Verdana,Arial,Helvetica size=2><form action=\"rick_top_ten_action.php\" method=\"post\">\"; echo \"<p><input type=text name=one maxlength=50 size=50 value=$one>\"; echo \"<p><input type=text name=two maxlength=50 size=50 value=$two>\"; echo \"<p><input type=text name=three maxlength=50 size=50 value=$three>\"; echo \"<p><br><input type=submit value=Update>\"; ?>[/php:1:c05af3bd96] I actually have ten instead of the three shown, and there is alot more to the html, but to simplify things I am only showing what is necessary for this to work for you. Thanks! Rick Link to comment https://forums.phpfreaks.com/topic/378-update-works-but-i-want-to-see-whats-in-there-first/#findComment-1284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.