[NOT SA-MP]PHP/MySQL Website Error[NOT SA-MP]
#1

Hello guys. I started to make a PHP+MySQL Website, and made a registering system together with the help of a tutorial.

All works perfectly when simple, but when i try to makeup the design, it gives me errors. Not sure if the error comes from MySQL or PHP, but shoul be easy to solve to someone that actualy knows these languages good.

So let's take it to the point.

This works perfectly:
Код:
<?php
include("conf.inc.php"); // Includes the db and form info.
session_start(); // Starts the session.
if (!isset($_POST['submit'])) { // The form has not been submitted.
    echo "<form action=\"login.php\" method=\"POST\">";
    echo "<table>";
    echo "<tr>";
    echo "<td colspan=\"2\">Login:</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />";
    echo "</tr>";
    echo "<tr>";
    echo "<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";
    echo "</tr>";
    echo "</table>";
    echo "</form>";
} else {
    $username = form($_POST['username']);
    $password = md5($_POST['password']); // Encrypts the password.

    $q = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query
    $r = mysql_num_rows($q); // Checks to see if anything is in the db.

        if ($r == 1) { // There is something in the db. The username/password match up.
        $_SESSION['logged'] = 1; // Sets the session.
        header("Location: site.php"); // Goes to main page.
        exit(); // Stops the rest of the script.
        } else { // Invalid username/password.
header("Location: login.php"); // Goes back to login page.
    }
}

mysql_close($db_connect); // Closes the connection.
?>
And this gives me this error:
http://i50.tinypic.com/2day7ah.png

And if i put the right user name and password:
http://i46.tinypic.com/acewt1.png

Код:
<BODY BGCOLOR = "#A0A0A0">
<div align="center">
<img src="http://images.cooltext.com/2643376.png" width="209" height="109" alt="Login" />
<br /></a>
<table border="5">
<tr>
<th>
<?php
include("conf.inc.php"); // Includes the db and form info.
session_start(); // Starts the session.
if (!isset($_POST['submit'])) { // The form has not been submitted.
    echo "<form action=\"login.php\" method=\"POST\">";
    echo "<table>";
    echo "<tr>";
    echo "<td colspan=\"2\">Login:</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />";
    echo "</tr>";
    echo "<tr>";
    echo "<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";
    echo "</tr>";
    echo "</table>";
    echo "</form>";
} else {
    $username = form($_POST['username']);
    $password = md5($_POST['password']); // Encrypts the password.

    $q = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query
    $r = mysql_num_rows($q); // Checks to see if anything is in the db.

        if ($r == 1) { // There is something in the db. The username/password match up.
        $_SESSION['logged'] = 1; // Sets the session.
        header("Location: site.php"); // Goes to main page.
        exit(); // Stops the rest of the script.
        } else { // Invalid username/password.
header("Location: login.php"); // Goes back to login page.
    }
}

mysql_close($db_connect); // Closes the connection.
?>
Thanks. It's the same with ALL other pages.. If i let them likke original, all works, if i change them to look better, this happens.
Reply
#2

Headers must go at the top of your file, it can give errors if it doesn't as it must be sent before anything else.
Reply
#3

You mean adding <HEAD>? If so, where should i put the finam </HEAD>? Cos the params i used up there like align center, are also supposed to align the PHP registering boxed..
Reply
#4

No sorry... In PHP you have header('location: somewhere'); or just header('SOMETHING');, this must be above any content on the page (so above the <html> tags) and shouldn't have white space above them. I find them very tricky, sometimes they work but most of the time you do need to add them at the top of the page rather than in the middle.
Reply
#5

Quote:
Originally Posted by TheJayMan
Посмотреть сообщение
No sorry... In PHP you have header('location: somewhere'); or just header('SOMETHING');, this must be above any content on the page (so above the <html> tags) and shouldn't have white space above them. I find them very tricky, sometimes they work but most of the time you do need to add them at the top of the page rather than in the middle.
No way you can give me an example of how to fix this page? It's my first time working with PHP/MySQL. :S
Reply
#6

