I made this code:
<?php
//Database Information
$dbhost = '*';
$dbuser = '*';
$dbpass = '*';
$dbname = '*'; // the database you put the table into.
//Connect to database
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$ip = $_SERVER["REMOTE_ADDR"];
session_start();
$username = $_POST['username'];
$password = ($_POST['password']);
$query = "select * from users where username='$username' and password='$password'";
$result = mysql_query($query);
if (mysql_num_rows($result) != 1) {
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')
or die(mysql_error());
include "error2.php";
} else {
$_SESSION['username'] = "$username";
mysql_query("INSERT INTO successful_logins
(ip) VALUES('$ip')
or die(mysql_error());
include "loaded.php";
}
?>And it keeps saying: Parse error: syntax error, unexpected T_STRING in /home/a5292800/public_html/loader.php on line 30
Last edited by WindowsExplorer (2011-10-05 03:24:38)
Offline
line thirty is the include "error2.php"; but I don't see what could be wrong with that.
Offline
include is a php function. All php functions have a space for variables to be entered, even if they have no variable needed like so: function(). Your variable for include function is the page you are including so you need to add the brackets to show where the variable starts and stops
replace:
include "error2.php";
with
include ("error2.php");
Also; session_start() needs to go before any other php in your code, so move it up to the top!
remove the brackets you don't need from the line "$password = ($_POST['password']);"
It is a good idea to follow common practice with MySQL and capitalise key action words in this line: $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
Last edited by sparks (2011-10-05 04:26:35)
Offline
This:
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')needs a " at the end, i.e.
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')"and the same with the code in the else bit.
@sparks: session_start() only needs to go before any output or session usage, not necessarily at the beginning. It's still a good idea to put it there anyway, though.
Last edited by TheSuccessor (2011-10-05 07:25:29)
Offline
TheSuccessor wrote:
This:
Code:
mysql_query("INSERT INTO failed_logins (ip) VALUES('$ip')needs a " at the end, i.e.
Code:
mysql_query("INSERT INTO failed_logins (ip) VALUES('$ip')"and the same with the code in the else bit.
@sparks: session_start() only needs to go before any output or session usage, not necessarily at the beginning. It's still a good idea to put it there anyway, though.![]()
Wouldn't it then be
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')")???
Offline
sparks, the include wasn't actually the error - it was I was forgetting the " at the end like TheSuccessor wrote - But that's anyway! (also, the include function can work without brackets)
Offline
TheSuccessor wrote:
This:
Code:
mysql_query("INSERT INTO failed_logins (ip) VALUES('$ip')needs a " at the end, i.e.
Code:
mysql_query("INSERT INTO failed_logins (ip) VALUES('$ip')"and the same with the code in the else bit.
@sparks: session_start() only needs to go before any output or session usage, not necessarily at the beginning. It's still a good idea to put it there anyway, though.![]()
Good practice to put it at the start so all your scripts can access it.
Offline
LOL! But now I'm getting this message: Parse error: syntax error, unexpected ';' in /home/a5292800/public_html/loader.php on line 28
And when I take away the ;, I get: Parse error: syntax error, unexpected T_INCLUDE in /home/a5292800/public_html/loader.php on line 29
whether I have the brackets or not :\
Offline
replace
if (mysql_num_rows($result) != 1) {
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')
or die(mysql_error());
with
if (mysql_num_rows($result) != 1) {
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')");
or die(mysql_error());
Unexpected does not [i]necessarily mean that it does not belong there, it could also (as is the case here) mean that it's waiting for something else that you've missed. In this case it was waiting for the ") to match the beginning of the query (I marked it in blue) and the ; at the very end :)
Last edited by sparks (2011-10-05 12:54:03)
Offline
sparks wrote:
replace
if (mysql_num_rows($result) != 1) {
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')
or die(mysql_error());with
if (mysql_num_rows($result) != 1) {
mysql_query("INSERT INTO failed_logins
(ip) VALUES('$ip')");
or die(mysql_error());Unexpected does not [i]necessarily mean that it does not belong there, it could also (as is the case here) mean that it's waiting for something else that you've missed. In this case it was waiting for the ") to match the beginning of the query (I marked it in blue) and the ; at the very end
![]()
Thanks! But now I'm getting: Parse error: syntax error, unexpected T_LOGICAL_OR in /home/a5292800/public_html/loader.php on line 28
Offline