How to insert data in two tables at the same time (SQL server)

Joined
Feb 28, 2016
Messages
1
<?php
include 'conn.php';
$affected_rows = $conn->exec("INSERT into tbl_ideas1 (week_no,category,problem,solution,id_no) Values ('".$_POST["week_no"]."','".$_POST["category"]."','".$_POST["problem"]."','".$_POST["solution"]."','".$_POST["id_no"]."')");


$affected_rows = $conn->exec("Insert into tbl_sub (idea_no,week_no,category,problem,solution,id_no) Values ('".$idea."','".$_POST["week_no"]."','".$_POST["category"]."','".$_POST["problem"]."','".$_POST["solution"]."','".$_POST["id_no"]."')");

/* $affected_rows = $conn->exec("INSERT into tbl_sub (week_no,category,problem,solution,Fname,Mname,Lname,building,cluster,id_no) Values ('".$_POST["week_no"]."','".$_POST["category"]."','".$_POST["problem"]."','".$_POST["solution"]."','".$_POST["Fname"]."','".$_POST["Mname"]."','".$_POST["Lname"]."','".$_POST["building"]."','".$_POST["cluster"]."','".$_POST["id_no"]."')"); */


echo "<script language=\"Javascript\">alert('Submitted Successfully!');self.location=\"send_ideas.php\"</script>";
?>
 
Thats some of the worst code I've ever seen - and I've seen a lot of bad php. Sheesh.
 
Nothing in that indicates it needs to be "at the same time"..

... Also use parameters.
 
xkcd: Exploits of a Mom
bc8Be4b.png
 
Keep in mind incoming $_POST can be crafted without the need for a html form. So, client side checks are useless.
Also, you could try "read locking" the table for the time you're inserting. There are tutorials.
It will still be readable but not writeable.
 
Back
Top