
Undefined index
Publicado por jesus (5 intervenciones) el 05/08/2015 19:21:24
Hola,
Tengo un problema con mi código me aparece el siguiente error:
Notice: Undefined index: orange in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: grapefruit in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: banana in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: orange in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: grapefruit in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: banana in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 28
Warning: mysqli_error(): Couldn't fetch mysqli in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 28
Error reading database:
Pero si me guarda los datos en mi Base me pueden apoyar se los agradeceria mucho
Codigo:
<?php
include("conexion.php");
$chkbox = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['btnsave']))
{ $fruit = $_POST['fruit'];
$values = array();
foreach($fruit as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
}
// var_dump($selection); Ver el arreglo de forma rapida
// MySQL statement.
for ($i=0; $i <sizeof($values) ; $i++) {
$insert = "INSERT INTO table_location2 (orange, apple, grapefruit, banana, watermelon)
VALUES ('".$values['orange']."', '".$values['apple']."','".$values['grapefruit']."', '".$values['banana']."','".$values['watermelon']."')";
// MySQL statement to execute the INSERT statement above.
mysqli_query($dbconnect, $insert) or die('<br/>Error reading database: '.mysqli_error($dbconnect));
mysqli_close($dbconnect);
}
} // End of, if statement from the button check
?>
<html>
<head>
<title>Checkbox</title>
<head>
<title>HTML Checkbox</title>
</head>
<body>
<h2> Pick your most favorite fruits: </h2>
<form name="fruitcheckbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="fruit[]" value="orange"> Orange
<input type="checkbox" name="fruit[]" value="apple"> Apple
<input type="checkbox" name="fruit[]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[]" value="banana"> Banana
<input type="checkbox" name="fruit[]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btnsave">
</form>
</body>
</html>
Muchas gracias!!!!!!!!!!!!! :)
Tengo un problema con mi código me aparece el siguiente error:
Notice: Undefined index: orange in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: grapefruit in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: banana in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: orange in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: grapefruit in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Notice: Undefined index: banana in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 23
Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 28
Warning: mysqli_error(): Couldn't fetch mysqli in C:\xampp\htdocs\molina\prueba_enc\prueba2.php on line 28
Error reading database:
Pero si me guarda los datos en mi Base me pueden apoyar se los agradeceria mucho
Codigo:
<?php
include("conexion.php");
$chkbox = array('orange', 'apple', 'grapefruit', 'banana', 'watermelon');
if(isset($_POST['btnsave']))
{ $fruit = $_POST['fruit'];
$values = array();
foreach($fruit as $selection )
{ if(in_array($selection, $fruit))
{ $values[ $selection ] = 1; }
else
{ $values[ $selection ] = 0; }
}
// var_dump($selection); Ver el arreglo de forma rapida
// MySQL statement.
for ($i=0; $i <sizeof($values) ; $i++) {
$insert = "INSERT INTO table_location2 (orange, apple, grapefruit, banana, watermelon)
VALUES ('".$values['orange']."', '".$values['apple']."','".$values['grapefruit']."', '".$values['banana']."','".$values['watermelon']."')";
// MySQL statement to execute the INSERT statement above.
mysqli_query($dbconnect, $insert) or die('<br/>Error reading database: '.mysqli_error($dbconnect));
mysqli_close($dbconnect);
}
} // End of, if statement from the button check
?>
<html>
<head>
<title>Checkbox</title>
<head>
<title>HTML Checkbox</title>
</head>
<body>
<h2> Pick your most favorite fruits: </h2>
<form name="fruitcheckbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="checkbox" name="fruit[]" value="orange"> Orange
<input type="checkbox" name="fruit[]" value="apple"> Apple
<input type="checkbox" name="fruit[]" value="grapefruit"> Grapefruit
<input type="checkbox" name="fruit[]" value="banana"> Banana
<input type="checkbox" name="fruit[]" value="watermelon"> Watermelon
<br>
<input type="submit" value="Save" name="btnsave">
</form>
</body>
</html>
Muchas gracias!!!!!!!!!!!!! :)
Valora esta pregunta


0