I am trying to get a variable from a form on my page 1 into a query I have made on page 2 so that when the query works it will use the variable entered on page 1
Page 1 Form
<form method="post" action="testformQ.php"> <input type="text" name="testform"> <input type="submit">enter
Page 2 Query
'$software = mysql_query("SELECT software.SoftwareID, rooms.RoomID
FROM softwareroom
INNER JOIN software
ON software.SoftwareID=softwareroom.SoftwareID
INNER JOIN rooms ON rooms.RoomID=softwareroom.RoomID
WHERE rooms.RoomNum=$_GET[testform]"); (the where clause is where i want the variable)
while($rec = mysql_fetch_array($software))
{
echo $rec['SoftwareID'] . " " . $rec['RoomID'];
}'
So where the GET testform is within the query is where I want the form variable to go. Any help would be appreciated thanks
This code will work for you
$data = $_REQUEST['testform'];
$software = mysql_query("SELECT software.SoftwareID, rooms.RoomID
FROM softwareroom
INNER JOIN software
ON software.SoftwareID=softwareroom.SoftwareID
INNER JOIN rooms ON rooms.RoomID=softwareroom.RoomID
WHERE rooms.RoomNum='$data'");
while($rec = mysql_fetch_array($software))
{
echo $rec['SoftwareID'] . " " . $rec['RoomID'];
}'
Try this for Page02 Query..
$servername = "servername";
$username = "username";
$password = "password";
$db = "db_name";
$query = "SELECT software.SoftwareID, rooms.RoomID FROM softwareroom INNER JOIN software ON software.SoftwareID = softwareroom.SoftwareID"
+ "INNER JOIN rooms ON rooms.RoomID = softwareroom.RoomID WHERE rooms.RoomNum = '$_POST["testform"]'";
//Create db connection
$connection = mysqli_connect($servername, $username, $password, $db);
//Check connection
if(!$connection){
echo "Failed to connect to database ".mysqli_connect_error();
}
$software = mysqli_query($connection, $query);
mysqli_close($connection);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.