Jump to content

Recommended Posts

Is there something wrong this? If so, I'm not seeing it...I keep getting this error:

( ! ) Parse error: syntax error, unexpected T_STRING in C:\Program Files\wamp\www\register.php on line 1059

 

Here's my code for registering a member:

 

<?php
mysql_query (INSERT INTO fans (id, username, email, password, country, region, gender, status, account, subscription, time_registered, date_registered, birthdate, name, website, age, activation_key) VALUES ('', '{$_SESSION["user"]["username"]}', '{$_SESSION["user"]["email"]}', '{$_SESSION["user"]["password"]}', '{$_SESSION["user"]["country"]}', '{$_SESSION["user"]["region"]}', '{$_SESSION["user"]["gender"]}', 'Offline', 'Inactive', 'Unsubscribed', '{$_SESSION["user"]["time"]}', '{$_SESSION["user"]["date"]}', '{$_SESSION["user"]["birthdate"]}', '{$_SESSION["user"]["name"]}', '{$_SESSION["user"]["website"]}', '{$_SESSION["user"]["age"]}', '{$_SESSION["user"]["activation_key"]}')) or die ("Could not register member");
?>

 

Help, please and thank you!

Link to comment
https://forums.phpfreaks.com/topic/231792-mysql_query-error/
Share on other sites

Just looking over the query I see id and for the value it's '' If the row ID in your table is auto increment you don't need to worry about placing it in your query it will get a value automatically.

 

It's also yelling at you for your $_SESSION["thisvalue"] for your values.

 

I believe they should look like this:

 

'.$_SESSION['thisvalue'].'

 

EDIT:

 

Forgot to mention, why are you using session variables to place the intial registration into the database? You should be using a html form, escaping the inputs, and then sending the cleaned up variables to the database for storage.

Link to comment
https://forums.phpfreaks.com/topic/231792-mysql_query-error/#findComment-1192596
Share on other sites

Just looking over the query I see id and for the value it's '' If the row ID in your table is auto increment you don't need to worry about placing it in your query it will get a value automatically.

 

It's also yelling at you for your $_SESSION["thisvalue"] for your values.

 

I believe they should look like this:

 

'.$_SESSION['thisvalue'].'

 

EDIT:

 

Forgot to mention, why are you using session variables to place the intial registration into the database? You should be using a html form, escaping the inputs, and then sending the cleaned up variables to the database for storage.

 

Thanks, for the tip, but I did do that. The input comes from an html form, and gets stored in the $_POST array, and then I format those post values using a variety of functions (Like mysql_real_escape_string for instance) and assign them to session variables so I can span the registration form over multiple pages. I also like to allow the user to review their information before submitting, so that's another reason. And once they hit the submit button, the information gets inserted into the database, and I just dump my $_SESSION array, so as to "unclutter" what's going on, essentially.

Link to comment
https://forums.phpfreaks.com/topic/231792-mysql_query-error/#findComment-1192599
Share on other sites

I just tried what you suggested and cut the code down to just insert one value into one field in the table, and I got the same error.

 

Here's the revised code:

<?php

	mysql_query (INSERT INTO fans (username) VALUES ('.$_SESSION["user"]["username"].'));

?>

 

I tried put single quotes in the ["user"]["username"] part of the $_SESSION variable, but I get that error message either way.

 

What in the heck is going on? I've done queries like this in the past before, so I'm like...really confused...

 

Link to comment
https://forums.phpfreaks.com/topic/231792-mysql_query-error/#findComment-1192603
Share on other sites

The query string isn't quoted. It needs to be.

 

Okay, well I just rewrote the code like this:

	
<?php

$querry = "INSERT INTO fans (username) VALUES ('hello')";

mysql_query ($querry);

?>

 

And this inserts "hello" in the field "username". So, I'm guessing the problem lies in all those session variables. I've tried nearly ever variation I can think of, but it just doesn't work. Do you know how to send those session variables to the query the CORRECT way?

Link to comment
https://forums.phpfreaks.com/topic/231792-mysql_query-error/#findComment-1192606
Share on other sites

Have you print_r()'d the $_SESSION array to see if it actually contains the values you think it does?

 

Yep, I print_r'ed both the $_POST and $_SESSION arrays and everything looks okay.

 

I figured out how to do it properly (after a LOT of messing around)...

<?php

$query = "INSERT INTO fans (name, username, email, password, country, region, gender, status, account, subscription, time_registered, date_registered, birthdate, website, age, activation_key) VALUES ('{$_SESSION['user']['name']}', '{$_SESSION['user']['username']}', '{$_SESSION['user']['email']}', '{$_SESSION['user']['password']}', '{$_SESSION['user']['country']}', '{$_SESSION['user']['region']}', '{$_SESSION['user']['gender']}', 'Offline', 'Inactive', 'Unsubscribed', '{$_SESSION['user']['time']}', '{$_SESSION['user']['date']}', '{$_SESSION['user']['birthdate']}', '{$_SESSION['user']['website']}', '{$_SESSION['user']['age']}', '{$_SESSION['user']['activation_key']}')";

?>

 

This works perfectly. Thanks for all the help and suggestions guys!

Link to comment
https://forums.phpfreaks.com/topic/231792-mysql_query-error/#findComment-1192659
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.