Jump to content

[SOLVED] SQL Inserts


CincoPistolero

Recommended Posts

Not sure whether to put this in mysql help or php help. I have a php page that sends paramaters to a confirm page to update the database. I have two sql insert statements. The first updates the DB twice, it should only do it once. The second updates the DB once, this is working as intended. Below is the code.

 

//Insert Into pwUser Table
$sql="INSERT INTO pwUsers (userName, password, email, acctType, activationKey, active, createDate, loggedIn, lastLoggedIn, firstLogin) 
VALUES ('$userName','$md5pwd','$email',23,'$activationKey',0,CURDATE(), 0, CURDATE(),0)";
$result1 = mysql_query($sql) or die ("Error in query: $sql. " . mysql_error());
$aID=mysql_insert_id();

if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}

//Insert Into Employer Table
$sql2="INSERT INTO employers (pwUserID, companyID, jobID, email, fname, lname, title, ac, ac2, phone, phone2, fax, mainAcct, active) 
VALUES ('$aID','','','$email','','','','','','','','',1,1)";
if (!mysql_query($sql2))
{
die('Error: ' . mysql_error());
}

 

Now, if I take out the below lines, the first INSERT updates only once, but pwUserID does not get set in the second INSERT. I need each INSERT to work once, and for pwUserID to get set in the second.

 

 

$result1 = mysql_query($sql) or die ("Error in query: $sql. " . mysql_error());
$aID=mysql_insert_id();

 

Link to comment
Share on other sites

The sql statements aren't failing. I'm inserting into the database in the first one, then what I want is the ID that gets created in that INSERT. I then want to put it into a field in the second INSERT. I've done this in code on other websites, but on this one, that original InSERT is reacting twice for whatever reason. I take those two lines out I mentioned above and it INSERTS once, wierd.

Link to comment
Share on other sites

//Insert Into pwUser Table
$sql="INSERT INTO pwUsers (userName, password, email, acctType, activationKey, active, createDate, loggedIn, lastLoggedIn, firstLogin)
VALUES ('$userName','$md5pwd','$email',23,'$activationKey',0,CURDATE(), 0, CURDATE(),0)";
$result1 = mysql_query($sql) or die ("Error in query: $sql. " . mysql_error());
$aID=mysql_insert_id();

// **** HERE YOU ARE EXECUTING THE QUERY A SECOND TIME
// **** I THINK YOU WANT TO TEST $result1
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}

 

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.