php - Receiving Error message when performing Update Statement
Get the solution ↓↓↓Solution:
Try this:
$sql = "UPDATE tblStudents
SET first_name = '{$pUInput[1]}',
last_name = '{$pUInput[2]}',
major = '{$pUInput[3]}',
year = '{$pUInput[4]}'
WHERE id = '{$pUInput[0]}'";
if(!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "1 record update";
And change this:
// Variables of User Input
$idnum = $_POST["idnum"];
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$major = $_POST["major"];
$year = $_POST["year"];
$action = $_POST["action"];
To:
// Variables of User Input
$idnum = mysql_real_escape_string($_POST["idnum"]);
$fname = mysql_real_escape_string($_POST["fname"]);
$lname = mysql_real_escape_string($_POST["lname"]);
$major = mysql_real_escape_string($_POST["major"]);
$year = mysql_real_escape_string($_POST["year"]);
$action = mysql_real_escape_string($_POST["action"]);
You might want to read up on sql injection.
Answer
Solution:
Your id-column is of a numeric value and you're comparing it to a string-value. Computer says no.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot access offset of type string on string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.