-1

How would i put the $newd values into the database. The way I'm doing it now just puts one value in. I want all values.

<?php
$checked = $_POST['options'];
for($i=0; $i < count($checked); $i++){
    $newd = "" . $checked[$i] . ",";
}   
    if(isset($_POST['loginbtn'])){
        if(!empty($order)){

if($money){
    //making the sql command
    $sql = "INSERT INTO `orders`(`order`,`date`,`time`,`timepass`,`money`,`corder`,`cancel`,`category`) VALUES ('$order','$date','$timenow','$time','$money','$corder','$cancel','$newd')";

    //querying the sql
    $query = mysqli_query($db,$sql);

    $lastid = mysqli_insert_id($db);

    $twosql = "INSERT INTO `comments`(`order_id`, `comment`,`user`,`time`,`timepass`) VALUES ('$lastid','$comment','$username','$timenow','$time')";
    $twoquery = mysqli_query($db,$twosql);

    header("Location: moneyorder.php"); 

}
?>
2

2 Answers 2

1

You need a dot here, you are not concatenating the new values :)

$newd .=
Sign up to request clarification or add additional context in comments.

Comments

-1

You have to define first $newd variable on top else it will give error but please do the things as suggested by Alex Howansky in comment

$checked = $_POST['options'];
    $newd = '';
    for($i=0; $i < count($checked); $i++){
        $newd .= "" . $checked[$i] . ",";
    } 
$newd = rtrim($newd, ',');

   // OR you can use

    $newd = implode(",", $checked );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.