Jump to content

getting id from a table and putting it into another


dolcezza

Recommended Posts

<?php
include_once("connect.php");

$authorlast=$_POST['authorlast'];
$date=$_POST['date'];
$venue=$_POST['venue'];
var_dump("$authorlast");
var_dump("$date");
var_dump("$venue");

$authorquery = ("SELECT * FROM `authors` WHERE `authorlast`='{$_POST['authorlast']}'");
$authorresult=mysql_query($authorquery);
$info = mysql_fetch_assoc($authorresult);
$authorid = $info['authorid'];
var_dump("$authorid");

$venuequery = ("SELECT * FROM 'venues' WHERE 'venue'='{$_POST['venue']}");
$venueresult=mysql_query($venuequery);
$info = mysql_fetch_assoc($venueresult);
$venueid = $info['venueid'];
var_dump("$venueid");

$query = "INSERT INTO events (date,venueid,authorid) VALUES ('$date','$venueid','$authorid')";


$my_result=mysql_query($query);
if(!$my_result){echo mysql_error();}
else {

include('events.php');
        // get code from database
        // mail code to venue
}

?>

 

This is what I get:

string(0) "" string(9) "1/28/2006" string(16) "White Oak School" string(0) "" string(0) "" event has been added.

 

The database has an event added, but none of the values.

 

Any help for a beginner is greatly appreciated!!!

Link to comment
Share on other sites

Looking at the var_dump results:

 

authorlast has no value, so consequently no rec found and authorid is therefore empty

 

The venue query has syntax errors so you won't get a venueid either

 

Insert dates into tables in 2007-01-28 format.

 

I suggest you check values of query result and, if false, display mysql_error() after each of your queries and also check if any rows are returned

Link to comment
Share on other sites

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.