Forum Moderators: coopster
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/netmusic/public_html/login.php on line 25
this is the script:
$result = mysqli_query($cxn, $sql)
or die (Couldn't execute query. " ) ;
$num = mysqli_num_rows($result);
if ($num > 0) // login name was found
{
$sql = "SELECT loginName FROM Member
WHERE loginName='$_POST[fusername] ' " ;
AND password=md5('$_POST[fpassword]') " ; #line 25
[edited by: eelixduppy at 11:58 pm (utc) on Sep. 9, 2007]
[edit reason] removed excess code dump [/edit]
You might want to have a look at this forum's charter [webmasterworld.com] - it's better to post as little code as possible, isolating it to the parts that you think have trouble, so it's easier to look at - it's sort of a pain to hand-count down 25 lines.
Your problem is here - you need to remove the quote and semicolon at the end of the first line:
WHERE loginName='$_POST[fusername] ' " ;
AND password=md5('$_POST[fpassword]') " ;
Also, the correct syntax to use for referring to associative arrays inside quotes is to use braces { } and to surround the array indices with single quotes. So your first line would look like:
WHERE loginName='{$_POST['fusername']}'
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/netmusic/public_html/login.php on line 169
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/netmusic/public_html/login.php on line 169
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/netmusic/public_html/login.php on line 169
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/netmusic/public_html/login.php on line 169
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/netmusic/public_html/login.php on line 169
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/netmusic/public_html/login.php on line 169
Warning: mysql_real_escape_string() expects parameter 1 to be string, resource given in /home/netmusic/public_html/login.php on line 169
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/netmusic/public_html/login.php on line 178
Couldn't execute select query.
153 /* clean data */
$cxn = mysqli_connect($host,$user,$passwd,$dbname);
155
foreach($_POST as $field => $value)
157 {
if($field!= "Button" and $field!= "do")
159 {
if($field == "password")
{
$password = strip_tags(trim($value));
}
else
165 {
$fields[]=$field;
$value = strip_tags(trim($value));
$values[] =
169 mysqli_real_escape_string($cxn,$value);
$$field = $value;
}
}
}
175 /* check whether user name already exists */
$sql = "SELECT loginName FROM Member
WHERE loginName = '$loginName'";
$result = mysqli_query($cxn,$sql)
or die("Couldn't execute select query.");
$num = mysqli_num_rows($result);
if ($num > 0)
182 {
$message_new = "$loginName already used.
Select another User Name.";
include("login_form.inc");
exit();
}
/* Add new member to database */
else
you have your parameters mixed up if you were using mysql_real_escape_string
but I see in the code you posted you are using
169 mysqli_real_escape_string($cxn,$value);
which should be correct as the params are expected in that order
I am guessing the code you posted isn't what gave you an error, or you changed something and posted different code
"The Login Name, 'abcde' exists, but you have not entered the correct password! Please try again."
on the registration page it emailed me the login name and password I signed up with. I know the password is right but it wont accept it.
any ideas why?
"The Login Name, 'abcde' exists, but you have not entered the correct password! Please try again."
Then try again ;)
Post some part of the code, which you think is creating the problem. If it is a logic issue, be more specific.
[edited by: Habtom at 12:41 pm (utc) on Sep. 11, 2007]
<!-- form for Member login -->
<form action="login.php" method="POST">
<p><table border="0">
<?php #30
if (isset($message))
{
echo "<tr><td style='color: red'
colspan='2' >$message <br /></td></tr>";
}
?>
<tr><td class="bold_right">Username</td>
<td><input type="text" name="fusername"
size="20" maxsize="20"></td></tr>
<tr><td class="bold_right">Password</td>
<td><input type="password" name="fpassword"
size="20" maxsize="20"></td></tr>
<input type="hidden" name="do"
value="login">
<tr><td style="text-align: center" colspan="2">
<br /><input type="submit" name="log"
value="Enter"></td></tr>
</table>
</form>
The above is from an .inc file
switch (@$_POST['do'] )
{
case "login":
$cxn = mysqli_connect($host, $user, $passwd,$dbname)
or die ( "Couldn't connect to server. ") ;
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername] ' " ;
$result = mysqli_query($cxn, $sql)
or die ("Couldn't execute query.") ;
$num = mysqli_num_rows($result);
if ($num > 0) // login name was found
{
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername] '
AND password=md5('$_POST[fpassword]') " ;
$result2 = mysqli_query($cxn,$sql)
or die("Couldn't execute query 2.");
$num2 = mysqli_num_rows($result2);
if ($num2 > 0) // password is correct
{
$_SESSION['auth']="yes";
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d h:i:s");
$sql = "INSERT INTO login (loginName,loginTime)
VALUES ('$logname','$today')";
$result = mysqli_query($cxn,$sql)
or die("Can't execute insert query.");
header("Location: member_page.php");
}
else // password is not correct
{
$message="The Login Name, '$_POST[fusername]'
exists, but you have not entered the
correct password! Please try again.<br />";
include("login_form.inc");
}
}
elseif ($num == 0) // login name not found
the above is from my login.php file
Find the appropriate lines and replace them with the following lines. The md5 seems to do it for the $_POST array itself instead of the data in it. (I could be wrong though)
Give it a try by replacing it with the following lines:
$loginName = $_POST['fusername'];
$password = md5($_POST['fpassword']);
$sql = "SELECT loginName FROM member WHERE loginName='". $loginName ."' AND password = '". $password ."'" ;
$result2 = mysqli_query($cxn,$sql) or die("Couldn't execute query 2.");
$num2 = mysqli_num_rows($result2);
Find the appropriate lines.
case "login":
$cxn = mysqli_connect($host, $user, $passwd,$dbname)
or die ( "Couldn't connect to server. ") ;
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername] ' " ;
$result = mysqli_query($cxn, $sql)
or die ("Couldn't execute query.") ;
$num = mysqli_num_rows($result);
if ($num > 0) // login name was found
{
$sql = "SELECT loginName FROM member
WHERE loginName='$_POST[fusername] '
AND password=md5('$_POST[fpassword]') " ;
$result2 = mysqli_query($cxn,$sql)
or die("Couldn't execute query 2.");
$num2 = mysqli_num_rows($result2);
if ($num2 > 0) // password is correct
{
$_SESSION['auth']="yes";
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d h:i:s");
$sql = "INSERT INTO login (loginName,loginTime)
VALUES ('$logname','$today')";
$result = mysqli_query($cxn,$sql)
or die("Can't execute insert query.");
header("Location: member_page.php");
}
else // password is not correct
{
$message="The Login Name, '$_POST[fusername]'
exists, but you have not entered the
correct password! Please try again.<br />";
include("login_form.inc");
}
}
elseif ($num == 0) // login name not found
{
$message = "The Login Name you entered does not
exist! Please try again.<br />";
include("login_form.inc");
}
break;