Hi - I'm a real novice at this and trying my best to find my way through HTML PHP and MySQL. I'd like to have a form take an input (the password) and pass this to a db table which treats the password as an index returning an integer in an adjacent field in the table. Four strings of length 4 are concatenated and submited as the unique index.
eg input AAAA BBBB CCCC DDDD, which is concatenated to AAAABBBBCCCCDDDD and queried to the table which should return a value eg 30
Here's some code fragments:
This is in index.php.........
<form method="POST" action="connection.php">
<input type="PASSWORD" name="AAAA" size="4"><input type="PASSWORD" name="BBBB" size="4"><input type="PASSWORD" name="CCCC" size="4"><input type="PASSWORD" name="DDDD" size="4">
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<?php include("connection.php");?>
This is in connection.php
echo $_POST['AAAA'] . $_POST['BBBB'] .$_POST['CCCC'] .$_POST['DDDD'] .'<br>'; //This lets me see that the form input has been concatenated correctly
$my_password = $_POST['AAAA'] . $_POST['BBBB'] .$_POST['CCCC'] .$_POST['DDDD'];
echo $my_password . '<br>'; //This lets me see that the variable is assigned
$sql = mysql_query('SELECT * FROM `table101` WHERE `key` = $my_password');
if (!$sql) {
echo 'Could not run query: ' . mysql_error();
exit;
}
echo mysql_result($sql);
And I get the following error message:
Could not run query: Unknown column '$my_password' in 'where clause'
The issue seems to be centred on the mysql_query() function and the containing ' ' marks. I've used ' ', " " and no quotes each with a different error message. I'm a bit stuck on how to pass the variable to the table and get a return value. Can you please help?
Thanks
Nigel








Bookmarks