Hello all, first post here.

I'm a newbie in php code, but declaring a simple variable I thought I could do, but apparently not. I cannot figure out which rule I broke, but I keep getting an error message in line 4 of the following code for an unexpected t variable:

<?php
ob_start();
$host="localhost";
$username="";
$password="";
$db_name="member_login";
$tbl_name="members";

I wont bother you with the rest of the code. In case there it says a different line when I post this, my error is on the line for username, but for the life of me I can't figure out how I messed that up.

Recommended Answers

All 9 Replies

You have corrected the error during posting; initially (in your code) you forgot to put semicolon after line3.

looks fine. can u comment that line and see if the error goes to the next line instead?

You have corrected the error during posting; initially (in your code) you forgot to put semicolon after line3.

that's what i thought but the codes now looks fine. puzzled me.

I copied and pasted the code, so I did not change it in posting, but I double checked anyway. What you see is what I have. Tested adding comments, no it did not change anything. On a hunch, got rid of ob_start() and the flush at the end. That got rid of the T_Variable error, but now it always says wrong username or password when checking with my sql database and also this error comes up: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26" I'm unsure what all you need to see or why getting rid of the ob(start) worked, but let me know what you need to see and i will post it. currently, I have my sql database, a main_login.php, a checklogin.php and a login_success.php

I dont get it. normally you'll get Incorrect T_VARIABLE when there is incorrect variable or there is no semi-colon on the last line.
can you post the whole line of error.

Alright, like I said, changed my code from the Main_Login.php file, and it almost works now. Now if I can just get the last bit of code on my checklogin.php file to work, I should be in business. However, I keep getting this error: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\checklogin.php on line 26.

Here is the code for checklogin.php

<?php
$host="localhost";
$username=""; 
$password="";
$db_name="test";
$tbl_name="members";


mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];


$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);


$count=mysql_num_rows($result);


if($count==1){

session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

I can't figure out where I messed up here...any thoughts?

Please show us some more of your code...:idea:

That's it for that file. From what I understand of boolean errors, it does not like something about my if else statement. But I can't see where its wrong.

My bad, it was a typo, I had something mispelled. It was searching for "test" database and I had mispelled it in the naming of the database. Sorry for bugging everyone. later.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.