Jump to content

how to retrieve db keys?


BigD
 Share

Recommended Posts

I just inserted a row into my db, how do I retrieve the row key?Here is the code: $query = "INSERT INTO student (graduatedate,lastname,firstname, gender,classid,address, city, state, zip, phone, altphone, email,ssn, dob, picture, lboxname, lbdeposit) " . " VALUES ('na','$lastname', '$firstname', '$gender','$classid','$address', '$city', '$state', '$zip', '$phone', '$altphone','$email','$ssn', '$dob', '$thumbnail','$lboxname', '$lbdeposit')"; $result = mysql_query($query);echo "<h2> Here is the result on student db= $stdid, $lastname ,$firstname,$gender,$classid,$address,$city,$state, $zip,$phone,$altphone,$email,$ssn,$dob,$lboxname,$lbdeposit</h2>\n"; if ($result) { echo "<h2>Student added</h2>\n"; $query = "SELECT $stdid, $classid from student where lastname= '$lastname' and firstname= '$firstname'"; } else { echo "<h2>Problem adding Student</h2>\n". mysql_error(); exit; } Here is the inquire result: Here is the result on student db= , aa ,aa,,2,,,, ,,,,,,, Student added$stdid is the key, it is not returned.

Link to comment
Share on other sites

$query = "SELECT $stdid, $classid from student where lastname= '$lastname' and firstname= '$firstname'"; $stdid, $classid will represent a field value, whereas you require the actual field-NAME, SELECT field-names FROM table WHERE field-name (value within this field) = required search criteria

Edited by dsonesuk
Link to comment
Share on other sites

I see my mistakes. $query = "SELECT $stdid, $classid from student where lastname= '$lastname' and firstname= '$firstname'";should be $query = "SELECT stdid, classid from student where lastname= '$lastname' and firstname= '$firstname'"; Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...