Hello dear stackoverflow users,
I am having a strange problem. I have a 2 page form.
page 1 is index.php:
<form action="insert.php" method="post">
<div class="slider"><input type="checkbox" onclick="this.form.checkbox1.checked = this.checked;" id="slider" name="10001" value="10001"><label for="slider"></label></div>
<input type="checkbox" value="127.20" id="checkbox1" name="chk"/>
<input type="submit">
</form>
page 2 is insert.php
<?php
$q=$_GET["q"];
// Load Joomla! configuration file
require_once('configuration.php');
// Create a JConfig object
$config = new JConfig();
// Get the required codes from the configuration file
$server = $config->host;
$username = $config->user;
$password = $config->password;
$database = $config->db;
$con = mysqli_connect($server,$username,$password,$database);
if (!$con){
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,$database);
$q = mysqli_real_escape_string($con,$q);
// Save form input
$10001 = $POST_['10001'];
$sql_add = "INSERT INTO cypg8_testtest (10001) VALUES ('$10001')";
$result_add = $mysqli->query($sql_add);
// Close connection
mysqli_close($con);
?>
The database table is called: cypg8_testtest
This table has 2 columns and is setup as this:
id | 10001
Where id is a column and 10001 is a column.
I have been looking on the internet and tried using several methods including:
- http://www.mustbebuilt.co.uk/php/insert-update-and-delete-with-mysqli/
- http://codular.com/php-mysqli
- mysqli does not save to my database
- http://www.w3schools.com/php/php_mysql_insert.asp
- Send html form data to sql database via php (using mysqli)
But i do not know why none of them are working. I get all kinds of errors like unexpected 10001 or unexpected ;
With the code above i get the following error: Parse error: syntax error, unexpected '10001' (T_LNUMBER), expecting variable (T_VARIABLE) or '$'
I want to save the value(value=10001) from the first checkbox to table column 10001
Thanks for any help in advance.
EDIT 1: <== Solution is in here.
The code and database needed to change to make it work.
In the database the table column name needed to start with a letter so this is changed from 10001 to a10001
Then the checkbox name needed to change also to a10001 to make it correspond with the db table column.
The Save form input needed some changes as well this is easier to see in code. So i put both codes below for easy reference.
page 1 is index.php:
<form action="insert.php" method="post">
<div class="slider"><input type="checkbox" onclick="this.form.checkbox1.checked = this.checked;" id="slider" name="a10001" value="10001"><label for="slider"></label></div>
<input type="checkbox" value="127.20" id="checkbox1" name="chk"/>
<input type="submit">
</form>
page 2 is insert.php
<?php
$q=$_GET["q"];
// Load Joomla! configuration file
require_once('configuration.php');
// Create a JConfig object
$config = new JConfig();
// Get the required codes from the configuration file
$server = $config->host;
$username = $config->user;
$password = $config->password;
$database = $config->db;
$con = mysqli_connect($server,$username,$password,$database);
if (!$con){
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,$database);
$q = mysqli_real_escape_string($con,$q);
// Save form input
$a10001 = $_POST['a10001'];
mysqli_query($con,"INSERT INTO cypg8_testtest (a10001) VALUES ('".$a10001."')");
// Close connection
mysqli_close($con);
?>
Thank you to everyone who helped getting me to the answer. And special thanks for Arian with supplying the solution.