I have the following code which is supposed to pull data from mysql database if search box value matches row & attribute Client_Name in MYSQL.
please see http://www.recruitingblt.comli.com/add-new-sales-record.html.
When a match is found, the form reverts back (try James Dean) and does not autopopulate the fields I want it to (for now I am just asking for Client_Address, Client_Phone & Attn_Email1 to test). These are the names of columns in mysql table bltrecruiting
).
I am thinking that maybe Client_Name needs to be unique, say I have company Microsoft, and there is more than one row, will the query not be able to pull through address, phone etc despite being the same for all Microsoft records? Does the look up value need to be unique?
<?php
$regnum = $_GET['regnum'];
//////////regnum is named box at top of form page (Client Name Box)
//////Connection which seems to work fine
$db_host = 'mysql6.000webhost.com';
$db_username = '********';
$db_password = '********';
$db_name = 'a8748341_bltrec';
mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_name);
////// Check for the Client Name which is a field Client_Name in the database - Should Client_Name be unique?
$result = mysql_query("SELECT * FROM bltrecruiting WHERE Client_Name='$regnum'") or
die(mysql_error());
$row = mysql_fetch_array( $result );
if (empty($row[Client_Name]))
{
echo "No previous record of Client: $regnum <br>";
echo "Please try again <br>" ?>
<div id=regcon>
<FORM NAME = "reg" action=database.php>
<div style=width:150px; float:left; display:inline-block; font-family: Verdana;
font-size: 12px; padding-left:13px;> Client Name: </div>
<input type="text" id="textbox" name="regnum" size="20"/>
<input name="Submit" type="submit" value="Get Form"/>
</form>
</div>
}
else
{
///////// Get the fields from the database
$address = $row['Client_Address'];
$phonenumber = $row['Client_Phone'];
$name= $row['Attn_Name1'];
//add your additional fields here
echo '<script type="text/javascript"src="http://form.jotform.com/jsform/43438603456356?"Client_Name='.$regnum.'&Client_Address='.$address.'&Client_Phone='.$phonenumber.'&Attn_Name1='.$name.'"></script>';
}
?>
</body>
</html>