Code: Select all
$query = "insert into $tableName ($fields) values ($values)";
Moderators: egami, macek, gesf
Code: Select all
$query = "insert into $tableName ($fields) values ($values)";
Code: Select all
<?php
if(isset($HTTP_POST_VARS["submit"])){
//variables must have a value :) with your server and database information
$conection=mysql_connect($server,$login,$pass); mysql_select_db($database,$conection);
$sql= "INSERT INTO ".$table." VALUES (NULL,'$check1','$check2', '$check3')";//this will produce an insert in the database. the first value (NULL) is the autoincrement ID
mysql_query($sql);
}else{
?>
<h3>Introduce values to database</h3><p>
<form action="<?php echo $php_self; ?>" method="post">
Select fruits:<br>
apples: <input type="checkbox" name="check1" value="apples"><br>
oranges: <input type="checkbox" name="check2" value="oranges"><br>
lemons: <input type="checkbox" name="check3" value="lemons"><p>
<input type="submit" name="submit" value="Submit!">
<?php
}//end else
?>
Code: Select all
$sql= "INSERT INTO ".$table." VALUES (NULL,'$check[0]','$check[1]', '$check[2]')
Code: Select all
<?php
if(isset($HTTP_POST_VARS["submit"])){
echo "<h2>fruits</h2>";
echo $HTTP_POST_VARS["fruits"][0]."<br>";
echo $HTTP_POST_VARS["fruits"][1]."<br>";
echo $HTTP_POST_VARS["fruits"][2]."<p>";
echo "<h2>animals</h2>";
echo $HTTP_POST_VARS["animals"][0]."<br>";
echo $HTTP_POST_VARS["animals"][1]."<br>";
echo $HTTP_POST_VARS["animals"][2]."<p>";
echo "<h2>array structure</h2>";
echo "<pre>";
print_r ($HTTP_POST_VARS);
echo "</pre>";
}else{
?>
<h3>Introduce values to database</h3><p>
<form action="<?php echo $php_self; ?>" method="post">
Select fruits:<br>
apples: <input type="checkbox" name="fruits[]" value="apples" checked><br>
oranges: <input type="checkbox" name="fruits[]" value="oranges" checked><br>
lemons: <input type="checkbox" name="fruits[]" value="lemons" checked><p>
Select animals:<br>
apples: <input type="checkbox" name="animals[]" value="dogs" checked><br>
oranges: <input type="checkbox" name="animals[]" value="cats" checked><br>
lemons: <input type="checkbox" name="animals[]" value="humans" checked><p>
<input type="submit" name="submit" value="Submit!">
<?php
}//end else
?>
fruits
apples
oranges
lemons
animals
dogs
cats
humans
array structure
Array
(
[fruits] => Array
(
[0] => apples
[1] => oranges
[2] => lemons
)
[animals] => Array
(
[0] => dogs
[1] => cats
[2] => humans
)
[submit] => Submit!
)