I cannot upload to the database drop down menu variables, when the form is submitted the text area is blank. I am new to coding and all of the information I have found thus far has been unable to help me. The students first and last names are submitting fine I just now need to process their grades
These are the Subjects:
English<br>
<select name="Grade">
<option value="-">-</option>
<option value="A*">A*</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="Fail">Fail</option>
</select><br>
Maths<br>
<select name="Grade2">
<option value="-">-</option>
<option value="A*">A*</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="Fail">Fail</option>
</select><br>
Science<br>
<select name="Grade3">
<option value="-">-</option>
<option value="A*">A*</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="Fail">Fail</option>
</select><br>
I need to upload them to here:
$DB_HOST = "localhost";
$DB_USERNAME = "admin";
$DB_PASSWORD = "chichester";
$DB_NAME = "results";
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$examboard = $_POST["examboard"];
$grade = $_POST["grade"];
$grade2 = $_POST["grade2"];
$grade3 = $_POST["grade3"];
$additionalcomments = $_POST["Additional Comments"];
$conn = new mysqli($DB_HOST, $DB_USERNAME, $DB_PASSWORD, $DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO studentresults (Name,lastname,examboard,additionalcomments) VALUES ('$fname','$lname','$examboard','$grade','$grade2','$grade3','$additionalcomments')";
$sql = "INSERT INTO studentresults (grade, grade2, grade3) VALUES ('$grade','$grade2','$grade3')";
if ($conn->query($sql) === TRUE) {
echo "Student exam results have been successfully submitted. ";
} else {
echo "Error, please try again later. : " . $sql . "<br>" . $conn->error;
}
//close connection
$conn->close();
Now how do I overcome this, the script and database does not show an errors. All I need to do is process a series of exam results and display this in a database. The tag seems to have confused matters.
1) you are updating the insert query.
2) The query you have written is wrong as there number of columns is different than the number of values given.
3) $_POST["Additional Comments"]; this won't work, as array key cannot contain space.
Why do you have two $sql insert statements? Only use one.
INSERT INTO ___ (col1,col2) VALUES ('data1','data2');
You can't have spaces in $_POST['']; variables.
Related
I tried inserting some license generated kes from a for loop into the database but I was getting Errormessage: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'keys)values('46F2-SH73-2QDD-Z4VH-HV')' at line 1
I have been on it for sometime now trying to fiure it but it gives the same error everytime I run it.
Here is my code:
<?php
//ob_start();
//session_start();
//error_reporting(0);
//ini_set('display_errors', '0');
date_default_timezone_set('Africa/Lagos');
#$db = parse_ini_file("../config/db.ini");
$dbhost = 'localhost'; //$db['host'];
$dbuser = 'root';//$db['user'];
$dbpass = '';//$db['pass'];
$dbname = 'infonetsch_mgmt';//$db['dbname'];
//Connect
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()) {
printf("MySQLi connection failed: ", mysqli_connect_error());
exit();
}
// Change character set to utf8
if (!$mysqli->set_charset('utf8')) {
printf('Error loading character set utf8: %s\n', $mysqli->error);
}
?>
<html>
<head>
<title>License Key Generator</title>
</head>
<body style="background-color:#F0F0F0">
<h1>License Key generation</h1>
<form method="POST" action="">
<table>
<tr>
<td>Keys to generate</td>
<td><select name="numkeys">
<option value="1">1</option>
<option value="5" selected>5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="5000">5000</option>
<option value="10000">10000</option>
<option value="20000">20000</option>
<option value="50000">50000</option>
</select></td>
</tr>
<tr>
<td>Length of Key</td>
<td><select name="keylen">
<option value="8">8</option>
<option value="10">10</option>
<option value="12">12</option>
<option value="14">14</option>
<option value="16">16</option>
<option value="18">18</option>
<option value="20">20</option>
</select></td>
</tr>
</table>
<input name="validate" type="submit" value="Generate!"/>
</table>
</form>
<?php
if(isset($_POST['validate'])){
$name= 'a';//$_POST['client'];
$software= 'sis';//$_POST['software'];
$numkeys=$_POST['numkeys']; if($numkeys<1)$numkeys=1; if($numkeys>50000)$numkeys=50000;
$keylen=$_POST['keylen'];if($keylen<1)$keylen=1; if($keylen>20)$keylen=20;
include("license_key.class.php");
$pass=new license_key();
echo "<h3>Generating $numkeys Random License Keys </h3>
KeyLenght: $keylen</a><hr/>";
for($i=0;$i<$numkeys;$i++){
$pass->keylen=$keylen;
$key= $pass->codeGenerate($name.$software);
$get = mysqli_query($mysqli, "insert into license_keys(keys)values('".$key."')");//Insert query
$j=$i+1;
echo "$j- $key <br/>";
}
if($get){
echo "Done";
}else{ printf("Errormessage: %s\n", $mysqli->error);; }
echo "<br/><br/>Generate again<br/><br/>";
}
?>
</body>
</html>
Why am I getting such an error?
There could be some special charaters in your license keys. Try using prepare statement with reference from https://www.w3schools.com/php/php_mysql_prepared_statements.asp as
$stmt = $mysqli->prepare("insert into license_keys (`keys`) values(?)");
$stmt->bind_param("s", $key);
$stmt->execute();
run that code and check your keys field varchar limit
<?php
//ob_start();
//session_start();
//error_reporting(0);
//ini_set('display_errors', '0');
date_default_timezone_set('Africa/Lagos');
#$db = parse_ini_file("../config/db.ini");
$dbhost = 'localhost'; //$db['host'];
$dbuser = 'root';//$db['user'];
$dbpass = '';//$db['pass'];
$dbname = 'infonetsch_mgmt';//$db['dbname'];
//Connect
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()) {
printf("MySQLi connection failed: ", mysqli_connect_error());
exit();
}
// Change character set to utf8
if (!$mysqli->set_charset('utf8')) {
printf('Error loading character set utf8: %s\n', $mysqli->error);
}
?>
<html>
<head>
<title>License Key Generator</title>
</head>
<body style="background-color:#F0F0F0">
<h1>License Key generation</h1>
<form method="POST" action="">
<table>
<tr>
<td>Keys to generate</td>
<td><select name="numkeys">
<option value="1">1</option>
<option value="5" selected>5</option>
<option value="10">10</option>
<option value="20">20</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="1000">1000</option>
<option value="5000">5000</option>
<option value="10000">10000</option>
<option value="20000">20000</option>
<option value="50000">50000</option>
</select></td>
</tr>
<tr>
<td>Length of Key</td>
<td><select name="keylen">
<option value="8">8</option>
<option value="10">10</option>
<option value="12">12</option>
<option value="14">14</option>
<option value="16">16</option>
<option value="18">18</option>
<option value="20">20</option>
</select></td>
</tr>
</table>
<input name="validate" type="submit" value="Generate!"/>
</table>
</form>
<?php
if(isset($_POST['validate'])){
$name= 'a';//$_POST['client'];
$software= 'sis';//$_POST['software'];
$numkeys=$_POST['numkeys']; if($numkeys<1)$numkeys=1; if($numkeys>50000)$numkeys=50000;
$keylen=$_POST['keylen'];if($keylen<1)$keylen=1; if($keylen>20)$keylen=20;
include("license_key.class.php");
$pass=new license_key();
echo "<h3>Generating $numkeys Random License Keys </h3>
KeyLenght: $keylen</a><hr/>";
for($i=0;$i<$numkeys;$i++){
$pass->keylen=$keylen;
$key= $pass->codeGenerate($name.$software);
$get = mysqli_query($mysqli, "INSERT INTO license_keys (keys) VALUES('".$key."')");//Insert query
$j=$i+1;
echo "$j- $key <br/>";
}
if($get){
echo "Done";
}else{ printf("Errormessage: %s\n", $mysqli->error);; }
echo "<br/><br/>Generate again<br/><br/>";
}
?>
</body>
</html>
Please read the SQL error correctly.
MySQL is throwing an SQL syntax error, so your insert query has incorrect syntax.
insert into license_keys(`keys`) values(?)
Put a space between the license_keys(keys) and the 'values'
Also put backticks around the 'keys' column.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I am trying to take the input from drop down menus that users enter and submit them to a table in my database. I am trying to submit the values into this table:
I use the POST to check that the values are being pulled from the HTML form and they are, but they won't submit into my table. I've made sure that all of the names with the columns and HTML forms are correct, why won't the values post to the table?
<?php
$databaseName = 'pizza_db';
$databaseUser = 'root';
$databasePassword = 'root';
$databaseHost = '127.0.0.1';
$conn = new mysqli($databaseHost, $databaseUser, $databasePassword, $databaseName);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected sucessfully\n";
if(isset($_POST['submit'])){
$value = mysqli_real_escape_string($conn,$_POST['drink']);
$value2 = mysqli_real_escape_string($conn,$_POST['cheese']);
$value3 = mysqli_real_escape_string($conn,$_POST['veggies']);
$value4 = mysqli_real_escape_string($conn,$_POST['meat']);
$value5 = mysqli_real_escape_string($conn,$_POST['sauce']);
$value6 = mysqli_real_escape_string($conn,$_POST['crust']);
$value7 = mysqli_real_escape_string($conn,$_POST['size']);
$sql = "INSERT INTO order_info(drink,cheese,veggies,meat,sauce,crust,size)
VALUES('$value','$value2','$value3','$value4','$value5','$value6','$value7')";
//Here I am posting the values to check that they are being submitted
echo $_POST["size"];
echo "\n";
echo $_POST["sauce"];
echo "\n";
echo $_POST["crust"];
echo "\n";
echo $_POST["cheese"];
echo "\n";
echo $_POST["meat"];
echo "\n";
echo $_POST["veggies"];
echo "\n";
echo $_POST["drink"];
$conn->close();
}
?>
<!DOCTYPE html>
<html>
<body>
<form action='' method='post'>
<p>Choose a size<p>
<select id="size" name="size">
<option value="small">Small</option>
<option value="medium">Medium</option>
<option value="large">Large</option>
<option value="x-large">X-large</option>
</select>
<p> Choose a sauce <p>
<select id="sauce" name="sauce">
<option value="none">None</option>
<option value="marinara">Marinara</option>
<option value="alfredo">Alfredo</option>
<option value="ranch">Ranch</option>
<option value="bbq">BBQ</option>
</select>
<p> Choose a cheese<p>
<select id="cheese" name="cheese">
<option value="none">None</option>
<option value="mozzarelaa">Mozarella</option>
<option value="cheddar">Cheddar</option>
<option value="parmesan">Parmesan</option>
<option value="three cheese">Three-Cheese</option>
</select>
<p> Choose a meat <p>
<select id="meat" name="meat">
<option value="none">None</option>
<option value="Pepperroni">Pepperroni</option>
<option value="sausage">Sausage</option>
<option value="bacon">Bacon</option>
<option value="canadian bacon">Canadian Bacon</option>
<option value="chicken">Chicken</option>
<option value="salami">Beef</option>
<option value="anchovies">Anchovies</option>
</select>
<p> Choose a veggies <p>
<select id="veggies" name="veggies">
<option value="none">None</option>
<option value="onions">Onions</option>
<option value="green peppers">Green Peppers</option>
<option value="Red peppers">Red peppers</option>
<option value="Black olives">Mushrooms</option>
<option value="jalapenos">Jalapenos</option>
<option value="tomatoes">Tomatoes</option>
<option value="pineapple">Pineapple</option>
</select>
<p> Choose a crust <p>
<select id="crust" name="crust">
<option value="regular">Regular</option>
<option value="deep-dish">Deep-dish</option>
<option value="thin-crust">Thin Crust</option>
<option value="stuffed crust">Stuffed Crust</option>
<option value="gluten free">Gluten Free</option>
</select>
<p> Choose a drink <p>
<select id="drink" name="drink">
<option value="none">None</option>
<option value="rootbeer">Root Beer</option>
<option value="coke">Coke</option>
<option value="diet coke">Diet Coke</option>
<option value="dr pepper">Dr Pepper</option>
</select>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
Seems like you are not running the query.
// sql
$sql = "INSERT INTO order_info(drink,cheese,veggies,meat,sauce,crust,size)
VALUES('$value','$value2','$value3','$value4','$value5','$value6','$value7')";
// run query
mysqli_query($conn, $sql);
// or
$conn->query($sql);
You prepared string query but you are not executing it.
$sql = "INSERT INTO order_info(drink,cheese,veggies,meat,sauce,crust,size)
VALUES('$value','$value2','$value3','$value4','$value5','$value6','$value7')";
// run query with below mentioned function
mysqli_query($conn, $sql);
Then check your table. You will see the data saved.
I want to insert the selected status timestamps in the corresponding column which user has chosen from the menu.
Brief explanation
Start from the database i have created columns like snap below.
Initially user will insert the sonumber and status, Now i need database to update current time and date in the database, remaining column initialized to zero.
Next user will select update option, here user will enter so-number as well as new status(from dropdown). Now i need database to update the new status with current time and store in the particular status column.
Starting with insert page saved as "insert.html" and "insert.php" Respectively
<form id="form1" name="form1" method="post" action="insert.php" >
<p>
<lable>ENTER SO NUMBER</lable>
<input type="text" name="soid" id="soid" maxlength="6" required>
<p>
<lable>SELECT DEPARTMENT</lable>
<select type="text" name="dept" id="dept">
<option value="NGS Analysis">NGS Analysis</option>
<option value="E-Array">E-Array</option>
<option value="Micro-Array">Micro-Array</option>
<option value="NGS Data">NGS Data</option>
</select>
</p>
<p>
<lable>SELECT STATUS</lable>
<select type="text" name="status" id="status">
<option value="Sample Recived">Sample Recived</option>
<option value="Mol Bio Extraction">Mol-Bio Extraction</option>
<option value="Extraction QC">Extraction QC</option>
<option value="Library Prep">Library Prep</option>
<option value="Library QC">Library QC</option>
<option value="Sequencing">Sequencing</option>
<option value="Data check">Data Check</option>
<option value="Re-Sequencing">RE-Sequencing</option>
<option value="QC Check">QC Check</option>
<option value="Analysis Started">Analysis Started</option>
<option value="Analysis Completed">Analysis Completed</option>
<option value="Report">Report</option>
<option value="Outbound">Outbound</option>
</select>
</p>
<p><button><img src="http://brandonmadeawebsite.com/images/art/icons/insert_icon.png" height="50" />INSERT</button></p>
</form>
insert.php
<?php
$so = $_POST['soid'];
$dp = $_POST['dept'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "status";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}
$result = mysqli_query($conn, "INSERT INTO $dbname.statusinfo (soid, dept ) VALUES ( '$so','$dp')") or die(mysqli_error($conn));
echo "Inserted sucessfully with So Number <u><b>$so</b></u> Corresponding Status is <u><b>$st</b></u>";
$conn->close();
?>
Now below update script which is saved as "update.html","update.php" respectively
<form action="update.php" method="post" name="form2">
<p>
<lable>ENTER SO NUMBER</lable>
<input type="text" name="soid" id="soid" required>
<p>
<lable>SELECT STATUS</lable>
<select type="text" name="status" id="status">
<option value="Sample Recived">Sample Recived</option>
<option value="Mol Bio Extraction">Mol-Bio Extraction</option>
<option value="Extraction QC">Extraction QC</option>
<option value="Library Prep">Library Prep</option>
<option value="Library QC">Library QC</option>
<option value="Sequencing">Sequencing</option>
<option value="Data check">Data Check</option>
<option value="Re-Sequencing">RE-Sequencing</option>
<option value="QC Check">QC Check</option>
<option value="Analysis Started">Analysis Started</option>
<option value="Analysis Completed">Analysis Completed</option>
<option value="Report">Report</option>
<option value="Outbound">Outbound</option>
</select>
</p>
<p><button><img src="http://icons.iconarchive.com/icons/icons8/windows-8/32/User-Interface-Available-Updates-icon.png" height="50" /> UPDATE</button></p>
</form>
update.php
<?php
$so = $_POST['soid'];
$st = $_POST['samplerecived'];
$st1 = $_POST['molbioextraction'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "status";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}
switch ($st):
case $st:$result = mysqli_query($conn, "UPDATE statusinfo SET `samplerecived`= CURTIME() WHERE soid='$so' ") or die(mysqli_error($conn));
break;
case $st1:$result1 = mysqli_query($conn, "UPDATE statusinfo SET `molbioextraction`= CURTIME() WHERE soid='$so' ") or die(mysqli_error($conn));
break;
echo "Updated sucessfully with So Number $so Current Status is set to $st ";
$conn->close();
?>
Kindly help me to do so, if you guys need any more information feel free to ask.
Thanks in advance
If I understand your problem correctly, you only need the user selected fields to be inserted and the other to be either NULL or some default value.
You have the default value for all the fields set as CURRENT_TIMESTAMP. This is why all the fields are being assigned a default value of the current timestamp. Remove the default value, allow them to be NULL (or set some default value other than CURRENT_TIMESTAMP) and your problem will be solved.
I am developing a script for a table called 'minivan'. Here is the table structure sql fiddle link. Admin provides seats for minivan.
I want to check if seats are available from this search form: search form link The method is GET.
First i want to check the date [this is format of date: 2015-02-16 for example] that a user submits. If the date matches i want to proceed with 'from' and 'to' location that a user chooses. If records are found i want to check what is the total passenger from the dropdown list for different ages that a users provides.
If the total number of passenger does not exceed the seat number for a particular day that a user chooses, i want to echo "seats are available". and proceed with other parts that i am planning to develop later.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
if (isset($_GET['submit'])) {
$date = $_GET['date_up'];
$query = "SELECT date_up FROM minivan WHERE date_up = '$date'";
$result = mysqli_query($conn, $query);
$numrows = mysqli_num_rows($result);
//print_r($numrows);
if ($numrows)
{
$startPlace = $_GET['startpoint'];
$query2 = "SELECT startpoint FROM minivan WHERE startpoint = '$startPlace'";
$result2 = mysqli_query($conn, $query2);
//print_r($result2);
$numrows2 = mysqli_num_rows($result2);
$endPlace = $_GET['endpoint'];
$query3 = "SELECT endpoint FROM minivan WHERE endpoint = '$endPlace'";
$result3 = mysqli_query($conn, $query3);
//print_r($result2);
$numrows3 = mysqli_num_rows($result3);
if ($numrows2 && $numrows3) {
$adult = $_GET['adult'];
$juvenile = $_GET['juvenile'];
$kids = $_GET['kids'];
$child = $_GET['child'];
$totalPassenger = $adult + $juvenile + $kids + $child ;
$seatQuery = "SELECT seat FROM minivan WHERE seat > $totalPassenger";
$result4 = mysqli_query($conn, $seatQuery);
$numrows4 = mysqli_num_rows($result4);//shows error here how to fix it?
if ($numrows4) {
while ($row = mysqli_fetch_row($result4)) {
$seats = $row[0];
echo "$seats are availble for the $date you selected";
}
} else {
echo "no seats are found";
}
}
} else {
"start point and end point does not match";
}
}
$conn->close();
?>
It shows error here $numrows4 = mysqli_num_rows($result4);//shows error here how to fix it?
here is the form i am trying to search with
<form action="" method="GET">
From
<select name="startpoint" id="from">
<option >Hat Yai Airport</option>
<option >Pak Bara</option>
<option >Kohlipe</option>
</select>
To
<select name="endpoint" id="to">
<option >Pak Bara</option>
<option >Hat Yai Airport</option>
<option >Kohlipe</option>
</select>
<label for="Date">Date</label>
<input type="text" name="date_up" id="datepicker">
<h4 style="margin-top: 30px;">Passengers</h4>
Adults
<select name="adult" id="from">
<option >1</option>
<option >2</option>
<option >3</option>
<option >4</option>
<option >5</option>
</select>
< 12 years
<select name="juvenile" id="to">
<option >0</option>
<option >1</option>
<option >2</option>
<option >3</option>
<option >4</option>
</select>
< 7 years
<select name="kids" id="from">
<option >0</option>
<option >1</option>
<option >2</option>
<option >3</option>
</select>
< 3 years
<select name="child" id="to">
<option >0</option>
<option >1</option>
<option >2</option>
<option >3</option>
</select>
<input type="submit" value="Search" class="submit" name="submit">
Can't really figure out whats wrong with this. I am beginner in php and mysql. Please help me solve this.
Please help me
I want to search the data of employee by month like january, february etc. by drop down list
and the date field is date type 0000-00-00.How can I search this type of data in php
thank you..
<code>
<select name="month" id="month">
<option>
</option>
<option>
January
</option>
<option>
February
</option>
<option>
March
...
You first need to give your form options some values for the month numbers. This will be queried by your database. You action can be the page that you want to display the data
<form method="post" action="process.php">
<select name="month" id="month">
<option></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
</select>
</form>
process.php
the "username" and "password" and the database username and password used to connect to the database
<?php
// Make a MySQL Connection
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database_name") or die(mysql_error());
$date = mysql_real_escape_string($_POST['month']);
// Retrieve all the data from the "example" table
//set date_column to the date field in your database
$sql ="SELECT * FROM table_name WHERE MONTH(date_column) = $date";
$result = mysql_query($sql)
or die(mysql_error());
// store the record of the "example" table into $row
while($row = mysql_fetch_array($result)){
// Print out the contents of the entry
extract($row, EXTR_PREFIX_INVALID, '_');
//change these to whatever you want to display
echo "Name: ".$row['column1'];
echo " Age: ".$row['column2'];
}
?>
EDIT:
I've rewritten it for you and i've tested it also. This is presuming you're using MySQLi
This uses prepared statement which make it more secure. Have a look here for more info http://mattbango.com/notebook/code/prepared-statements-in-php-and-mysqli/
In the SELECT statement you can put whatever tables you want but the rest should be good to go.
<html>
<head>
</head>
<body>
<form method="post" action="testing.php">
<select name="month" id="month">
<option></option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<input type="submit" value="submit" name="submit"/>
</form>
</body>
</html>
<?php
// Include connection file here and replace these variables
$hostname="localhost";
$username="username";
$password="password";
$dbname="dbasename";
/* Create a new mysqli object with database connection parameters */
$db = new mysqli($hostname, $username, $password, $dbname);
// Create statement object
$stmt = $db->stmt_init();
// Create a prepared statement
if($stmt->prepare("SELECT name, month, blah FROM test WHERE MONTH(month) = ?")) {
// Bind your variable to replace the ?
if(!$stmt->bind_param('s', $month)) {
//if BIND fails, display an error
printf("Errormessage: %s\n", $stmt->error);
}
// escape the POST data for added protection
$month = isset($_POST['month'])
? $db->real_escape_string($_POST['month'])
: '';
// Execute query
if(!$stmt->execute()) {
printf("Errormessage: %s\n", $stmt->error);
}
// Bind your result columns to variables
if(!$stmt->bind_result($name, $url, $logo)) {
printf("Errormessage: %s\n", $stmt->error);
}
// Fetch the result of the query
while($stmt->fetch()) {
echo $name;
}
// Close statement object
$stmt->close();
}
?>