parse error, unexpected '='
I've gone over and over this and I can't figure out why it's giving me this error message. I'm kind of new to php/mySQL but I basically copied this code from another form that's working. Here is the offending line:
$q1-firstthing = $_POST['1-firstthing'];
'
Here is the form: http://www.housing.uwaterloo.ca/surveys/quick-quiz.php
Here is the full code block:
<?php
// include database info
include '../library/db_connect.php';
// set variables for for the form
$q1-firstthing = $_POST['1-firstthing'];
$q1-firstthing-other = $_POST['1-firstthing-other'];
$q2-laundry = $_POST['2-laundry'];
$q3-necessities = $_POST['3-necessities'];
$q4-gainweight = $_POST['4-gainweight'];
$q5-eatout = $_POST['5-eatout'];
$q5-eatout-other = $_POST['5-eatout-other'];
$query = "INSERT INTO quickquizW07 (1-firstthing, 1-firstthing-other, 2-laundry, 3-necessities, 4-gainweight,
5-eatout, 5-eatout-other)
VALUES ('$q1-firstthing', '$q1-firstthing', '$q1-firstthing-other', '$q2-laundry', '$q3-necessities',
'$q4-gainweight','$q5-eatout', '$q5-eatout-other')";
echo $query;
mysql_query($query) or die('Oops, something went wrong. Please go back and try again.');
echo "<p>Thanks for participating! Here are the results so far:</p>";
Are the hyphens in the variables going to be a problem too? I tried taking them out but it's still giving me the same error.
teammatt3 posted this at 00:22 — 29th March 2007.
He has: 2,102 posts
Joined: Sep 2003
I get the same type of error, but when I take all of the -s out and replace them with _s, I just get a db connection warning and an include warning. Did you take them out of your $_POSTs too?
From this post it seems like PHP thinks the - is an operator so you can't use it in var names.
Megan posted this at 13:16 — 29th March 2007.
She has: 11,421 posts
Joined: Jun 1999
Oh, I think I might have missed the -other hyphens before. But now it's just giving me an error message. Won't insert anything. Hmmmm... I really need to get this working by Monday!
Megan
Connect with us on Facebook!
pr0gr4mm3r posted this at 20:08 — 29th March 2007.
He has: 1,502 posts
Joined: Sep 2006
If you are having SQL errors, print the errors and I can help you out.
Looking at your code, my best guess is that MySQL doesn't like those hyphens in the table names. Try surrounding the column names with `.
Megan posted this at 20:43 — 29th March 2007.
She has: 11,421 posts
Joined: Jun 1999
Yes, that was the problem. Getting all the hyphens out and making sure everything matched. For awhile I was trying to put it in the wrong table too
Megan
Connect with us on Facebook!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.