|
-
Aug 7th, 2004, 12:27 PM
#1
Thread Starter
Banned
Inserting into db
Hi,
I'm trying to insert these values into my mysql database, but my browser throws in an error message at this line:
PHP Code:
$query = "INSERT INTO staf_temp VALUES (', $_POST['achternaam'], $_POST['voornaam'],$_POST['tussenvoegsel'],$_POST['adres'],$_POST['postcode'], $_POST['woonplaats'],$_POST['telefoon'],, $_POST['email'],,$_POST['gebdat1'] . $_POST['gebdat2']. $_POST['gebdat3'],$_POST['voornaam'], Date('d m Y'), '3', $_POST['wachtwoord1']');
The error is:
Code:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in blahblah/aanmelding.php on line 66
-
Aug 7th, 2004, 12:28 PM
#2
Thread Starter
Banned
The first value is the ID, so I left that one blank. (hence only the ',' )
-
Aug 7th, 2004, 05:50 PM
#3
You had a lot of errors in that line. If you want to include a variable array in a string you need to enclose it in curly brackets. I.e.:
PHP Code:
$string = "{$_POST['var']}"
If you dont do this then it will just print the varaible name as it is in the string.
Have you checked your POST variables? Making sure all integers are integers and all strings have SQL meta characters escaped? - if not I suggest you do, otherwise your scriptwill be open to SQL injections.
Also when you are writing an SQL query for MySql, enclose all all values in single quotes, even dates and numbers (mysql will convert them as necessary) and if you are omiting a field it is a good idea to put NULL in its place to show its being omitted. Although it makes your query bigger it is also a good idea to explicitly state only the fields you are going to insert. This that if you add or remove a column from your table , you won't need to change the query.
I have corrected the line for you and it should work:
PHP Code:
$query = "INSERT INTO staf_temp VALUES (NULL, '{$_POST['achternaam']}', '{$_POST['voornaam']}', " .
"'{$_POST['tussenvoegsel']}', '{$_POST['adres']}', '{$_POST['postcode']}', " .
"'{$_POST['woonplaats']}','{$_POST['telefoon']}', NULL, '{$_POST['email']}', NULL, " .
"'{$_POST['gebdat1']}{$_POST['gebdat2']}{$_POST['gebdat3']}', '{$_POST['voornaam']}', '" .
Date('d m Y') . "', '3', '{$_POST['wachtwoord1']}')";
-
Aug 7th, 2004, 05:54 PM
#4
<?="Moderator"?>
you forgot to close the string.
try this
PHP Code:
$query = "INSERT INTO staf_temp VALUES (', $_POST['achternaam'], $_POST['voornaam'],$_POST['tussenvoegsel'],$_POST['adres'],$_POST['postcode'], $_POST['woonplaats'],$_POST['telefoon'],, $_POST['email'],,$_POST['gebdat1'] . $_POST['gebdat2']. $_POST['gebdat3'],$_POST['voornaam'], Date('d m Y'), '3', $_POST['wachtwoord1']')";
also try using this syntax for your SQL statement
Code:
INSERT INTO table (name1, name2) VALUES ("value1", "value2")
It means you only need to supply information for data you want to insert and not make mistakes with column name order (if that made sense )
-
Aug 8th, 2004, 03:56 PM
#5
Stuck in the 80s
Michael, just curious -- what text editor do you use? Does it have syntax-coloring?
-
Aug 8th, 2004, 04:19 PM
#6
Thread Starter
Banned
I used notepad. Just switched to Crimson Editor.
-
Aug 8th, 2004, 05:04 PM
#7
Stuck in the 80s
I used to use Notepad, and then I switched to EditPlus. One thing I noticed is that the syntax highlighting really helps catch errors like this. Like in the code above, since the semicolon is red like the text, you know something's up.
-
Aug 8th, 2004, 05:06 PM
#8
Stuck in the 80s
Originally posted by Michael_Kamen
The first value is the ID, so I left that one blank. (hence only the ',' )
Also, in your code you have this:
That's going to generate an error on the MySQL end. You want:
Two of them.
-
Aug 9th, 2004, 01:26 PM
#9
Frenzied Member
Macromedia's Homesite 5.5 has excellent code coloring. It's a little expensive, but well worth it, especially if your company can buy it for you.
-
Aug 9th, 2004, 01:28 PM
#10
gVIM - Open source and supports syntax highlighting for every language under the sun.
-
Aug 9th, 2004, 02:19 PM
#11
Stuck in the 80s
I'd recommend EditPlus. It's not free, but it doesn't force you to purchase it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|