Forum Moderators: coopster

Message Too Old, No Replies

querying database using form field

         

jortworx

8:53 am on Jun 30, 2005 (gmt 0)

10+ Year Member



This is my code, what i would like to do is to query my database using the value form a menubox form field.

I just want to know if this is correct? I encountered problems... It doues not output to my output text field... Hope you can help guys! Thanks!

Code:

<?php
$n = $_GET['n'];
$dbConn = mysql_pconnect("zione", "user", "password") or trigger_error(mysql_error(),E_USER_ERROR);
$query = "SELECT * FROM tbloutlet WHERE StoreID=".dbquote($n);
$result = $dbConn->Execute();
$row = $result->FetchRow();
//$dbConn->Close();

echo "var formObj = document.forms[0];"."\n";
echo "formObj.outlet.value = \"".$row['Outlet']."\";"."\n"
?>

[edited by: ergophobe at 4:57 pm (utc) on June 30, 2005]
[edit reason] thread title changed - no URLs in posts or titles please [/edit]

mcibor

9:32 am on Jun 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the html correct?
Try echoing the
echo "Query: $query<br>";

Also see if there's really any value in
echo "Outlet: ".$row['Outlet']."<br>";

I would also recommend validating input from GET. I understand it's an integer value

$n = (int)$_GET['n']; //returns 0 if not integer and there's no 0 row, so the db returns no output - quite safe

Best regards
Michal Cibor

PS. It may be clearer to get out of php for some time:
?>
var formObj = document.forms[0];
formObj.outlet.value = "<?php echo $row['Outlet'];?>";
<?php ...