1

I have problem inserting my value to my database I have this code

<?php if(isset($_POST['next'])) {
for($x=1;$x<=$sites;$x++)
{

    $sql  = "SELECT * FROM  category where status = '1' ";
        $results = mysql_query($sql) or die(mysql_error()); 

        while($rows = mysql_fetch_array($results, MYSQL_ASSOC))
        {
        $cat="cat".$x;

        $site="site".$x;

        //echo $category."<br>";

        }
}   

        $items = array();
        $itemss = array();
        foreach($_POST['site'] as $value) {
            $items[] = $value;
            $sql  = "SELECT * FROM  sitelist where name = '$value' ";
            $results = mysql_query($sql) or die(mysql_error()); 

            while($rows = mysql_fetch_array($results, MYSQL_ASSOC))
            {
                $idc = $rows['name'];
                 $qx="INSERT INTO site (sitename) VALUES ('".$idc."')";
            $result=mysql_query($qx);
            }
        }

        $try = $_POST['checkbox'];
        $N = count($try);
        $tet = array();
        foreach($_POST['checkbox'] as $values) {
             $tet[] = $values;
             $lol = implode("','",$tet);
            //echo $values;
            echo $lol;
             //$qx="INSERT INTO site (studyid,sitename,category,status) VALUES ('".$studid."','".$total."','".$try[$i]."','1')";
                $qx = "UPDATE site 
                SET studyid='$studid',
                category='$lol',
                status = '1'                    
                WHERE sitename IN 
                  ( SELECT name 
                    FROM sitelist 

                  )";
            $result=mysql_query($qx);
            //echo($try[$i] . " ");

        }

}
?>

The form is a drop down combobox and a checbox which are not constant and depends on the value in the db. What I want is if user picks a value in combo box and also checed their deside category it will be save in my db in a 1 row I want an output something like this if the user have 2 combobox with different values and 4 checkbox each on every combobox Let say and the user pick combobox1 value 1 checkbox1 value1 checkbox 2 value 2 and combobox 2 checkbox3 value 3 checkbox4 value 4

but unfortunately the checkbox output on my code is like checkbox 1-4 is all the same value

Seymour
  • 7,043
  • 12
  • 44
  • 51
  • 2
    **Warning:** you're using [a **deprecated** database API](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) yourself from. – Marcel Korpel Dec 09 '13 at 14:16
  • thanks for notifying. Will change the structure as soon as a I finish this – user3073578 Dec 09 '13 at 14:37
  • Please indent your code properly. – gwaigh Dec 20 '13 at 03:52

0 Answers0