1
$sql = mysql_query("INSERT INTO `users` VALUES(
        '',
        '$form['name']',
        '$form['saddress']',
        '$form['apt']',
        '$form['zip']',
        '$form['homephone']',
        '$form['cellphone']',
        '$form['email']',
        '$form['    ']',
        '$form['city']',
        '$form['state']',
        '$form['country']',
        '$salt','$hash',
        '$form['username']'
    )");

How would I make that work? It's giving me Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

6
  • 2
    don't forget the dots ... ' . $form['city'] . ' Commented Sep 23, 2011 at 1:44
  • Why are dots necessary? I've never used them before when inserting normal variables into a SQL query. Commented Sep 23, 2011 at 1:45
  • or {} '{$form['name']}', Commented Sep 23, 2011 at 1:45
  • you can use the dots of curly brace. I prefer the dots since it's easier to read. see Nexerus or rfausak answer and see what you prefer. Commented Sep 23, 2011 at 1:47
  • funny i prefer the {} for the same reason! Commented Sep 23, 2011 at 1:49

3 Answers 3

2

Try using curly brackets around the variables, like this:

..
'{$form['name']}',
'{$form['saddress']}',
..
Sign up to request clarification or add additional context in comments.

Comments

1

Either by removing the single quotes from the $form['x'] or by doing something like:

mysql_query("INSERT INTO x VALUES(
  '" . mysql_real_escape_string($form['x']) . "',
  '" . mysql_real_escape_string($form['x']) . "'
");

Notice that there are double quotes inside the single quotes.

Comments

0

This is a classic problem that stems from PHP's ability to parse strings for variables, which can get confusing. I prefer to keep my variables outside of the strings, and concatenate when needed.

Here's what I would do:

$sql = mysql_query("INSERT INTO `users` VALUES('" .
    implode("','", array(
        "",
        $form['name'],
        $form['saddress'],
        $form['apt'],
        $form['zip'],
        $form['homephone'],
        $form['cellphone'],
        $form['email'],
        $form['    '],
        $form['city'],
        $form['state'],
        $form['country'],
        $salt,
        $hash,
        $form['username']
    )) . "')";
);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.