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');
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
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.
Improve this question
I am trying to execute the following query:
INSERT INTO table_timesheet (name, datein, dateout)
VALUES ('Rupert', 'NOW()', '')
WHERE NOT EXISTS (
SELECT name FROM table_listnames WHERE datein='NOW()'
);
But this returns an error.
Basically I don't want to insert a record if the 'datein' field of the record already exists in another record - how to check if the new datein is unique?
And how can i insert in the same way the date out on the same row something like an update the datein row?
This INSERT query will do exactly what you want:
INSERT INTO table_timesheet (name, datein, dateout)
SELECT 'Rupert', NOW(), null
FROM DUAL
WHERE NOT EXISTS (
SELECT * FROM table_listnames WHERE datein=NOW()
);
Please see it here. But a proper solution would be to set a table constraint. How are table_timesheet and table_listnames related? I would use a unique constraint on the datein column, but this depends on what are your requirements.
first check this query (using MYSQLI or PDO ) if this query return false than you insert record
IF... this return false
SELECT name FROM table_listnames WHERE datein='NOW()'
FALSE
INSERT INTO table_timesheet (name, datein, dateout)VALUES ('Rupert', 'NOW()', '')
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
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.
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.
Improve this question
evening all, i have an issue with a syntax sql error
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where username = danny (name, url, banner, description, sponsor, date, password)' at line 1
Here is my code
$query = "UPDATE websites where username = $login_session (name, url, banner, description, sponsor, date, password) VALUES ('$n', '$b', '$d', '0', now(), SHA('$p'))";
Your MySQL query is wrong, as the error says, check the manual.
In UPDATE you don't use table(field,field1) values('value','value1') like in INSERT, you use field='value', field1='value1' also, WHERE should be at the end, the right order is query + where + order + limit. MySQL is not that flexible.
That's because your UPDATE statement syntax is wrong. Check MySQL documentation for proper UPDATE syntax. I think you meant to do a INSERT rather
INSERT INTO websites (name, url, banner, description, sponsor, date, password)
VALUES ('$login_session', '$n', '$b', '$d', '0', now(), SHA('$p'))
EDIT:
I think this is what you are after
UPDATE websites SET name = '$n',
url = '$b',
banner = '$d',
description = '0',
sponsor = 'some_value_here',
date = now(),
password = SHA('$p')
where username = '$login_session';
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 8 years ago.
Improve this question
I have been trying to insert data from form in two tables but I didn't get lucky, and the last I have tried got the first table inserted but the second table is empty and nothing inserted to it, below is my query code:
$query1=mysql_query("INSERT INTO $Tname (tnumber2, results, idate, iaddress, tstatus, saddress, scountry, ddate, daddress) VALUES('$tnumber2','$results','$idate','$iaddress','$tstatus','$saddress','$scountry','$ddate','$daddress')");
$id = mysql_insert_id();
$query2=mysql_query("INSERT INTO $UPname (tnumber2, pdate, act, paddress, up) VALUES('$tnumber2','$pdate','$act','$paddress','$up')");
I am getting this 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 'update (tnumber2, pdate, act, paddress, up) VALUES('59644039299744','59644039299' at line 1
From 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 'update (...
it looks like your table is called update
That's a reserved word in SQL, so it's generating an error.
If possible, you should rename the table, as using reserved words as table or column names is confusing; but if that's not feasible, you can escape the name with backticks; try this as your second SQL call:
INSERT INTO `$UPname` (tnumber2, pdate, act, paddress, up) VALUES('$tnumber2','$pdate','$act','$paddress','$up')");
I'll also add the compulsory warning that mysql_ functions are deprecated, and you should switch to mysqli_ or PDO - they both help you write safer code. Also, if you're going to be using variables for table names, you need to be make sure that you're validating them very, very well.
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
I'm trying to insert data into a MySQL table using PHP, but getting the error
Column count doesn't match value count at row 1
mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}' '{$filepass}') ") or die(mysql_error());
mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}' '{$filepass}') ") or die(mysql_error());
You should add the missing comma after {$filesize}:
mysql_query("INSERT INTO file (id, filename, extention, filelink, filesize, filepass) VALUES('{$random}', '{$filename}', '{$extension}', '{$filelink}', '{$filesize}', '{$filepass}') ") or die(mysql_error());
'{$filesize}' '{$filepass}' is being considered as a single value since you're missing the comma. Your query would look like:
INSERT INTO file (id, filename, extention, filelink, filesize, filepass)
VALUES ( '{$random}',
'{$filename}',
'{$extension}',
'{$filelink}',
'{$filesize}' '{$filepass}')
There. You have 6 columns and 5 values. The column count doesn't match the value count and hence MySQL throws an error message.
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 9 years ago.
Improve this question
I have problem with query, anybody see something bad?
INSERT INTO messages (subject, from, recipient, text, time)
VALUES
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')
Error from sql:
#1064 - 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 'from, recipient, text, time) VALUES ('Welcome in King of the States!','The Gam' at line 1
from is a mysql reserved word. try placing from in backtick
Like below:
`from`
try to do:
INSERT INTO messages (`subject`, `from`, `recipient`, `text`, `time`)
VALUES
('Welcome in King of the States!','The Game','$username','Hello $username, THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')
From is the reserve keyword in the mysql so use the below query:
INSERT INTO `messages` (`subject`, `from`, `recipient`, `text`, `time`)
VALUES
('Welcome in King of the States!',
'The Game','$username',
'Hello $username,
THIS MESSAGE IS DISPLAYED IN ENGLISH AUTOMATICLY SORRY FOR THAT! this game is in baby stadium so if you will see any bugs, please report them to our help desc system','$time')
"INSERT INTO messages SET subject='Welcome in King of the States!',from='The Game',recipient='".$username."',text='Hello.$username', time=''";
Instruction:
from is a keyword in mysql. So you can not use directly in query like this.
You need to parse it every time and for that use backtick
use it like from