Hey,

I've been messing around with SQL And PHP recently and I've come into another problem which has blown all logic out for me.

I have this form:

System Type <select name="systype">
<option value="systype1">type1</option>
<option value="systype2">type2</option>
<option value="systype3">type3</option>
<option value="systype4">type4</option>
<option value="none" selected="selected">None</option>
</select><br>

This form will send whatever is selected to the database. Or so I thought...

This is the main snippet of my PHP

// Note that whatever is enclosed by $_POST[""] matches the form input elements
// $Value_name = $_POST["Form_Name"]; 

$value_customer_name = $_POST["customer_name"];
$value_customer_name_letterhead = $_POST["customer_name_letterhead"];
$value_customer_notes = $_POST["customer_notes"];
$value_systype = $_POST["systype"];

    // Connect to our DB with mysql_connect(<server>, <username>, <password>)    
    $sql_connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)  or die(mysql_error());
    mysql_select_db(DB_NAME , $sql_connection) or die(mysql_error());

    $sql = "INSERT INTO Customers(
                customer_name,
                customer_name_letterhead,
                customer_notes
                systype
        ) VALUES (
            '$value_customer_name',
            '$value_customer_name_letterhead',
            '$value_customer_notes',
            '$value_systype'
        )";

However, when I put

Test, Test, Test in all of the customer sections and then leave systype as None.

I recieve this error:

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 'systype ) VALUES ( 'test', 'test', ' at line 5

Any hints?

check your line 16 and 17 in your sample:

customer_notes // missing comma
systype

You have a missing comma in your SQL Statement
Should be:

    $sql = "INSERT INTO Customers(
                customer_name,
                customer_name_letterhead,
                customer_notes,
                systype
        ) VALUES (
            '$value_customer_name',
            '$value_customer_name_letterhead',
            '$value_customer_notes',
            '$value_systype'
        )";

can you please mark this as solved.. I just landed on this page for the third time :).

Done and dusted :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.