I am having a problem figuring out how to get data out of a MySQL database for a website I'm working on, sort of.
I say sort of, because this is a test page I'm working on to model the functions first and test them, before I put them on the actual page.
Anyway, I got the other functions I was working on done: Connecting, Creating a DB, Creating Tables, and inserting rows.
However, when it comes to getting the data back out of the database, I keep hitting a problem with mysql_fetch_array.
Here is the code I have for it so far:
- Code: Select all
$result = mysql_query("SELECT * FROM " . $_POST["SQLTABLE"] . " WHERE " . $_POST["SQLFIELD"] . " = " . $_POST["SQLSEARCHDATA"]);
$rez = "SELECT * FROM " . $_POST["SQLTABLE"] . " WHERE " . $_POST["SQLFIELD"] . " = " . $_POST["SQLSEARCHDATA"];
while($row = mysql_fetch_array($result))
echo "<br />";
I fill in the form with the values, and when I click submit I get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/test/php/dbtest2.php on line 74
Line 74 = while($row = mysql_fetch_array($result))
The echo of the $rez var give's out proper SQL (as far as I am aware), E.g.
SELECT * FROM users WHERE UserName = TEST1
This has got me stumped, can someone please put me out of my misery and tell me what I'm doing wrong? Is it the PHP? The SQL?