Jump to content

Recommended Posts

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')";

Link to comment
https://forums.phpfreaks.com/topic/87335-variable-not-passing-to-next-page/
Share on other sites

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");
}

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>';
?>

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>';
?>

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.