Forum Moderators: coopster

Message Too Old, No Replies

Searching MySql Table and Outputting

Errors on my first search attempt

         

mandarin

9:50 am on Apr 7, 2006 (gmt 0)

10+ Year Member



This is my first attempt at trying to access a mysql db but I'm getting errors which I can't figure out.

Db has one table with 2 fields called input and output. User will enter the input via web form which sends "forminput" to this script. I can echo that to screen so I know it's getting through.

Script should then display the input and output fields to the screen. Here's the script

<?

$dbh=mysql_connect ("localhost", "database_name", "passwordhere") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database_name");

$query = "SELECT * FROM database_name WHERE input = {$_POST['forminput']} LIMIT 1";

$result = mysql_query ($query);

$row = mysql_fetch_assoc ($result);

echo "input: {$row['input']}<br>output: {$row['output']}";

?>

Any ideas very welcome

Mike

tomda

10:05 am on Apr 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmasterworld Mandarin,
let us know which error message you get!

See below that you can echo the query.


<?
$dbh=mysql_connect ("localhost", "database_name", "passwordhere") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database_name");
$query = "SELECT * FROM database_name WHERE input = {$_POST['forminput']} LIMIT 1";
echo $query;
$result = mysql_query ($query) or die('Error');;
$row = mysql_fetch_assoc($result);
echo "input: {$row['input']}<br>output: {$row['output']}";
?>

mandarin

10:19 am on Apr 7, 2006 (gmt 0)

10+ Year Member



Oops, should have put that in, sorry.

mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html etc etc

If I add your echo error bit (thanks) I get this

SELECT * FROM avdbdown_modes WHERE input = 008001 LIMIT 1Error

where 008001 is the forminput

Mike

tomda

6:12 am on Apr 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, regarding the error you get, try
SELECT * FROM avdbdown_modes WHERE input = '008001' LIMIT 1