Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-20-2011, 04:05 PM   PM User | #1
spiralzone
New to the CF scene

 
Join Date: Mar 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
spiralzone is an unknown quantity at this point
Question Damn you syntax error, need help please (:

Hi guys, i need some help here with my php code. Im trying to make a login and regestration site, havn't gotten very far though. I tried to fix the problem on my own, by reading alot about it, but still it gives me this error.
im getting a "Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\afsluttende projekt\test.php on line 5"

and heres my code:
PHP Code:
<?php

$username 
$_POST ['username']

$link mysql_connect ('localhost','root',''); //this is line 5
if (!$link) {
    die(
'Could not connect: ' mysql_error());
}
echo 
'Connected successfully';
mysql_close($link);

$db mysql_select_db ('phplogin');
if (!
$db) {
    die(
'Could not find database: ' mysql_error());
}

$query mysql_query ("SELECT * FROM phplogin WHERE username = {$_POST ['username']}"$link) or die (mysql_error());
mysql_query($query);

$num_row mysql_num_rows ($query);
echo (
$num_row);

?>
Im just trying to make it spit out a username and password for now, one step at the time right :p
ty in advanced

Last edited by spiralzone; 03-20-2011 at 04:08 PM..
spiralzone is offline   Reply With Quote
Old 03-20-2011, 04:27 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,645
Thanks: 4
Thanked 2,449 Times in 2,418 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
$username assignment is missing a semi-colon at the end.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
spiralzone (03-20-2011)
Old 03-20-2011, 04:31 PM   PM User | #3
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
You are missing a semi-colon at the end of this line $username = $_POST ['username'];
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Users who have thanked djm0219 for this post:
spiralzone (03-20-2011)
Old 03-20-2011, 05:57 PM   PM User | #4
spiralzone
New to the CF scene

 
Join Date: Mar 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
spiralzone is an unknown quantity at this point
oh my bad, must have missed that, ty
but now i get a "Notice: Undefined index: username in C:\wamp\www\afsluttende projekt\test.php on line 3"? can you help me with this also?(:
spiralzone is offline   Reply With Quote
Old 03-20-2011, 06:05 PM   PM User | #5
djm0219
Senior Coder

 
djm0219's Avatar
 
Join Date: Aug 2003
Location: Wake Forest, North Carolina
Posts: 1,227
Thanks: 2
Thanked 189 Times in 187 Posts
djm0219 is on a distinguished road
Any time you are going to use a form variable, either POST or GET, check to see if it is set before blindly retrieving or using it.

PHP Code:
$username '';
if (isset(
$_POST['username '])) {
   
$page mysql_escape_string($_POST['username ']);

What you default $username to, blank or something else, depends on whether or not the rest of your code depends on it and how it will behave if it is an empty string as I showed above.
__________________
Dave .... HostMonster for all of your hosting needs
djm0219 is offline   Reply With Quote
Old 03-20-2011, 06:09 PM   PM User | #6
spiralzone
New to the CF scene

 
Join Date: Mar 2011
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
spiralzone is an unknown quantity at this point
Thx alot, that fixed the problem! it had been buggin me for some time now, ty!
spiralzone is offline   Reply With Quote
Reply

Bookmarks

Tags
php, syntax, t_variable, username

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:55 AM.


Advertisement
Log in to turn off these ads.