amer_net
asked on
passign values from database to textbox with php/mysql
Hi,
I am trying to build an update page,
I have problem in getting the vaules from the database into a textboxes so the user can see the old values,
it is my first time to do this so I don't know how:
This is my code:
<?php
$username="whatever";
$password="whatever";
$database="whatever";
mysql_connect(localhost,$u sername,$p assword);
$query=" SELECT * FROM Companies WHERE Company_id='1'";
$result=mysql_query($query );
$num=mysql_numrows($result );
mysql_close();
$i=0;
while ($i < $num) {
$Company_id=mysql_result($ result,$i, "Company_i d");
$Company_name=mysql_result ($result,$ i,"Company _name");
$City=mysql_result($result ,$i,"City" );
$State=mysql_result($resul t,$i,"Stat e");
++$i;
}
?>
<html>
<head>
<title>Update Page</title>
</head>
<form action="updated.php" method="post">
Compnay_id <input type="text" name="ud_first" value="<? echo $Company_id; ?>"><br>
Company_name <input type="text" name="ud_last" value="<? echo $Company_name; ?>"><br>
City <input type="text" name="ud_phone" value="<? echo $City; ?>"><br>
State <input type="text" name="ud_mobile" value="<? echo $State; ?>"><br>
<input type="Submit" value="Update">
</form>
</html>
This did not work with me and don't stuck with this code, if you have better ideas or easier code it would be great,
Thank you
I am trying to build an update page,
I have problem in getting the vaules from the database into a textboxes so the user can see the old values,
it is my first time to do this so I don't know how:
This is my code:
<?php
$username="whatever";
$password="whatever";
$database="whatever";
mysql_connect(localhost,$u
$query=" SELECT * FROM Companies WHERE Company_id='1'";
$result=mysql_query($query
$num=mysql_numrows($result
mysql_close();
$i=0;
while ($i < $num) {
$Company_id=mysql_result($
$Company_name=mysql_result
$City=mysql_result($result
$State=mysql_result($resul
++$i;
}
?>
<html>
<head>
<title>Update Page</title>
</head>
<form action="updated.php" method="post">
Compnay_id <input type="text" name="ud_first" value="<? echo $Company_id; ?>"><br>
Company_name <input type="text" name="ud_last" value="<? echo $Company_name; ?>"><br>
City <input type="text" name="ud_phone" value="<? echo $City; ?>"><br>
State <input type="text" name="ud_mobile" value="<? echo $State; ?>"><br>
<input type="Submit" value="Update">
</form>
</html>
This did not work with me and don't stuck with this code, if you have better ideas or easier code it would be great,
Thank you
ASKER
can you give me any example
forget about my code because I took it from the internet and i did not understand it very well,
I want any example in which I can take the values from my database into the textbox,
use only one text box thats fine.
thank you
forget about my code because I took it from the internet and i did not understand it very well,
I want any example in which I can take the values from my database into the textbox,
use only one text box thats fine.
thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much
also you may want to use full tags for your echoing into your text values