Link to home
Start Free TrialLog in
Avatar of amer_net
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,$username,$password);

$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_id");
$Company_name=mysql_result($result,$i,"Company_name");
$City=mysql_result($result,$i,"City");
$State=mysql_result($result,$i,"State");

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


Avatar of Raynard7
Raynard7

The problem is that mysql_numrows should have an additonal _ and that to pull rhte result values you need to use something like $row = mysql_fetch_array or mysql_fetch_assoc with the $result,

also you may want to use full tags for your echoing into your text values
Avatar of amer_net

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
ASKER CERTIFIED SOLUTION
Avatar of Raynard7
Raynard7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you so much