Welcome to Forum Support Mark forums read | View Forum Leaders
Forum Support
This is an ad revenue sharing forum



Reply
LinkBack Thread Tools Display Modes
What's wrong with my PHP code?
 
 
Junior Member

Reply With Quote
Bleah is on a distinguished road
 
Join Date: Dec 2008
Posts: 1
12-30-2008, 01:50 PM
 
The error is: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 44

Line 44 is
$result = mysql_query("SELECT * FROM login WHERE username= $_POST['username']");<?php

$con = mysql_connect("server","database","password");
if (!$con)
{
die("Could not connect: " . mysql_error());
}

$username = $_POST['username'];
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];

$result = mysql_query("SELECT * FROM login WHERE username= $_POST['username']");

$numfound = mysql_num_rows($result);
if ($_POST['password'] != $_POST['confirmpassword'])
{
mysql_close($con);
echo "The passwords did not match";
}
else {
mysql_select_db("login", $con);
mysql_query("INSERT INTO login (username, password)
VALUES ('$username', '$password')");
echo "Thank you " . $username . ". Your account has been created.";
}
if ($numfound != 0)
{
mysql_close($con);
echo "This username is already taken.";
}
else {
mysql_select_db("login", $con);
mysql_query("INSERT INTO login (username, password)
VALUES ('$username', '$password')");
echo "Thank you " . $username . ". Your account has been created.";
}


mysql_close($con);



?>
 
 
 
 
Junior Member

Reply With Quote
ZackT is on a distinguished road
 
Join Date: Dec 2008
Posts: 1
12-30-2008, 05:16 PM
 
Your code:
$result = mysql_query("SELECT * FROM login WHERE username= $_POST['username']");

Try:
$result = mysql_query("SELECT * FROM login WHERE username= '$_POST[username]'");

Untested, but it should work.
 
 
 
 
Junior Member

Reply With Quote
justJR6121 is on a distinguished road
 
Join Date: Dec 2008
Posts: 1
12-30-2008, 08:42 PM
 
Your syntax is incorrect (does not follow mySQL recommendations)

$username = $_POST [ ' username ' ] ;
$sql = " select * from ` login ` where ` username ` = '" . $username . "'" ;
$result = mysql_query ( $sql ) ;


1. Pay attention to different: ` (reverse), ' (single quote) and " (double quote).
2. Spaces added for clarity.
3. mySQL recommends using lower cases only for keywords (unix)

Same here:
$sql2 = "insert into `login` (`username`,`password`)
values ( '" . $username . "' , '" . $password . "' ) " ;
mysql_query ($sql2);
I know, it is a lot of ` '", but it is guaranteed to work on ALL versions of mysql.
 
 
 
Reply

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 07:30 AM.
Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Advertisement System V2.6 By   Branden