6

Ive been going over this for a couple days and i just cant find the reason it is erroring out. Im not getting a php warning, just the error handler "somethign went wrong" instead of inserting. I know the fine young lads here will probably spot it in a few seconds, esp considering its just a simple insert statement, but im buggered. Thanks in advance.

include('core.inc.php');
$sql = 'INSERT INTO $resultsTable (
    id, 
    firstName, 
    lastName, 
    email, 
    birthday, 
    anniversary,
    location,
    campaign
) 
VALUES (NULL,?,?,?,?,?,?,?)';
$stmt = $mysql->stmt_init();
if ($stmt->prepare($sql)) { 
// bind parameters and execute statement
$stmt->bind_param(
    'sssssss', 
    $_POST['fname'], 
    $_POST['lname'],
    $_POST['email'],
    $_POST['birthday'],
    $_POST['anniversary'],
    $_POST['location'],
    $campaign
);

$OK = $stmt->execute();}
 // return if successful or display error
    if ($OK) {$response = "Success";}
    else {$response ="Something went wrong.";}
}
4
  • Have you tried echoing mysqli_error()? php.net/manual/en/mysqli.error.php Commented Apr 21, 2012 at 15:12
  • Where is $mysql coming from? Is that defined in core.inc.php? Commented Apr 21, 2012 at 15:12
  • Instead of just printing out "something went wrong," print out the actual error that mysqli tells you Commented Apr 21, 2012 at 15:13
  • ok i echoed stmt error and it told me that $resultsTable didnt exist. In core.inc, I have a definition for that variable, i wonder why it isnt carrying over? Commented Apr 21, 2012 at 15:18

1 Answer 1

3

ok i echoed stmt error and it told me that $resultsTable didnt exist. In core.inc, I have a definition for that variable

Use concatenation or double quotes.

$sql = 'INSERT INTO ' . $resultsTable . ' (
    id, 
    firstName, 
    lastName, 
    email, 
    birthday, 
    anniversary,
    location,
    campaign
) 
VALUES (NULL,?,?,?,?,?,?,?)';


$sql = "INSERT INTO $resultsTable (
    id, 
    firstName, 
    lastName, 
    email, 
    birthday, 
    anniversary,
    location,
    campaign
) 
VALUES (NULL,?,?,?,?,?,?,?)";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.