Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Validation

Status
Not open for further replies.

rogerzebra

Technical User
May 19, 2004
216
SE
Hi,
I can't get this code to work and after several hours of trying, I could need a couple of fresh eyes to have a look at it.
If I query just the sql part it works fine and register in both tables, but when I add the
php part it register in t1 but not t2. What am I doing wrong?

Code:
$q= "INSERT INTO submissions (SubmissionID, NameInsured, FEIN, EffectiveDate, DateRecieved, DateSubmitted, Producer, Contacts1, ClassCode) 
VALUES (NULL, '$NameInsured', '$FEIN', '$EffectiveDate', NOW(), '$DateSubmitted', '$Producer', '$Contacs1', '$Classcode')"; 
"INSERT INTO test (EvaluationID)
VALUES (LAST_INSERT_ID())";
    $result = mysql_query($q);

Thanks in advance
 
In your code, what is the following string supposed to be:
Code:
"INSERT INTO test (EvaluationID)
VALUES (LAST_INSERT_ID())";
It's not assigned to anything and it's not used.

Ken
 
Kenrbnsn,
It's supposed to use the id from the first insert query and insert a copy in a second table "test", row "EvaluationID".
If I try this code:
Code:
"INSERT INTO test (EvaluationID)
VALUES (LAST_INSERT_ID()'$EvaluationID')";
It gives me an error and shows me this:
Column count doesn't match value count at row 1.
This was what you ment right? As I said the code works fine in sql.
 
But you're not using it in any way.

Here's what you probably want:
Code:
$q= "INSERT INTO submissions (SubmissionID, NameInsured, FEIN, EffectiveDate, DateRecieved, DateSubmitted, Producer, Contacts1, ClassCode)
VALUES (NULL, '$NameInsured', '$FEIN', '$EffectiveDate', NOW(), '$DateSubmitted', '$Producer', '$Contacs1', '$Classcode')";
$result = @mysql_query($q)[b][red] or die('Something is wrong: ' . $q . '<br>' . mysql_error())[/red][/b];
[b][red]$q2 = [/red][/b]"INSERT INTO test (EvaluationID) VALUES ([b][red]mysql_insert_id[/red][/b]())";
[b][red]$r2 = @mysql_query($q2) or die('Something is wrong: ' . $q2 . '<br>' . mysql_error());[/red][/b]

The [red]red[/red] text is what I added or changed.

Ken
 
kenrbnsn,
I forgot to check my post,
thanks for your reply ken. I got it to work and as you said I used mysql_insert_id instead...
thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top