I am fairly new to php/mysql and have a database with 3 tables. The first table holds users, the 2nd table holds ads and 3d table is supposed to hold the id field from each of the first two tables. If I execute my first query, it runs fine: (This query should only execute for a new user)
$queryUser = mysql_query("INSERT INTO users (userNum, user_id, username, email, MemberNumber, firstName, lastName, city, state, zip, country, phone, password, balance, totalAds) VALUES ('', '$user_id', '$username', '$email', '$MemberNumber', '$firstName', '$lastName', '$city', '$state', '$zip', '$country', '$phone', '$password', '$balance', '$totalAds')");
My second query that inserts the ad also executes without error:
$queryAd=mysql_query("INSERT INTO adtable (adNum, userNum, AdName, AdType, paidFree, adTitle, adText, Display, Comments, pic1, pic2, pic3, pic4, pic5) VALUES ('','$userNum','$AdName', '$AdType', '$paidFree', '$AdTitle', '$AdText', '$Display', '$Comments', '$pic1', '$pic2', '$pic3', '$pic4', '$pic5')") or die("Insert Error: Could not insert your ad in the database. ".mysql_error());
Next, I grab the record number from the last query's auto increment field so I know what the ad # is:
$lastIn=mysql_insert_id(); //--- last record # added to database
However, the third query that I want to use to link the two tables fails:
$queryC=mysql_query("INSERT INTO classifieds (classNum, userNum, adNum, submitDate, approvedDate) VALUES( '', '$userNum', '$lastIn', '$submitDate', '' ") or die("Error: Couldn't creat linked reference".mysql_error() );
Does anyone have any idea what I am doing wrong? Thanks for the help.
brad