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!!!

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.