Jump to content

What's wrong with my code?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
Hi guys,

Iv been making a website for a few days now, but have got to a point where im really stuck. I'm trying to create a file which will register a user. Im getting the error...

Quote

Parse error: syntax error, unexpected T_STRING in /home/a4941674/public_html/register.php on line 17

Here's my code (Im not posting it all for security reasons)

$sql=INSERT INTO  `'$db_name'`.`members` (`id` ,`username` ,`password` ,`email` ,`coins`)VALUES (NULL ,  '$username',  '$password',  '$email',  '0');

$result=mysql_query($sql);



can somebody tell me why i'm getting this error and how to fix it?

Thanks a bunch guys!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It looks like you aren't delimiting the string you are assigning to $sql.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
Does that mean I'v missed out the " before and after the Sql query? If I have, I'm sorry for my mistake!

Thanks.

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
You are not storing $sql as a string. Your code:
$sql=INSERT INTO  `'$db_name'`.`members` (`id` ,`username` ,`password` ,`email` ,`coins`)VALUES (NULL ,  '$username',  '$password',  '$email',  '0');
$result=mysql_query($sql);
And fixed -- the SQL contained within a string:
$sql = "INSERT INTO  `$db_name`.`members` (`id` ,`username` ,`password` ,`email` ,`coins`)VALUES (NULL ,  '$username',  '$password',  '$email',  '0')";
$result=mysql_query($sql);
You may use a syntax highlighter to write your code in, it can be handy to show you what are strings and not, so you can verify if you wrote it correctly. You can see by the first code how it appears wrong for example.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
I understand.

Thankyou very much for this reply, it's really helped me!

Kudos for you my friend(: