I am just starting to learn PHP and MySQL by myself.
I have a form like this:
Upart1 | Upart2 | Utotal
Dpart1 | Dpart2 | DTotal
Its like a sports game with 2 periods and 2 teams competing.
And I have MySQL table 'test1' in database 'mydb' where is 4 columns: id | up_id | part1 | part2 | total
How I have this code to post data from one part of the table (Upper)
<?php
if(count($_POST) > 0){
$link = mysqli_connect("127.0.0.1", "root", "password", "mydb");
if(!$link){
echo "No connection: (" . mysqli_connect_errno(). ")";
}
else{
$statement = mysqli_prepare($link, "INSERT INTO test1(part1, part2, total) VALUES(?,?,?)");
if($statement){
mysqli_stmt_bind_param($statement, "sss", $_POST["Upart1"], $_POST["Upart1"], $_POST["Utotal"]);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($link);
}
}
}
?>
1) How can I make MySQL write data in two rows simultaneously after pressing 'submit'?
2) I think its better to use an array here (if I have more parts, not only two). And if I will use array how can I write 2 rows at once in MySql? Will it be multi-dimensional array?
you can use insert query inside for loop like:for($i=1; $i<=2; $i++){ **your insert query here** }