The problem is your headers... Just remove them and replace them with either a link or HTML redirect.

PHP код:
<BODY BGCOLOR = "#A0A0A0">
<div align="center">
<img src="http://images.cooltext.com/2643376.png" width="209" height="109" alt="Login" />
<br /></a>
<table border="5">
<tr>
<th>
<?php
include("conf.inc.php"); // Includes the db and form info.
session_start(); // Starts the session.
if (!isset($_POST['submit'])) { // The form has not been submitted.
    
echo "<form action=\"login.php\" method=\"POST\">";
    echo 
"<table>";
    echo 
"<tr>";
    echo 
"<td colspan=\"2\">Login:</td>";
    echo 
"</tr>";
    echo 
"<tr>";
    echo 
"<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />";
    echo 
"</tr>";
    echo 
"<tr>";
    echo 
"<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />";
    echo 
"</tr>";
    echo 
"<tr>";
    echo 
"<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";
    echo 
"</tr>";
    echo 
"</table>";
    echo 
"</form>";
} else {
    
$username form($_POST['username']);
    
$password md5($_POST['password']); // Encrypts the password.
    
$q mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query
    
$r mysql_num_rows($q); // Checks to see if anything is in the db.
        
if ($r == 1) { // There is something in the db. The username/password match up.
        
$_SESSION['logged'] = 1// Sets the session.
        // PUT YOUR HTML REDIRECT HERE, OR LINK
        
exit(); // Stops the rest of the script.
        
} else { // Invalid username/password.
        
        
        // PUT YOUR HTML REDIRECT HERE, OR LINK
    
}
}
mysql_close($db_connect); // Closes the connection.
?>
That should work..
Reply
#7

It actualy says: Parse error: syntax error, unexpected '<' in /home/tvsempre/public_html/site/login.php on line 37

If i add the HTML links like that: <a href="login.php"></a>
Reply
#8

echo "<a href=\"login.php\"></a>";
Reply
#9

Made it like that, and now it shows this:
Код:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/tvsempre/public_html/site/login.php:8) in /home/tvsempre/public_html/site/login.php on line 10
PHP код:
<BODY BGCOLOR = "#A0A0A0"> 
<div align="center">
<img src="http://images.cooltext.com/2643376.png" width="209" height="109" alt="Login" />
<br />
<table border="5">
<tr>
<th>
<?php 
include("conf.inc.php"); // Includes the db and form info. 
session_start(); // Starts the session. 
if (!isset($_POST['submit'])) { // The form has not been submitted. 
    
echo "<form action=\"login.php\" method=\"POST\">"
    echo 
"<table>"
    echo 
"<tr>"
    echo 
"<td colspan=\"2\">Login:</td>"
    echo 
"</tr>"
    echo 
"<tr>"
    echo 
"<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />"
    echo 
"</tr>"
    echo 
"<tr>"
    echo 
"<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"text\" />"
    echo 
"</tr>"
    echo 
"<tr>"
    echo 
"<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Login\"</td>"
    echo 
"</tr>"
    echo 
"</table>"
    echo 
"</form>"
} else { 
    
$username form($_POST['username']); 
    
$password md5($_POST['password']); // Encrypts the password. 

    
$q mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query 
    
$r mysql_num_rows($q); // Checks to see if anything is in the db. 

        
if ($r == 1) { // There is something in the db. The username/password match up. 
        
$_SESSION['logged'] = 1// Sets the session. 
        
echo "<a href=\"site.php\"></a>";
        exit(); 
// Stops the rest of the script. 
        
} else { // Invalid username/password. 
        
echo "<a href=\"login.php\"></a>";
    } 


mysql_close($db_connect); // Closes the connection. 
?>
</th>
</tr>
</table>
</div>
</BODY>
Reply
#10

Try putting the session above your config includes, if that fails just remove it from there and add above the HTML tag.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)