I've created 2 pages. One called test.php that just has some html on it with a bog standard form.
<Form name ="form1" Method ="GET" Action ="result.php">
room number: <INPUT TYPE = "TEXT" Name ="roomId">
<INPUT TYPE = "Submit" Name = "Submit" VALUE = "Go">
</FORM>
and another page that will process it called results.php.
$roomId = $_POST['roomId'];
$sql = mysql_query("SELECT * FROM forestcourt WHERE id=$roomId");
$id2 = 'id';
$buildingName = 'buildingName';
$subBuildings = 'subBuildings';
$imagePath = 'imagePath';
$description = 'description';
$rows2 = mysql_fetch_assoc($sql);
echo 'Name: ' . $rows2[$buildingName] . '<br/>' . 'Sub Buildings: ' . $rows2[$subBuildings] . '<br/>' . 'Description: ' . $rows2[$description] . '<br/>' . 'Location: ' . '<img src="../' . $rows2[$imagePath] . '"/>' . '<br/><br/>';
What I want it to effectively do is grab the value from the input on test.php and store it on the results.php page as $roomId
when the submit button is pressed. I've got it to work with other examples but I'm not sure why it's not here... Hopefully I've just made an easy mistake and someone can just point it out!
I know that the page is connected to the database because if I do some commenting on 'results.php' it grabs information from the database.
If I comment out:
$roomId = $_POST['roomId'];
and change:
$sql = mysql_query("SELECT * FROM forestcourt WHERE id=$roomId");
to;
$sql = mysql_query("SELECT * FROM forestcourt WHERE id=1");
the information on the results.php page is the same as the ones in the database.
An error that comes up when I go through the process is;
"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /websites/123reg/LinuxPackage23/ed/ge/_g/xxx.co.uk/public_html/testing/result.php on line 49"
Line 49 would be:
$rows2 = mysql_fetch_assoc($sql);
on results.php.
If anyone could shed some light on why it isn't working that would be great. I'm pretty new to MySQL and I've spent the best part of a day on this problem! If any more information is needed I'll quickly try and supply it.