简体   繁体   中英

PHP MySQL insert not working

Sorry if it's a quite simple problem. I am not too experienced with web languages.
Basically, it doesn't work.

$insert=
(
  "INSERT INTO phpbb_members ".
  "(emailAddress, uid, valid, firstandlast, propic, memberName) ".
  "VALUES ($me['email'], $uid, 1, $me['name'], $propic, $newuser)"
);
mysql_query($insert) or die('Error, insert query failed');
$insert="INSERT INTO phpbb_members (emailAddress, uid, valid, firstandlast, propic, memberName)
VALUES ('".$me['email']."', $uid, 1, '".$me['name']."', '$propic', $newuser)";

Missing singular quotes (for strings [varchar, char, text, etc]) and you need to close your quotes and concatenate when referencing an array. The above assumed $uid and $newuser are stored numerically in the DB.

如果您将使用以下内容进行测试,它将显示错误:

mysql_query($insert) or die(mysql_error()."<br />".$insert);

I think the problem may be in the way you've laid out the information to be inserted.

This should work:

$insert=("INSERT INTO phpbb_members (emailAddress, uid, valid, firstandlast, propic, memberName)
VALUES ('$me[email]', '$uid', '1', '$me[name]', '$propic', '$newuser')");
        mysql_query($insert) or die('Error, insert query failed');

Hope it helps!

EDIT: I'm pretty sure the information to be inserted has to be inside ' ' .

$insert=("INSERT INTO phpbb_members (emailAddress, uid, valid, firstandlast, propic, memberName) 
VALUES ($me['email'], $uid, 1, $me['name'], $propic, $newuser)"); 

Do wee need those extra brackets in the beginning and end? Try to remove it and execute.

$sql = "SELECT * FROM Person";
mysql_query($sql,$con);
$insert=("INSERT INTO phpbb_members (emailAddress, uid, valid, firstandlast, propic, memberName)
VALUES ('".$me['email']."','". $uid."',1,'". $me['name']."','" .$propic."','". $newuser."')");
mysql_query($insert) or die('Error, insert query failed');

Try the following code,

 $insert=("INSERT INTO phpbb_members (emailAddress, uid, valid, firstandlast, propic, memberName) VALUES ('{$me['email']}', '{$uid}', '1', '{$me['name']}', '{$propic}', '{$newuser}')");
mysql_query($insert) or die('Error, insert query failed');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM