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 6 years ago.
Improve this question
I have a mysql query and I keep on getting a syntax error. I ran it through different debugging tools and haven't found anything. Is tehre anything i'm missing.
My Query
INSERT INTO futureposts
(
ID,
username,
postedby,
link,
message,
picture,
name,
caption,
description,
groups,
type
)
VALUES
('','1','CodeCompiler','CodeCompiler,'','','','','','','default','daily')
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 'default','daily')' at line 1
You missed ' code after CodeCompiler so change your query from
INSERT INTO futureposts (ID, username, postedby, link, message, picture, name, caption, description, groups, type) VALUES ('','1','CodeCompiler','CodeCompiler,'','','','','','','default','daily')
to
INSERT INTO futureposts (ID, username, postedby, link, message, picture, name, caption, description, groups, type) VALUES ('','1','CodeCompiler','CodeCompiler','','','','','','default','daily')
and also there is one extra column added in query , check it and remove extra column
You missed ' (closing quote) after CodeCompiler
....VALUES ('','1','CodeCompiler','CodeCompiler,'','....
Also one change that you need to do that is you are giving 12 values to 11 column..I have checked personally in my phpmyadmin by creating same table.
So your final query will be
INSERT INTO futureposts (ID, username, postedby, link, message, picture, name, caption, description, groups, type) VALUES ('','1','CodeCompiler','','','','','','','default','daily');
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I've been trying to insert a tuple into my relation, but it doesn't seem to work.
<?php
$link=mysql_connect ("connection", "name", "pw");
mysql_select_db('pizzaria');
$sql = "INSERT INTO pizza_bakery (Name, Address, Telenum)
VALUES ('Test', 'Test', '111')";
?>
The connection seems to go through ok, as I'm able to print the table out easily on my html page, why is this failing?
Your insert statement should look something like this:
$sql = "INSERT INTO pizza_bakery (Name, Address, Telenum)
VALUES ('Test', 'Test', 111)";
Reason: The last column (Telenum) is an integer datatype and the insert statement was treating it like a string.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
No matter what I do I get a syntax error and I cannot figure out why?
$sn= "INSERT INTO [Drive Errors](Serial Number) SELECT [Serial Number] FROM [Drive List] ORDER BY [Position]ASC";
odbc_exec($con,$sn);
Thanks, the code works but now all the previous data is being deleted when I insert the the serial number data. Any suggestions?
$sn= "INSERT INTO [Drive Errors]([Serial]) SELECT [Serial Number] FROM [Drive List] ORDER BY [Position]ASC";
odbc_exec($con,$sn);
//Selecting table(de) and row(pos) need it in brackets
$sql= "SELECT * FROM [Drive Errors] ORDER BY [Position]ASC";
$rs=odbc_exec($con,$sql);
if (!$rs)
{echo("Error");}
You need square brackets around the first Serial Number, too:
$sn= "INSERT INTO [Drive Errors]([Serial Number]) SELECT [Serial Number] FROM [Drive List] ORDER BY [Position]ASC";
The round brackets are part of the INSERT statement syntax; the square brackets are what delimits column names with spaces or funny characters, or are reserved words in Access SQL.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
I am using this query to insert values, but it is not working.
$sql="INSERT INTO $tbl_name (type, weight, side, size, quantity)
VALUES ($stock_type, $weight, $side,$size,$quantity)";
In Database table 'value type' is varchar for all values
I don't know the column types but you need to quote values for string type fields:
$sql='INSERT INTO $tbl_name (type, weight, side, size, quantity)
VALUES ("$stock_type", "$weight", "$side", "$size" , "$quantity")';
If any of those columns are char, varchar or date you need to quote them.
$sql="INSERT INTO $tbl_name ( type, weight, side, size, quantity)
VALUES ('$stock_type', $weight, '$side', $size, $quantity)";
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
How can I post only one word into the database.
I only need to insert one word from the values entered by a user.
For example: this is my car to insert only the word this
Here is my present code:
$write=mysql_query("INSERT INTO `staff_description` (`id`, `staff_name`, `description`, `description2`,`writer`, `date_stamp`) VALUES ('$id', '$staff_name', '$description', '$description2', '$user', '$date_stamp');") or die(mysql_error());
please assist
If you are looking to take only 1 word from user inputs and insert it into your database you could use explode() function as follows:
$description1 = $_POST['description1'];
$arr = explode(' ',$description1 ); // this will explode the string after every space
echo $arr[0]; //this is the first word
echo $arr[1];
echo $arr[2];
you could use this to insert into database like :
insert into database VALUES($arr[0])
// this will take the first word from the user input
If your table has only 1 column then you can simply use the INSERT query. If your table has multiple rows there can be 2 cases:
The row already exits - In this case you will have to use the UPDATE query.
The row doesn't exist - You may insert "1 word" into any column using the INSERT query. The other columsn will take default values which you have defined while creating the table OR you can simple add blanks if you plan to use those columns later.