Discussion:
assign database result to iinput text box
iccsi
2013-09-18 05:33:32 UTC
Permalink
I have following html code to show my input text box and php to connect
server and select result from database server.
I would like to know how I can I use php to assign the value to my input
text.
Your help and information is great appreciated,

Regards,

Iccsi,

<INPUT type="text" name="Mytxt" id="MytextID" />


<?php
$username = "root";
$password = "myPassword";
$hostname = "localhost";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";

//select a database to work with
$selected = mysql_select_db("iccsimd",$dbhandle)
or die("Could not select aerver");

//execute the SQL query and return records
$result = mysql_query("SELECT invid, invdate, note, amount FROM invheader");
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Maciek Sokolewicz
2013-09-18 11:45:32 UTC
Permalink
Post by iccsi
I have following html code to show my input text box and php to connect
server and select result from database server.
I would like to know how I can I use php to assign the value to my input
text.
Your help and information is great appreciated,
Regards,
Hi iccsi,

first, look at http://www.php.net/mysql_fetch_array the example should
help you.

Once you have the value you're looking for in a variable, you simply
assign insert it into the value property of your input element. Ie. you
should have something like <input type="text" name="a" id="b" value="the
variable containing your data">

Also please note that the mysql extension is deprecated; you are advised
to switch to either PDO_MySQL or mysqli instead.

- Tul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
ITN Network
2013-09-18 13:46:01 UTC
Permalink
<?php
$username = "root";
$password = "myPassword";
$hostname = "localhost";

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable
to connect to MySQL");
echo "Connected to MySQL<br>";

//select a database to work with
$selected = mysql_select_db("iccsimd",$dbhandle) or die("Could not select
aerver");

//execute the SQL query and return records
$result = mysql_fetch_assoc(mysql_query("SELECT invid, invdate, note,
amount FROM invheader"));
?>

<INPUT type="text" name="Mytxt" id="MytextID" value="<?php echo
$result['note'];?>" />

Like Maciek mentioned, if this is a new project use PDO or MySQLi instead,
else use a PDO wrapper for MySQL functions.


On Wed, Sep 18, 2013 at 7:45 AM, Maciek Sokolewicz <
Post by Maciek Sokolewicz
Post by iccsi
I have following html code to show my input text box and php to connect
server and select result from database server.
I would like to know how I can I use php to assign the value to my input
text.
Your help and information is great appreciated,
Regards,
Hi iccsi,
first, look at http://www.php.net/mysql_**fetch_array<http://www.php.net/mysql_fetch_array>the example should help you.
Once you have the value you're looking for in a variable, you simply
assign insert it into the value property of your input element. Ie. you
should have something like <input type="text" name="a" id="b" value="the
variable containing your data">
Also please note that the mysql extension is deprecated; you are advised
to switch to either PDO_MySQL or mysqli instead.
- Tul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...