trying to insert value from a database into a form
The below code is a form to insert a record into a database (test). I want to be able to key in the apt in the form & insert the name from the database (prerentdb) into the input box. Is this possible ? Sorry, Just learning PHP.
PHP Code:
<?php
$apt=$_POST['apt'];
$name=$_POST['name'];
$stat = mysql_connect(localhost,root,"") or die('Unable to connect to database: ' . mysql_error());
$stat = mysql_select_db(prerentdb) or die('Unable to select database: ' . mysql_error());
$query = "SELECT apt,name FROM payments WHERE apt='$apt'";
$stat = mysql_query($query) or die('Query failed: ' . mysql_error());
?>
<html>
<BODY onload="document.form.apt.focus()">
<b>Maintenance Log insert form<p>
<form name=form action="testinsert.php" method="post">
<INPUT TYPE="text" size=2 name=apt
onKeyUp="if(this.value.length==this.size)document.form.name.focus();">Apt#<BR>
<INPUT TYPE="text" size=25 name=name>Name<BR>
<INPUT TYPE="text" size=10 name=datereceived
onKeyUp="if(this.value.length==this.size)document.form.time.focus();">Date Received<BR>
<INPUT TYPE="text" size=10 name=time>Time Received<BR>
<INPUT TYPE="text" size=100 name=symptom>Problem<BR>
<INPUT TYPE="text" size=100 name=action>Action<BR>
<INPUT TYPE="text" size=2 name=compmo MAXLENGTH=2
onKeyUp="if(this.value.length==this.size)document.form.compday.focus();">
<INPUT TYPE="text" size=2 name=compday MAXLENGTH=2
onKeyUp="if(this.value.length==this.size)document.form.compyear.focus();">
<INPUT TYPE="text" size=4 name=compyear MAXLENGTH=4
onKeyUp="if(this.value.length==this.size)document.form.ordno.focus();">Date Completed<br>
<INPUT TYPE="text" size=4 name=ordno>Order# - If Insp<p>
<p>
<INPUT type=submit value="submit data"/>
<BR></form></body></html>
View full post on Webmaster-Talk.com
Database, Form, from, insert, into, Trying, Value'