Jump to content


This topic is now archived and is closed to further replies.


UPDATE works, but I want to see what's in there first...

Recommended Posts

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...





$db = mysql_connect(\"localhost\", \"\", \"\");




$sql = \"SELECT * FROM rick\";


$result = mysql_query($sql);


$myrow = mysql_fetch_array($result);


$one = $myrow[\"one\"];





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,


Share this post

Link to post
Share on other sites

$db = mysql_connect("localhost", "", ""); 


$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); 



$one = $myrow["one"]; 

echo "<input type=text name=one maxlength=50 size=50 value=\'$one\' > "

} while ($myrow = mysql_fetch_array($result));

Share this post

Link to post
Share on other sites

Ok, I got this figured out. Here is what my finished code looks like for anyone else who would like to do something similar...




$db = mysql_connect(\"localhost\", \"\", \"\");



$sql=\"SELECT * FROM rick\";



$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>\";




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.




Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.