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 ???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 !!!

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.