Mysql Insert Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn mysql error php more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags
Php Mysqli Error
Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you,
Mysql Query Error
helping each other. Join them; it only takes a minute: Sign up MySQL Insert error up vote 2 down vote favorite Ok, when trying to insert into the database I'm getting this error "You have an error in
Or Die Mysql Error
your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@email.com, UT, 84505, NOW(), 69.169.186.192)' at line 1" I can't figure out the problem. Here is the code for my insert statement. $insert_query = sprintf("INSERT INTO contacts (first_name, last_name, email, state, zip, date, ip) VALUES (%s, %s, %s, %s, %s, NOW(), %s)", $fname, $lname, $email, $state, $zip, $ip); $result = mysql_query($insert_query, $connection) or die(mysql_error()); My table has php mysql error handling the following structure: id int(11) first_name varchar(100) last_name varchar(100) email varchar(100) state varchar(3) zip int(10) date datetime ip varchar(255) php mysql mysql-error-1064 share|improve this question edited Mar 30 '11 at 6:04 ta-run 4,01912046 asked Mar 30 '11 at 5:55 Mitchell 1313 add a comment| 3 Answers 3 active oldest votes up vote 2 down vote accepted You need to quote all the string-type columns in the insert statement. Replace %s with '%s' in the sprintf format. Please read about SQL Injection if you haven't done so already. share|improve this answer answered Mar 30 '11 at 5:58 Mat 136k21235274 Beautiful. That did the trick. Earlier in my code I'm using mysql_real_escape_string() on each of the variables. Is this not the correct way to do it? –Mitchell Mar 30 '11 at 6:03 You need to do both. –Mat Mar 30 '11 at 6:04 1 Ok. Thank you very much for your help. I'm new to this whole programming thing. I'll read up more on SQL injection so I don't make this mistake again and keep my sites safe! I appreciate the quick responses from everyone. –Mitchell Mar 30 '11 at 6:07 add a comment| up vote 0 down vote This may help you.. $insert_query = "INSERT INTO contacts set first_name = '$fname', last_name = '$lname', email = '$email', state = '$state', zip =
and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations mysql_query error Installed as CGI binary Installed as an Apache module Session Security Filesystem mysqli_query error Security Database Security Error Reporting Using Register Globals User Submitted Data Magic Quotes Hiding PHP Keeping Current die(mysql_error()) Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Safe Mode Command line usage Garbage Collection DTrace http://stackoverflow.com/questions/5482427/mysql-insert-error Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Credit Card Processing Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions http://php.net/manual/en/function.mysql-error.php Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box mysql_escape_string » « mysql_errno PHP Manual Function Reference Database Extensions Vendor Specific Database Extensions MySQL MySQL (Original) MySQL Functions Change language: English Brazilian Portuguese Chinese (Simplified) French German Japanese Korean Romanian Russian Spanish Turkish Other Edit Report a Bug mysql_error (PHP 4, PHP 5)mysql_error — Returns the text of the error message from previous MySQL operation Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: mysqli_error() PDO::err
Connectors More MySQL.com Downloads Developer Zone Section Menu: Documentation Home MySQL 5.7 Reference Manual Preface and Legal Notices General Information Installing and Upgrading MySQL Using MySQL as a http://dev.mysql.com/doc/en/insert-on-duplicate.html Document Store Tutorial MySQL Programs MySQL Server Administration Security Backup and Recovery http://dev.mysql.com/doc/en/insert.html Optimization Language Structure Globalization Data Types Functions and Operators SQL Statement Syntax Data Definition Statements ALTER DATABASE Syntax ALTER EVENT Syntax ALTER FUNCTION Syntax ALTER INSTANCE Syntax ALTER LOGFILE GROUP Syntax ALTER PROCEDURE Syntax ALTER SERVER Syntax ALTER TABLE Syntax ALTER TABLE Partition Operations ALTER TABLE Online mysql error Operations in MySQL Cluster ALTER TABLE and Generated Columns ALTER TABLE Examples ALTER TABLESPACE Syntax ALTER VIEW Syntax CREATE DATABASE Syntax CREATE EVENT Syntax CREATE FUNCTION Syntax CREATE INDEX Syntax CREATE LOGFILE GROUP Syntax CREATE PROCEDURE and CREATE FUNCTION Syntax CREATE SERVER Syntax CREATE TABLE Syntax CREATE TABLE ... LIKE Syntax CREATE TABLE ... SELECT Syntax Using FOREIGN KEY mysql insert error Constraints Silent Column Specification Changes CREATE TABLE and Generated Columns Secondary Indexes and Generated Virtual Columns Setting NDB_TABLE options in table comments CREATE TABLESPACE Syntax CREATE TRIGGER Syntax CREATE VIEW Syntax DROP DATABASE Syntax DROP EVENT Syntax DROP FUNCTION Syntax DROP INDEX Syntax DROP LOGFILE GROUP Syntax DROP PROCEDURE and DROP FUNCTION Syntax DROP SERVER Syntax DROP TABLE Syntax DROP TABLESPACE Syntax DROP TRIGGER Syntax DROP VIEW Syntax RENAME TABLE Syntax TRUNCATE TABLE Syntax Data Manipulation Statements CALL Syntax DELETE Syntax DO Syntax HANDLER Syntax INSERT Syntax INSERT ... SELECT Syntax INSERT DELAYED Syntax INSERT ... ON DUPLICATE KEY UPDATE Syntax LOAD DATA INFILE Syntax LOAD XML Syntax REPLACE Syntax SELECT Syntax SELECT ... INTO Syntax JOIN Syntax UNION Syntax Subquery Syntax The Subquery as Scalar Operand Comparisons Using Subqueries Subqueries with ANY, IN, or SOME Subqueries with ALL Row Subqueries Subqueries with EXISTS or NOT EXISTS Correlated Subqueries Subqueries in the FROM Clause Subquery Errors Optimizing Subqueries Rewriting Subqueries as Joins UPDATE Syntax Transactional and Locking Statements START TRANSACTION, COMMIT, and ROLLBACK Syntax
Connectors More MySQL.com Downloads Developer Zone Section Menu: Documentation Home MySQL 5.7 Reference Manual Preface and Legal Notices General Information Installing and Upgrading MySQL Using MySQL as a Document Store Tutorial MySQL Programs MySQL Server Administration Security Backup and Recovery Optimization Language Structure Globalization Data Types Functions and Operators SQL Statement Syntax Data Definition Statements ALTER DATABASE Syntax ALTER EVENT Syntax ALTER FUNCTION Syntax ALTER INSTANCE Syntax ALTER LOGFILE GROUP Syntax ALTER PROCEDURE Syntax ALTER SERVER Syntax ALTER TABLE Syntax ALTER TABLE Partition Operations ALTER TABLE Online Operations in MySQL Cluster ALTER TABLE and Generated Columns ALTER TABLE Examples ALTER TABLESPACE Syntax ALTER VIEW Syntax CREATE DATABASE Syntax CREATE EVENT Syntax CREATE FUNCTION Syntax CREATE INDEX Syntax CREATE LOGFILE GROUP Syntax CREATE PROCEDURE and CREATE FUNCTION Syntax CREATE SERVER Syntax CREATE TABLE Syntax CREATE TABLE ... LIKE Syntax CREATE TABLE ... SELECT Syntax Using FOREIGN KEY Constraints Silent Column Specification Changes CREATE TABLE and Generated Columns Secondary Indexes and Generated Virtual Columns Setting NDB_TABLE options in table comments CREATE TABLESPACE Syntax CREATE TRIGGER Syntax CREATE VIEW Syntax DROP DATABASE Syntax DROP EVENT Syntax DROP FUNCTION Syntax DROP INDEX Syntax DROP LOGFILE GROUP Syntax DROP PROCEDURE and DROP FUNCTION Syntax DROP SERVER Syntax DROP TABLE Syntax DROP TABLESPACE Syntax DROP TRIGGER Syntax DROP VIEW Syntax RENAME TABLE Syntax TRUNCATE TABLE Syntax Data Manipulation Statements CALL Syntax DELETE Syntax DO Syntax HANDLER Syntax INSERT Syntax INSERT ... SELECT Syntax INSERT DELAYED Syntax INSERT ... ON DUPLICATE KEY UPDATE Syntax LOAD DATA INFILE Syntax LOAD XML Syntax REPLACE Syntax SELECT Syntax SELECT ... INTO Syntax JOIN Syntax UNION Syntax Subquery Syntax The Subquery as Scalar Operand Comparison