Jump to content

[SOLVED] SQl Statement INSERT with given ID number ?


aktell

Recommended Posts

Hi there,

 

The ERROR Msg is always around SELECT:

(.. right syntax to use near 'SELECT member_id FROM ....)' at line 2)

<?
//********** I have the member_id included as the ONLY given value in the DB.
if ((!$_POST[member_id]) || (!$_POST[f_name]) || (!$_POST[l_name]) || (!$_POST[username]) || (!$_POST[password])) {
header("Location: show_adduser.htm");
exit;
}
//********** code to connect etc.
//**********
//********** My real problem here is HOW to state the query ??? I assume that I have a bracket or comma etc. to much ???.
$sql = "INSERT INTO $table_name (f_name, l_name, username, password)
VALUES ('$_POST[f_name]', '$_POST[l_name]', '$_POST[username]', password('$_POST[password]'), SELECT member_id = '$_POST[member_id]' FROM $table_name)";
//**********
//********** OR ??
$sql = "INSERT INTO $table_name (f_name, l_name, username, password)
VALUES ('$_POST[f_name]', '$_POST[l_name]', '$_POST[username]', password('$_POST[password]'), 
SELECT member_id FROM $table_name WHERE member_id LIKE member_id = '$_POST[member_id]')";
?>

 

Thanks for any help in advance aktell ???

Array keys must be strings, like this:

$_POST['f_name']

 

What are you trying to do? You run an insert then a select - are you just trying to get the ID of the inserted member? use mysql_insert_id();

 

Either way the two statements should be seperated.

Array keys must be strings, like this:

$_POST['f_name']

 

What are you trying to do? You run an insert then a select - are you just trying to get the ID of the inserted member? use mysql_insert_id();

 

Either way the two statements should be seperated.

 

Hi there,

 

I'm trying to INSERT certain values as f_name etc. INTO a record which already has a given ID number (member_id)

 

aktell

That's called an Update. If the record already exists, you update it.

 

Well, I'm feeling pretty foolish here. Sorry, I ndid not think out of the INSERT.

$sql = "UPDATE $table_name SET f_name = '$_POST[f_name]', l_name = '$_POST[l_name]', username = '$_POST[username]', password = password('$_POST[password]')
WHERE member_id = '$_POST[member_id]'";

 

It worked strait away. Thanks alot !!!

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.