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.
Related
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 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.
I need some help, I am trying to insert into multiple tables using PDO - Can someone see what I am doing wrong - I am not getting a parse errors (nor did I set up an asset error):
Here is my form:
addcontact.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add New Contact</title>
<link rel="stylesheet" href="css/table.css" type="text/css" />
</head>
<body>
<div class="CSS_Table_Example" style="width:500px;height:350px;">
<center>
<form action="insert.php" method="post">
<p>
<td>
<tr><label for="ContactName">Contact Name:</label>
<input type="text" name="ContactName" id="ContactName">
</tr></p>
<p>
<tr> <label for="ContactTypeId">Contact Type:</label>
<select name="ContactTypeId">
<option value="1">Contact</option>
<option value="2">Organization</option>
</select>
</p>
<p>
<td>
<tr> <label for="AddressTypeId">Address Type:</label>
<select name="AddressTypeId">
<option value="1">Home</option>
<option value="2">Office</option>
<option value="3">Other</option>
</select>
</p>
<p>
<tr><label for="Address1">Address 1:</label>
<input type="text" name="Address1" id="Address1">
</tr></p>
<p>
<tr><label for="Address2">Address 2:</label>
<input type="text" name="Address2" id="Address1">
</tr></p>
<p>
<tr><label for="City">City:</label>
<input type="text" name="City" id="Address1">
</tr></p>
<tr> <label for="StateId">State:</label>
<select name="StateId">
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option>
<option value="5">Califorina</option>
<option value="6">Colorado</option>
<option value="7">Connecticut</option>
<option value="8">Delaware</option>
<option value="9">District of Columbia</option>
<option value="10">Florida</option>
<option value="11">Georgia</option>
<option value="12">Hawaii</option>
<option value="13">Idaho</option>
<option value="14">Illinois</option>
<option value="15">Indiana</option>
<option value="16">Iowa</option>
<option value="17">Kansas</option>
<option value="18">Kentucky</option>
<option value="19">Louisana</option>
<option value="20">Maine</option>
<option value="21">Maryland</option>
<option value="22">Massachusetts</option>
<option value="23">Michigan</option>
<option value="24">Minnesota</option>
<option value="25">Mississippi</option>
<option value="26">Missouri</option>
<option value="27">Montana</option>
<option value="28">Nebraska</option>
<option value="29">Nevada</option>
<option value="30">New Hampshire</option>
<option value="31">New Jersey</option>
<option value="32">New Mexico</option>
<option value="33">New York</option>
<option value="34">North Carolina</option>
<option value="35">North Dakota</option>
<option value="36">Ohio</option>
<option value="37">Oklahoma</option>
<option value="38">Oregon</option>
<option value="39">Pennsylvania</option>
<option value="40">Rhode Island</option>
<option value="41">South Carolina</option>
<option value="42">South Dakota</option>
<option value="43">Tennessee</option>
<option value="44">Texas</option>
<option value="45">Utah</option>
<option value="46">Vermont</option>
<option value="47">Virginia</option>
<option value="48">Washington</option>
<option value="49">West Virginia</option>
<option value="50">Wisconsin</option>
<option value="51">Wyoming</option>
</select>
</tr> </p>
<input type="submit" value="Add Record">
</tr></td>
</form>
</table>
</body>
</html>
Here is insert.php
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "crm";
//making an array with the data received, to use as named placeholders for INSERT by PDO.
$data = array('ContactName' => $_POST['ContactName'] , 'ContactTypeId'
=> $_POST['ContactTypeId'],
'ContactId'=> $_POST['ContactId'],'AddressTypeId'=>
$_POST['AddressTypeId'],'Address1'=>$_POST['Address1'],
'Address2'=>$_POST['
Address2'],'City'=>$_POST['City'],'StateId'=>$_POST['StateId']);
try {
// preparing database handle $dbh
$dbh = new PDO("mysql:host=$servername;dbname=$dbname",
$username,$password);
// set the PDO error mode to exception
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$currentID = mysql_inserted_id();
// query with named placeholders to avoid sql injections
$query = "INSERT INTO Contacts (ContactName, ContactTypeId)
VALUES(:ContactName, :ContactTypeId )";
$query2= "INSERT INTO
Addresses(ContactId,AddressTypeId,Address1,Address2,City,StateId)
VALUES(:$currentID,:AddressTypeId,:Address1,:Address2,:City,:StateId)";
//statement handle $sth
$sth = $dbh->prepare($query);
$sth->execute($data);
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$dbh = null;
?>
You need to create two arrays $data for $query & $data1 for $query1 and need use $dbh->lastInsertId() for last id. Use the below code. I think it will work:
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "crm";
//making an array with the data received, to use as named placeholders for INSERT by PDO.
$data = array('ContactName' => $_POST['ContactName'] , 'ContactTypeId'
=> $_POST['ContactTypeId']);
$data1=array('AddressTypeId'=>$_POST['AddressTypeId'],'Address1'=>$_POST['Address1'],
'Address2'=>$_POST['
Address2'],'City'=>$_POST['City'],'StateId'=>$_POST['StateId']);
try {
// preparing database handle $dbh
$dbh = new PDO("mysql:host=$servername;dbname=$dbname",
$username,$password);
// set the PDO error mode to exception
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// query with named placeholders to avoid sql injections
$query = "INSERT INTO Contacts (ContactName, ContactTypeId)
VALUES(:ContactName, :ContactTypeId )";
$sth = $dbh->prepare($query);
$sth->execute($data);
$currentID = $dbh->lastInsertId();
$query2= "INSERT INTO
Addresses(ContactId,AddressTypeId,Address1,Address2,City,StateId)
VALUES($currentID,:AddressTypeId,:Address1,:Address2,:City,:StateId)";
$sth = $dbh->prepare($query2);
$sth->execute($data1);
//statement handle $sth
echo "New record created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$dbh = null;
?>
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();
}
?>