Jump to content

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


RickChase

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

 

[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
Share on other sites

<? 



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

 

[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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.