will35010 Posted November 3, 2008 Share Posted November 3, 2008 I'm trying to query the database and pull the reservations based on the user's input. It keeps saying that the varible $id is not assigned on line 79, but I assigned it on line 65. I'm very new to php and any help would be appreciated. Thanks, <?php //PHP script to see events from database and see reservations by event //This will give us very good details on errors error_reporting(E_ALL); //global config files require 'include/config.php'; require 'include/opendb.php'; ?> <html> <head> <title>Panola Playhouse</title> </head> <?php //Return the Form Data from the Database $query = "SELECT DISTINCT eventname FROM events ORDER BY eventID"; $result = mysqli_query($conn, $query) or die('Error: ' . mysql_error()); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } ?> <form method="POST" Action="<?php echo $_SERVER['PHP_SELF'];?>"> <?php //print select menu with shows from database echo "<select name='shows' style='width:210px;'>\n"; //to pull all plays loop while ($row = mysqli_fetch_row($result)) { //assign varible names to results $event = $row[0]; echo "<option value='{$event}'>$event</option>"; } echo "</select>\n"; ?> <input type="submit" value="Choose Play"> </form> <?php //take POST value to pick times //Make sure varible is set so page doesn't display error on load if (isset($_POST['shows'])) { //assign varible name to pass to new query to pull show times $shows = $_POST['shows']; $query2 = "SELECT eventmonth, eventday, eventyear, hour, minute, ampm, eventID FROM events WHERE eventname = '$shows'"; $times = mysqli_query($conn, $query2) or die('Error: ' . mysql_error()); //so when time is selected it will pass it to itself for the next step ?> <form method="POST" Action="<?php echo $_SERVER['PHP_SELF'];?>"> <?php echo "<SELECT MULTIPLE NAME='times'>"; //loop so it pulls all shows mathing name while ($row = mysqli_fetch_row($times)) { $month = $row[0]; $day = $row[1]; $year = $row[2]; $hour = $row[3]; $min = $row[4]; $ampm = $row[5]; $id = $row[6]; echo "<OPTION VALUE='$id'>Date:$month-$day-$year Time:$hour:$min$ampm<BR>"; } echo "<input type='submit' value='Choose Time'></form>"; } //this part will show reservations by event if (isset($_POST['times'])) { //assign varible name to pass query to pull reservations $res = $_POST['times']; //query to pull reservations $query3 = "SELECT eventID, customerID, seatID FROM reservations WHERE eventID = $id"; $grab = mysqli_query($conn, $query3) or die('Error: ' . mysql_error()); while ($row = mysqli_fetch_row($grab)) { //assign varible names to mysql results $event = $row[0]; $cust = $row[1]; $seat = $row[2]; echo "$event $cust $seat"; } } ?> <?php include 'include/closedb.php'; ?> Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/ Share on other sites More sharing options...
ngreenwood6 Posted November 3, 2008 Share Posted November 3, 2008 You really should use the code tags when you are posting code. Makes it much easier to read. When you define $id try this: $id = $row['eventID']; You can also try echoing out $id to see if it is getting a value. Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681350 Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 You're assigning $id inside a loop. If that loop doesn't run (like if there's no rows returned), then $id isn't being assigned. Also, PLEASE use the code tags when inserting code in a post. Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681352 Share on other sites More sharing options...
ngreenwood6 Posted November 3, 2008 Share Posted November 3, 2008 Good point F1Fan didn't even notice that. Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681354 Share on other sites More sharing options...
revraz Posted November 3, 2008 Share Posted November 3, 2008 This is bad advice, seeing how he is using mysqli_fetch_row. There is no assocation with the object name. You really should use the code tags when you are posting code. Makes it much easier to read. When you define $id try this: $id = $row['eventID']; You can also try echoing out $id to see if it is getting a value. Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681356 Share on other sites More sharing options...
will35010 Posted November 3, 2008 Author Share Posted November 3, 2008 You're assigning $id inside a loop. If that loop doesn't run (like if there's no rows returned), then $id isn't being assigned. Also, PLEASE use the code tags when inserting code in a post. The loop does run, because there is data on the rows I selected. I just double checked that. So it is being assigned, but it won't let me put it in that query. I ran the query cli and it works. Also, codetags??? Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681357 Share on other sites More sharing options...
will35010 Posted November 3, 2008 Author Share Posted November 3, 2008 I want it to take the POST data from choose times and use that in the query. Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681360 Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 OK, it looks like the second time you're using $id, you should be using $res (or $_POST['times']), and NOT $id. Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681365 Share on other sites More sharing options...
will35010 Posted November 3, 2008 Author Share Posted November 3, 2008 OK, it looks like the second time you're using $id, you should be using $res (or $_POST['times']), and NOT $id. Using $res fixed it. I knew it had to be something small or at least I was hoping it was. Thanks F1Fan!!! Thanks to the others that replied too!!! Link to comment https://forums.phpfreaks.com/topic/131238-solved-varible-script-problem/#findComment-681370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.