This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-05 03:24:12

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Well... this is weird!

I made this code:

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)


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#2 2011-10-05 03:38:12

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Well... this is weird!

Look at line 30.  find error.


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#3 2011-10-05 03:44:33

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Well... this is weird!

Strange... hmmm...


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#4 2011-10-05 03:59:48

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Well... this is weird!

line thirty is the include "error2.php"; but I don't see what could be wrong with that.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#5 2011-10-05 04:20:43

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: Well... this is weird!

I noticed


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#6 2011-10-05 04:22:30

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Well... this is weird!

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  smile

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)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#7 2011-10-05 07:25:10

TheSuccessor
Scratcher
Registered: 2010-04-23
Posts: 1000+

Re: Well... this is weird!

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.  wink

Last edited by TheSuccessor (2011-10-05 07:25:29)


/* No comment */

Offline

 

#8 2011-10-05 11:02:16

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: Well... this is weird!

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.  wink

Wouldn't it then be

Code:

mysql_query("INSERT INTO failed_logins
    (ip) VALUES('$ip')")

???


Posts: 20000 - Show all posts

Offline

 

#9 2011-10-05 11:20:29

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Well... this is weird!

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)


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#10 2011-10-05 12:27:13

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Well... this is weird!

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.  wink

Good practice to put it at the start so all your scripts can access it.


http://i.imgur.com/zeIZW.png

Offline

 

#11 2011-10-05 12:38:51

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Well... this is weird!

Well you learn something new every day! I had no idea the include function worked without parentheses!

I did know about the session_start() not needing to go at the start, but it is good practice  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#12 2011-10-05 12:43:04

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Well... this is weird!

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 :\


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#13 2011-10-05 12:53:10

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Well... this is weird!

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)


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#14 2011-10-05 13:38:10

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Well... this is weird!

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  smile

Thanks! But now I'm getting: Parse error: syntax error, unexpected T_LOGICAL_OR in /home/a5292800/public_html/loader.php on line 28
hmm


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#15 2011-10-05 14:26:29

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Well... this is weird!

Google "Mysql insert" and check that your syntax matches the example.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#16 2011-10-05 14:54:05

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: Well... this is weird!

It does seem to be a mysql related error, when I googled it


http://i.imgur.com/zeIZW.png

Offline

 

Board footer