Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to complete an SQL insert query using php. The error I am returned with is: SCREAM: Error suppression ignored for Parse error: syntax error, unexpected T_STRING in C:\wamp\www\sign\db.php on line 28

I am using wamp and I have tested the query directly in php myadmin and it works fine. I don't know what the problem is.

Thanks in advance.

<?php
    //variables for db
    $username = "root";
    $password = "";
    $hostname = "127.0.0.1"; 
    $dbname = "site";
    //connection to the database
    $con = mysql_connect($hostname, $username, $password);

    if($con == FALSE)
    {
        echo 'Cannot connect to database' . mysql_error();
    }

    mysql_select_db($dbname, $con);

    mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) VALUES ("test","test", "test", "test");";

    ?>
share|improve this question
add comment

3 Answers

use single quotes instead.

mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) VALUES ('test','test', 'test', 'test');";
share|improve this answer
add comment

You need to backslash the quotes, here, else you close the statement

mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) VALUES (\"test\",\"test\", \"test\", \"test\");";

Alternatively you can replace them for single quotes

share|improve this answer
add comment

You need to fix your quotes:

// use single quotes
mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) 
             VALUES ('test','test', 'test', 'test');";

// Or...
// escape your double quotes
mysql_query("INSERT INTO users (full_name, first_name, dob, star_sign) 
             VALUES (\"test\",\"test\", \"test\", \"test\");";

What is happening (especially if you pay attention to syntax highlighting of the code in your question), is that simply using double quotes will end the string.

To fix this, you can use single quotes, or escape the double quotes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.