Hello. I've created 2 pages that i'm currently working on. One is called; Test.php -- which just includes a basic form in HTML.
<Form name ="form1" Method ="POST" Action ="result.php"> Building Name: <INPUT TYPE = "TEXT" Name ="buildingName"> Room Number: <INPUT TYPE = "TEXT" Name ="roomId"> <INPUT TYPE = "Submit" Name = "Submit" VALUE = "Go"> </FORM>
The other being a page (called results.php), which grabs the information from the form above when the submit button is clicked and queries a database that it's linked to.
<?php $buildingName = $_POST['buildingName']; $roomId = $_POST['roomId']; $sql = mysql_query("SELECT * FROM forestcourt WHERE buildingName=$buildingName AND id=$roomId"); $id2 = 'id'; $buildingName = 'buildingName'; $subBuildings = 'subBuildings'; $imagePath = 'imagePath'; $description = 'description'; $rows2 = mysql_fetch_assoc($sql); echo 'Name: ' . $rows2[$buildingName] . '<br/>' . 'Room Number: ' . $rows2[$id2] . '<br/>' . 'Sub Buildings: ' . $rows2[$subBuildings] . '<br/>' . 'Description: ' . $rows2[$description] . '<br/>' . 'Location: ' . '<img src="../' . $rows2[$imagePath] . '"/>' . '<br/><br/>'; ?>
However, this code does work and displays all the relevant information accuratly when I'm only working with ONE text-input field (
Room Number: <INPUT TYPE = "TEXT" Name ="roomId">) on the page; test.php.
I've later tried to expand on this to take into account the buildingName too. I have set it up in the exact same way that I did with the roomId and it seems to just spit out an error.
I'm pretty new to PhP and MySQL and as far as I'm aware the SQL;
$sql = mysql_query("SELECT * FROM forestcourt WHERE buildingName=$buildingName AND id=$roomId");
If anyone could help me with this matter It would be a great help!
Thanks a bunch,