Jump to content


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

  • Please log in to reply
2 replies to this topic

#1 RickChase

  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 21 April 2003 - 06:11 PM

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,

#2 shivabharat

  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 21 April 2003 - 06:16 PM


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

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 RickChase

  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 21 April 2003 - 06:49 PM

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.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users