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:


$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" />



$stmt = mysqli_prepare($con, "INSERT INTO table(id,s_id,date,time) VALUES(null,?,?,?)");
mysqli_stmt_bind_param($stmt, "iss", $id,$d,$t);
foreach($s_id as $val){
    $id = $val;
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);
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, learning, and sharing knowledge.