Jump to content

[SOLVED] Getting userid


ShaolinF

Recommended Posts

Hi Guys,

 

I need to populate 2 tables with data. One is the users table and the other is a purchase table. Now this is the code I am using for the users table:

 

$insert = mysql_query("INSERT INTO users VALUES ('', '".$_SESSION['NAME']."', '".$_SESSION['CONTACTNO']."', '".$_SESSION['EMAILADD']."', '".$_SESSION['GENDER']."')");

 

Now for the purchase field, is there anyway I could grab the userid for the user above without going through a lengthy SELECT statement ? Please note, there is no user registration allowed on the website.

Link to comment
https://forums.phpfreaks.com/topic/87671-solved-getting-userid/
Share on other sites

Thanks. I have now added the INSERT for purchase and am getting the following error:

 

Parse error: syntax error, unexpected T_VARIABLE

 

code (ERROR is in the $insert variable):

//Grab userid and eventid to be used for purchase table
$userid = mysql_insert_id();
$eventid = mysql_query("SELECT eventid FROM event WHERE eventset = 1")
//Update time to time of input into DB


// Add purchase details
$insert = mysql_query("INSERT INTO purchase VALUES ('', '$userid', '$eventid', '".$_SESSION['TICKET']."', '".$_SESSION['TOTALPRICE']."', 'N', '')") or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/87671-solved-getting-userid/#findComment-448454
Share on other sites

Thanks, didnt see that.

 

Yet again another 2 problems. First of all, I am trying to insert the date into the table but its not going.

 

This is how I defined the column:

timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

 

How I am adding date into the the column:

$date  = date("D dS M,Y h:i a");	//Update time to time of input into DB

// Add purchase details
$insert2 = mysql_query("INSERT INTO purchase VALUES ('', '$userid', '$eventid', '".$_SESSION['TICKET']."', '".$_SESSION['TOTALPRICE']."', 'N', '$date')") or die(mysql_error());

 

sECOND PROBLEM:

the eventid when inserted into the db does not work. See code:

 

$eventid = mysql_query("SELECT eventid FROM event WHERE eventset = 1");

 

 

Link to comment
https://forums.phpfreaks.com/topic/87671-solved-getting-userid/#findComment-448469
Share on other sites

sECOND PROBLEM:

the eventid when inserted into the db does not work. See code:

 

$eventid = mysql_query("SELECT eventid FROM event WHERE eventset = 1");

 

Is the name of the field "eventid"?  You could also try using complete syntax.

 

$eventid = mysql_query("SELECT `eventid` FROM `event` WHERE `eventset` = '1'");

Link to comment
https://forums.phpfreaks.com/topic/87671-solved-getting-userid/#findComment-448500
Share on other sites

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.