Click to See Complete Forum and Search --> : PHP MSQL get Id
kproc
07-30-2006, 08:24 PM
Hi
I have a table that sets user_id as follows
user_id int(25) NOT NULL auto_increment
I have a assoctiated table where I want to send the user_id
code I have been working with. I placed this code after the data is sent to the table so that the user_id is created.
for some reason the value is not being entered in to my master table
any thoughts thank you
$user_id = $_SESSION['user_id'];
mysql_query("INSERT INTO master (user_id) VALUE ('$user_id')") or die (mysql_error());
echo $user_id;
NogDog
07-30-2006, 10:11 PM
If user_id is an integer field, try it without the quotes around $user_id.
kproc
07-30-2006, 10:24 PM
thanks I got it to work
Know I need to assign a a column in another table to a varaible. I don't think that I can use $_session
I need to get child_id from table children and not sure how to assign it a variable
include 'db.php';
$userid = $_SESSION['user_id'];
$query1= ("SELECT * FROM children, master WHERE master.user_id = '$userid' AND children.child_id = master.children_id")or die("Create table Error: ".mysql_error());
$result=mysql_query($query1)or die("Create table Error: ".mysql_error());
$num=mysql_numrows($result);
aussie girl
07-31-2006, 04:40 AM
thanks I got it to work
Know I need to assign a a column in another table to a varaible. I don't think that I can use $_session
I need to get child_id from table children and not sure how to assign it a variable
include 'db.php';
$userid = $_SESSION['user_id'];
$query1= ("SELECT * FROM children, master WHERE master.c_id = '$userid' AND children.child_id = master.children_id")or die("Create table Error: ".mysql_error());
$result=mysql_query($query1)or die("Create table Error: ".mysql_error());
$num=mysql_numrows($result);
Your WHERE clause is wrong, that needs to be the join between the table tables. it should be
I need to get child_id from table children and not sure how to assign it a variable
[php]
include 'db.php';
$userid = $_SESSION['user_id'];
$query1= ("SELECT * FROM children, master WHERE master.child_id = children.child_id AND master.user_id = $userid")or die("Create table Error: ".mysql_error());
I don't think that you are setting the sesson variable properly, simply putting it at the top like that doesn't initialise it.