Reputation: 615
I have a table in a mysql database with only two columns and I want to insert data in both columns on the same row simultaneously using php. I have tried the following php script
but it inserts data in the one row then the other as follows:
1-NULL
NULL-4
I want both 1 and 4 to be on the same row. Here's my php script
:
<?php
$first_value = 1;
$second_value = 2;
$qry = "INSERT INTO my_table (first_value) VALUES ('$first_value')";
$qry .= "INSERT INTO my_table (second_value) VALUES ('$second_value')";
if($conn->multi_query($qry) === TRUE){
echo "success";
}
else {
echo "Error: " . $qry . "<br>" . $conn->error;
}
$conn->close();
?>
It inserts successfully. But I want the insert to be on the same row. Any help will be greatly appreciated.
Upvotes: 1
Views: 347
Reputation: 133360
just use a proper insert
$qry = "INSERT INTO my_table (first_value, second_value)
VALUES ('$first_value', '$second_value')";
Upvotes: 1