Hi there I am new at this website thanks for every one that help me

I have this output appear on the link below:

Click Here

I want to while I choosing a Time value this value must be send for these useres that absence row the checkbox is checked

this is my code:

 $s_id=$_POST['s_id'];
$date=$_POST['datee'];
$time=$_POST['time'];

for($i=0;$i<$num_rows;$i++)
{
$insert="INSERT INTO table(id,s_id,date,time) VALUES(null,'$s_id[$i]','$date','$time')";
mysqli_query($con,$insert)  or die(mysqli_error($con));
}

Recommended Answers

All 3 Replies

Use prepared statement instead of direct insert to prevent from SQL injection!
Naming checkboxes with empty quadratic brackets e.g.

<input type="checkbox" name="s_id[]" value="1" />
<input type="checkbox" name="s_id[]" value="2" />
<input type="checkbox" name="s_id[]" value="3" />

PHP

$s_id=filter_input(INPUT_POST,'s_id',FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
$date=filter_input(INPUT_POST,'datee');
$time=filter_input(INPUT_POST,'time');

$stmt = mysqli_prepare($con, "INSERT INTO table(id,s_id,date,time) VALUES(null,?,?,?)");
mysqli_stmt_bind_param($stmt, "iss", $id,$d,$t);
$d=$date;
$t=$time;
foreach($s_id as $val){
    $id = $val;
    mysqli_stmt_execute($stmt);
}
commented: Thank you Mr. Andrisp for your answer, I used you code but appear some warning, I don't understand PDO codes can you use MySQLi codes instead PDO? +0

@Talib_1 this is (procedural) MySQLi method not PDO. The PDO would look something like this:

$stmt = $con->prepare("INSERT INTO table(id,s_id,date,time) VALUES (null,:s_id,:date,:time)");
$stmt->bindParam(':date', $date, PDO::PARAM_STR);
$stmt->bindParam(':time', $time, PDO::PARAM_STR);
foreach($s_id as $val){
    $stmt->bindParam(':s_id', $val, PDO::PARAM_INT);
    $stmt->execute();
}
commented: Thanks @AndrisP for your answer, I used this code appear(Fatal error: Call to a member function bindParam() on boolean) at line 2, how fix it? +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.