jeudi 7 avril 2016

implode(): Invalid arguments passed in. Cant see the defined variable for the array

I have created the following checkbox form to display hobbies. The array enters into the database in the same cell which is perfect however, the following errors appear on the page before i have even submitted. ( I am new to this and any help would be greatly appreciated :))

Undefined index: hobbies in (line 29) Warning: implode(): Invalid arguments passed in (line 29)

The code:

$checkbox=implode(',', $_POST['hobbies']);

if(isset($_POST['Submit'])){

  //for($i=0; $i<sizeof($hobbies);$i++){

   $query=queryMysql("INSERT INTO hobbies  VALUES ('$user', '" .$checkbox. "')");

    mysql_query($query) or die(mysql_error());
    echo "record is inserted";
  }




echo <<<_END

<body>
<form method='post' action='hobbies.php' >
<input type="checkbox" name="hobbies[]" value="reading">Reading<br>
<input type="checkbox" name="hobbies[]" value="cycling">Cycling<br>
<input type="checkbox" name="hobbies[]" value="swimming">Swimming<br>
<input type="checkbox" name="hobbies[]" value="running">Running<br>
<input type="submit" name='Submit' value='Submit'/></form>
</body>
</html>




_END;
?>




Aucun commentaire:

Enregistrer un commentaire