dolcezza Posted January 23, 2008 Share Posted January 23, 2008 I have a dropdown populated by a database. When I try to insert the selection into another table, it isn't working. The form is getting the venueid column, I tested that by making it visible. If I echo $venueid in the next page, I get nothing. Any help for a newbie is appreciated. I only posted relevant parts of code. Form: Venue: <select name="venueid" id="venueid">" <? $query = "SELECT * FROM venues ORDER BY venue ASC"; $result = mysql_query($query) or die("there was an error:".mysql_error()); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { echo "<option value=\"$row[0]\">$row[1]</option>"; } } else { echo "<option value=\"\">No venues created yet</option>"; } echo '</select>'; ?> insert page: $venueid=$_POST['venueid']; $eventcode = md5(uniqid(rand())); $query = "INSERT INTO events (date,venueid,authorid,eventcode) VALUES ('$date_for_mysql','$venueid','$authorids','$eventcode')"; Quote Link to comment https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/ Share on other sites More sharing options...
dolcezza Posted January 23, 2008 Author Share Posted January 23, 2008 here is the whole insert page: I am posting this too because it is getting the venueemail, and sending the email. I thought it may help. Thanks. $authorlast=$_POST['authorlast']; $venueid=$_POST['venueid']; $eventcode = md5(uniqid(rand())); $venuequery = ("SELECT * FROM `venues` WHERE `venueid`='{$_POST['venueid']}'"); $venueresult=mysql_query($venuequery); $venueinfo = mysql_fetch_array($venueresult); //$venueid = $venueinfo['venueid']; $venueemail=$venueinfo['email']; $date_array=explode("/",$_POST["date"]); $date_for_mysql=$date_array[2]."-".$date_array[0]."-".$date_array[1]; $authorids = implode($_POST['authorid'],","); $query = "INSERT INTO events (date,venueid,authorid,eventcode) VALUES ('$date_for_mysql','$venueid','$authorids','$eventcode')"; $my_result=mysql_query($query); if(!$my_result){echo mysql_error();} else { include('events.php'); // get code from database // mail code to venue $send = mail($venueemail , "Connecting Authors Event Form" , "Thank you for booking your event with Connecting Authors (formerly KatzConnects)..\n\nPlease fill out our form by clicking the link below:\nhttp://www.connectingauthors.com/admin/eventform.php?id=".$eventcode."\n\nPlease do not reply, this is an automated mailer.\n\nThanks", "FROM: auto@mailer.com"); } Quote Link to comment https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/#findComment-446689 Share on other sites More sharing options...
Ken2k7 Posted January 23, 2008 Share Posted January 23, 2008 In the code below, what's $row[0] and $row[1] referring to? Venue: <select name="venueid" id="venueid">" <? $query = "SELECT * FROM venues ORDER BY venue ASC"; $result = mysql_query($query) or die("there was an error:".mysql_error()); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_row($result)) { echo "<option value=\"{$row[0]}\">{$row[1]}</option>"; } } else { echo "<option value=\"\">No venues created yet</option>"; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/#findComment-446691 Share on other sites More sharing options...
dolcezza Posted January 23, 2008 Author Share Posted January 23, 2008 in the database, row 0 is venueid and row 1 is the venue name. The venueid is unique, the name is what I want people to see obviously, but I use it's unique id Quote Link to comment https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/#findComment-446692 Share on other sites More sharing options...
Ken2k7 Posted January 23, 2008 Share Posted January 23, 2008 Try: Venue: <select name="venueid" id="venueid">" <?php $query = "SELECT * FROM venues ORDER BY venue ASC"; $result = mysql_query($query) or die("there was an error:".mysql_error()); if(mysql_num_rows($result)) { // we have at least one user, so show all users as options in select form while($row = mysql_fetch_array($result)) { echo "<option value=\"{$row[0]}\">{$row[1]}</option>"; } } else { echo "<option value=\"\">No venues created yet</option>"; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/#findComment-446700 Share on other sites More sharing options...
dolcezza Posted January 23, 2008 Author Share Posted January 23, 2008 It worked, thank you... I see you changed while($row = mysql_fetch_row($result)) to while($row = mysql_fetch_array($result)) do you mind explaining why one works and the other doesn't? I appreciate it if you are willing, I'm trying to get a better understanding. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/#findComment-446706 Share on other sites More sharing options...
dolcezza Posted January 23, 2008 Author Share Posted January 23, 2008 actually... I spoke too soon... it is writing the word "array" to the database instead of the id#. Quote Link to comment https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/#findComment-446707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.