Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to prepare an insertion inside the database with php, but i can't find any suggestions on how to use the syntax, this is what I've got so far, could someone help me with this please?
$last_id = mysqli_insert_id($conn);
$query = $conn->prepare("INSERT INTO `table`(name, surname) VALUES (?,?) , (?,?)");
$query->bind_param("ss", ($nameOne, $last_id), ($nametWO, $last_id));
the binding should be
$query->bind_param("ssss", $nameOne, $last_id, $nametWO, $last_id);
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
So lately I've tried my attempt at SQL, and PHP, and other such, I've come to a problem that of which being: INSERT INTO, just can't seem to work for me. Here's what I have in the PHP file:
$sql = "INSERT INTO forum(USERID, FN, LN, Email) VALUES (NULL,'".$_POST['FN']."', '".$_POST['LN']."', '".$_POST['Email']."';";
This string works, however, I get This error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
Would anyone be able to provide info on this?
You must close the parenthesis:
$sql = "INSERT INTO forum(USERID, FN, LN, Email) VALUES (NULL,'".$_POST['FN']."', '".$_POST['LN']."', '".$_POST['Email']."');";
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I get this error while trying to update. The query works in phpmyadmin just fine.
Was a bind error, all fixed thanks to the great people here.
That's because you've got typo in your parameters.
You are using :serreceivetxt instead of :userreceivetxt and :serreceiveemail instead of :userreceiveemail.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Possible duplicate, but I lost hours on this one
$stmt=$mysql->prepare(" insert into test_booked_tickets(book_id, ticket_id, num_people) values(:book_id,:ticket_id,:num)");
echo (int)$ticket->id."<br/>";
echo (int)$ticket->number_people."<br/>";
echo (int)$booking->id."<br/>";
$stmt->bindValue(":ticket_id", (int)$ticket->id);
$stmt->bindValue(":num", (int)$ticket->number_people);
$stmt->bindValue(":book_id", (int)$booking->id);
try{
$stmt->execute();
}
catch(PDOException $e){
echo "catched <br/>";
echo $e->errorInfo;
}
Other queries work perfectly. These are the returned values from echo
30
1
10
It doesn't get into catch, and it doesn't insert into table...
Thanks everyone for useful comments, I had a typo in database, column name.
Thanks A.O. for the most useful comment.
And thanks everyone else for other useful suggestions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
Can someone tell me what is wrong with that statement cause I do not see any mistake?
$PrevReleaseModel = $con->prepare("SELECT * FROM model WHERE model_name=:model_name AND model_release:model_release");
$PrevReleaseModel->bindParam('model_name',$model_name);
$PrevReleaseModel->bindParam('model_release',$model_release);
$PrevReleaseModel->execute(array('model_name'=>$model_name,'model_release'=>$model_release));
I am really confused.
WHERE model_name=:model_name AND model_release = :model_release
You missed a equal sign in the last condition.
You may try this out:-
$PrevReleaseModel = $con->prepare('SELECT * FROM model
WHERE model_name = :model_name AND
model_releas = :model_releas'
);
$PrevReleaseModel->bindParam(':model_name', $model_name, PDO::PARAM_STR);
$PrevReleaseModel->bindParam(':model_releas', $model_release, PDO::PARAM_STR);
$PrevReleaseModel->execute();
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
the below query is not working
$query= mysql_query('SELECT * FROM Registration WHERE name="'.$_POST['Username'].'" & password="'.$_POST['Password']);
Use the word SET once only in your query. And separate each data by comma(,).
You should also consider escaping the string of your variables before using them into your query.
If you are using MySQLi, you can do this:
$username=mysqli_real_escape_string($connection,$_POST['Username']);
$password=mysqli_real_escape_string($connection,$_POST['Password']);
$city=mysqli_real_escape_string($connection,$_POST['City']);
$state=mysqli_real_escape_string($connection,$_POST['State']);
$country=mysqli_real_escape_string($connection,$_POST['Country']);
$userid=mysqli_real_escape_string($connection,$_POST['user_id']);
$query="UPDATE Registration SET name='$username', password='$password', city='$city', state='$state', country='$country' WHERE id='$userid'";
mysqli_query($connection,$query); /* EXECUTE QUERY */
Use , instead of set between each fields. Use this altered query,
('UPDATE Registration SET name="'.$_POST['Username'].'" , password="'.$_POST['Password'].'" , city="'.$_POST['City'].'" , state="'.$_POST['State'].'" , country="'.$_POST['Country'].'" WHERE id='.$_POST['user_id']);