0

I am trying to update some columns in a row with MySQL in PHP like so:

$updateuser_sql = "
UPDATE `users`
SET
`HeaderPictureID` = $insertid,
`Bio` = '" . myre($_POST['Bio']) . "',
`ContactEmail` = '". myre($_POST['ContactEmail']) ."',
`PhoneNo` = '". myre($_POST['PhoneNo']) ."',
`TwitterHandle` = '". myre($_POST['TwitterHandle']) ."'
WHERE
`UserID` = '{$_SESSION['userID']}'
";

$mysqli->query($updateuser_sql);

if($mysqli->errno) {
    $handlerreturn['status'] = 'USER_UPDATE_FAILURE';
    console.log('FAILED');
} else {
    $handlerreturn['status'] = 'EXEC_SUCCESS';
    console.log('WORKED');
}

Unfortunately this doesn't work and I get the log 'FAILED'. How can I find out, more precisely, what is wrong and work to fix the issue? Am I doing something so obviously wrong?

Thanks!

4
  • 1
    echo $mysqli->error;? Commented Oct 8, 2013 at 20:01
  • echo $updateuser_sql;? Commented Oct 8, 2013 at 20:03
  • Nothing happens when I add this to the code... Commented Oct 8, 2013 at 20:24
  • o_O How? You can't to echo your SQL? Hm, what is 'console.log' ? Commented Oct 8, 2013 at 21:20

1 Answer 1

1

Put this at the end of your page

$_POST["Bio"] = "hi";
$_POST['ContactEmail'] = "cheese";
$_POST['PhoneNo'] = "lion";
$_POST['TwitterHandle'] = "asdl";
$_SESSION['userID'] = "asdf";

$updateuser_sql = "
                    UPDATE `users`
                    SET
                    `HeaderPictureID` = 1,
                    `Bio` = '" . $_POST['Bio'] . "',
                    `ContactEmail` = '". $_POST['ContactEmail'] ."',
                    `PhoneNo` = '". $_POST['PhoneNo'] ."',
                    `TwitterHandle` = '". $_POST['TwitterHandle'] ."'
                    WHERE
                    `UserID` = '{$_SESSION['userID']}'
                    ";

echo $updateuser_sql;

It'll spit out the UPDATE statement that is sent to the database. I didn't see any syntax errors from the above. I suspect the problem has to do with your custom "myre" function.

Sign up to request clarification or add additional context in comments.

6 Comments

Hi Lloyd, yes, if I put all that at the bottom it works. However, it still doesn't work in a function... The function is getting called though.
@JamesAnderson585 Can you post what your custom function looks like?
"'" . $var . "'" is not correct wrapping, also you need str_replace("'", "''", $var)
We asked for myre function, or better SQL from "if I put all that at the bottom it works"
@JamesAnderson585 Is this the same function you're using in your code? This looks like it does something entirely different than from how the "myre" function is being used in your original question
|

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.