0

Hi Everyone,

I would appreciate it if someone could have a look at this short mysqli script and tell my why I am getting this parse error:

Parse error: syntax error, unexpected T_VARIABLE in /home/james230/public_html/xampp/htdocs/lesson1/login.php on line 10

I had this set up as mysql and it works perfectly, but I have to have it work under mysqli for the course I am doing. I know that it sounds crazy but for some reason I have a lot of problems doing the mysqli change over and would really appreciate some help here.

<?php

session_start();

include ('mysqli.php');
echo "<pre>";
var_dump($_POST);
echo "</pre>";
if (isset ($_POST['submit'])) {
$username = mysqli_real_escape_string($link,$select)$_POST['username']));
$password = mysqli_real_escape_string($link,$select)$_POST['password']));
if(!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

if (!empty ($username) && !empty ($password)) {
$link = mysqli_query ("SELECT * FROM Customer
WHERE username='$username' AND
password='$password' LIMIT 1");



if (mysqli_num_rows ($result) > 0) {
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;

echo 'You are now logged in! <br />
Please proceed to the 
<a href="http://www.professorofprofit.com/xampp/htdocs/lesson1/members.php">
Members Only Page</a>';

} else {
echo 'Your username and/or password is incorrect.<br /> If you do not have one, please go <a href= "http://www.professorofprofit.com/xampp/htdocs/lesson1/register.php">
HERE</a> and register to become a member. Thank you...!';
}
} else {
echo 'You must enter a username and a password!';

}
} else {
include ('two_forms.inc');
}


?>

I am going to include the connect script in case it is in this area that the problem is happening. 

<?php

ini_set("display_errors","on");
error_reporting(E_ALL | E_STRICT);
ini_set("include_path","./includes");

$link = mysqli_connect($host,$user,$passwd, $dbname)
or die("error connecting to database!".mysqli_error($cxn));

$select = mysqli_select_db($link,$dbname) or die ('error selecting database!'.mysqli_error());

?>

I appreciate anyone taking the time to help me with this. I hope to return the favor sometime. Have great day everyone.

fridge2305

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
11
Replies
12
Views
7 Years
Discussion Span
Last Post by bigjoke
0

hi there,

dont know much about sqli stuff at the moment but a quick looksie at your code suggests that there is a problem with syntax. Try changing your line 10 so that it looks something like this..

$username = mysqli_real_escape_string($link,$select).$_POST['username'];

Do the same for line 11.

Hopefully, you will find that the error has now disappeared

regards

0

Hi,

The new line helped but created these new problems which are:

Warning: mysqli_query() expects at least 2 parameters, 1 given in /login.php on line 20

Notice: Undefined variable: result in /login.php on line 24

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /login.php on line 24

If you could help me with these I would also really appreciate it. Can you tell me where you came up with the line I used for line 10? Is it mysqli specific as I have never seen it without the 2 )); at the end?

Again, thanks very much...

fridge2305

0

Ummm, first things first :) try to code your original post so i know which line is actually line 20 :D

Anyway, the following link should be bookmarked. It may not make much sense if you are new to this but is very useful whenever you get parsing errors. i just followed it and found that you were using too many parentheses.

http://php.net/manual/en/mysqli.real-escape-string.php

On your line 20, you are using $result variable.. Now, i cant see where you have actually initialize it...Do you think that might be the problem? maybe change it with $link !!! which you HAVE initialized :)

Hope it helps

0

Hi bigjoke,

I did as you suggested and now down to one error which is:

Notice: Undefined variable: link in /login.php on line 12
Connect failed:

I really have to admit this is over my head and I am referring to the link you also sent me and I am not sure what I should be looking for. Any advice and assistance with this is greatly appreciated. Look forward to your thoughts or advice...

fridge2305

0

Quick question? can you double check that you are indeed getting connected to the database?

try inserting this line after you think your connection takes place and check what php says about it. Alter the variable appropriately.

trigger_error ("database: $db is connected", E_USER_NOTICE);

Very useful to check value of $link as well!

cheers

PS. reply back fairly quickly as i will be away from computer in 10 min for maybe an hour or so ..

0

Hi bigjoke,

I am really sorry but I am not sure where you want me to put this line of code. Can you explain 'after you think the connection takes place. I included the full script of the login and connection scripts in my first question. Could you possibly look and tell me where I should put the new line of code. Sorry to be such a pain in the butt, but I just am not sure where you mean. Thanks again..

fridge2305

0

no need to be sorry .. thats how u learn!

ok put that line of code on line 60...

change the bit in quotes on that line so that it shows u the value for $link and $result. post it here... whats your $dbname anyway. i cant see it here .

cheers

0

just noticed something... Change $link on line 19 to $result. $link variable contains info required to connect to database like username, pass etc etc.

EDIT: insert this line right at the end of your code. I dont know if it affects anything but u always should close the database connection before finish running your script/PHP file.

mysqli_close($link);

Edited by bigjoke: n/a

0

Hi bigjoke,

Ok here are all of the lines that are coming back now with the changes that you had me make. My database name is CustomerDirectory.

Notice: Undefined variable: db in /mysqli.php on line 16

Notice: database: is connected in /mysqli.php on line 16

Notice: Undefined variable: result in //login.php on line 20

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /login.php on line 22

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /login.php on line 28

Your username and/or password is incorrect.

If you do not have one, please go HERE and register to become a member. Thank you...!

Warning: mysqli_close() expects parameter 1 to be mysqli, null given in /login.php on line 55

The first two are based on the second script above mysqli.php and the remainder are the login.php script.

What a can of worms I have created here. Like I said, it worked like a dream in mysql but for some instructor wanting it in mysqli, I would be finished the course.

Thanks for all of your help, I do appreciate it...

fridge2305

0

OK start with the script where you set up a connection.... line 50 -line 60. Where have you provided these details. $host,$user,$passwd, $dbname. Echo the values of these variables and see if they are what you expect.(You should have them in hand b4 u even started writing any code.)

Comment out everything else so we can locate the error with minimum fuss. Lots of errors happens just because there is a variable missing or whatever...Focus on the DB connection , for now. Make sure you are including all the files required so the main script file knows where to look for them. report back...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.