Please anyone help.. I have the exact same error and I am trying to search google for past half an hour because If I just got this one line to be working then I would have finished some important feature in a project that I am working on:
The line in which i am getting the error is:
Code:
$query_string = "ALTER TABLE inventory ADD '" .$product_field . "' TINYINT NULL ";
$query = mysql_query($query_string);
The error:
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 ''anyword_or_any_phrase' TINYINT NULL' at line 1
Full code:
Code:
<form action = "newproduct.php" method = "POST">
<div><b>Enter the name of the product: </b><input type = "text" name = "product_name"></div>
<div>
<input type = "submit" name = "submit" value = " Add " ></div>
</form>
<?php
if(isset($_POST['submit']))
{
$product_name = $_POST['product_name'];
$product_field = mb_strtolower($product_name );
$product_field = preg_replace("/\s+/", "_", $product_field);
$query_string = "ALTER TABLE inventory ADD '" .$product_field . "' TINYINT NULL ";
$query = mysql_query($query_string);
if(!$query){
die(mysql_error());
}else
{
$query2 = mysql_query("INSERT INTO products (product_field, product_name)VALUES ('$product_field', '$product_name' ) ");
if(!$query) {die(mysql_error());}
else
{
echo " <p style = \" color:CC0033; font-weight:bold \"> Product has been added successfully</p>";
}
}
}
?>
Bookmarks