Please login or register.

Login with username, password and session length
Advanced search  

News:

Get quality web hosting, virtual private servers, reseller web hosting, and dedicated servers from www.webhostfreaks.com or www.serverpowered.com!

Maintenance Notice

PHPFreaks has successfully moved to a new Dedicated Server, hosted by Server Powered. Please help support future upgrades by Donating.

Author Topic: Pressing Submit Refreshes My Login  (Read 166 times)

0 Members and 1 Guest are viewing this topic.

TheHaloEffect

  • Member
  • Offline Offline
  • Posts: 13
    • View Profile
Pressing Submit Refreshes My Login
« on: May 18, 2007, 07:35:43 AM »
I've made a log in script but when I press submit...The script just appears to refresh.

Can anyone see what's going on?:)

Thanks

Code: [Select]
<html>
<head><title>Register</title></head>
<body>
<?php
$self 
$_SERVER['PHP_SELF'];;
$username $_POST['username'];
$password $_POST['password'];
 
if( ( 
$username == NULL ) or ( $password == NULL ) ) {
        
$form ="Please enter all new user details...";
        
$form.="<form action=\"$self\"";
        
$form.="method=\"post\">Username: ";
        
$form.="<input type=\"text\" name=\"username\"";
        
$form.=" value=\"$username\"><br>Password: ";
        
$form.="<input type=\"text\" names=\"password\"";
        
$form.=" value=\"$password\"><br>";
        
$form.="<input type=\"submit\" value=\"Submit!\">";
        
$form.="</form>";
        echo( 
$form );
}else{
        
// MySQL details
        
$mysql_host="localhost";
        
$mysql_user="nikon";
        
$mysql_pass="lol";
        
$mysql_dbname="nutrition_db";
 
 
        
//Connect to MySQL
        
$conn = @mysql_connect"localhost""nikon""lol" )
                or die(
"Could not connect to MySQL");
        
        
        
//Selects the database
        
$db = @mysql_select_db"nutrition_db"$conn )
                        or die(
"Could not select database");
        
        
//creates the query
        
$sql "insert into users (username, password) values ('".$username."', '".$password."')";
        
        
$result = @mysql_query$sql$conn )
                or die(
"Could not execute query");
        
        if( 
$result !== FALSE)  
                 echo( 
"New user $username added" ); 
}
?>

</body>
</html>
Logged

SoulAssassin

  • Member
  • Offline Offline
  • Posts: 34
    • View Profile
Re: Pressing Submit Refreshes My Login
« Reply #1 on: May 18, 2007, 07:57:38 AM »
Why are doing your form in PHP format?
It just makes it much easier to do it in HTML.
I also don't really understand why you put form values in "$username".

But this is what I would have done

<?
if(isset(
$_POST['Submit']))

if (
$_POST['username'] == "" or $_POST['password'] == "" 
{
echo 
"Please complete Username and Password";
}
else
{
$self $_SERVER['PHP_SELF'];
$username $_POST['username'];
$password md5($_POST[password]); //password encryption

$mysql_host="localhost";
$mysql_user="nikon";
$mysql_pass="lol";
$mysql_dbname="nutrition_db";

$conn = @mysql_connect"localhost""nikon""lol" )
or die(
"Could not connect to MySQL");
        

$db = @mysql_select_db"nutrition_db"$conn )
or die(
"Could not select database");

$sql "insert into users (username, password) values ('$username', '$password')";
        
$result = @mysql_query$sql$conn )
or die(
"Could not execute query");
        
if(
$result
{
echo( 
"New user $username added" ); 
}
}
}
?>
Please enter all new user details...
<form action="<? $self ?>"method="post">
Username:<input type="text" name="username" value="">
<br>
Password:
<input type="text" names="password" value="">
<br>
<input type="submit" value="Submit" name="Submit">
</form>
Logged

TheHaloEffect

  • Member
  • Offline Offline
  • Posts: 13
    • View Profile
Re: Pressing Submit Refreshes My Login
« Reply #2 on: May 18, 2007, 09:52:43 AM »
Thank you for your reply...but all this does is refreshes and makes "Please enter all new user details..." into "Please complete Username and PasswordPlease enter all new user details..."

The script that i posted above was 90% copied out of a book...I didn't imagine the book to be wrong =/


Why are doing your form in PHP format?
It just makes it much easier to do it in HTML.
I also don't really understand why you put form values in "$username".

But this is what I would have done

<?
if(isset(
$_POST['Submit']))

if (
$_POST['username'] == "" or $_POST['password'] == "" 
{
echo 
"Please complete Username and Password";
}
else
{
$self $_SERVER['PHP_SELF'];
$username $_POST['username'];
$password md5($_POST[password]); //password encryption

$mysql_host="localhost";
$mysql_user="nikon";
$mysql_pass="lol";
$mysql_dbname="nutrition_db";

$conn = @mysql_connect"localhost""nikon""lol" )
or die(
"Could not connect to MySQL");
        

$db = @mysql_select_db"nutrition_db"$conn )
or die(
"Could not select database");

$sql "insert into users (username, password) values ('$username', '$password')";
        
$result = @mysql_query$sql$conn )
or die(
"Could not execute query");
        
if(
$result
{
echo( 
"New user $username added" ); 
}
}
}
?>
Please enter all new user details...
<form action="<? $self ?>"method="post">
Username:<input type="text" name="username" value="">
<br>
Password:
<input type="text" names="password" value="">
<br>
<input type="submit" value="Submit" name="Submit">
</form>

Logged

yzerman

  • Member
  • Offline Offline
  • Posts: 182
    • View Profile
Re: Pressing Submit Refreshes My Login
« Reply #3 on: May 18, 2007, 10:07:53 AM »
Code: [Select]
<html>
<head><title>Register</title></head>
<body>
<?php
$self 
$_SERVER['PHP_SELF'];;
$username $_POST['username'];
$password $_POST['password'];
if (!isset(
$_POST['submit'])) { //form hasn't been submitted
//the reason the next line is wrong is because &nbsp; will return a true statement
//if( ( $username == NULL ) or ( $password == NULL ) ) {
        
$form ="Please enter all new user details...";
        
$form.="<form action=\"$self\"";
        
$form.="method=\"post\">Username: ";
        
$form.="<input type=\"text\" name=\"username\"";
        
$form.=" value=\"$username\"><br>Password: ";
        
$form.="<input type=\"text\" names=\"password\"";
        
$form.=" value=\"$password\"><br>";
        
$form.="<input type=\"submit\" value=\"Submit!\">";
        
$form.="</form>";
        echo( 
$form );
}else{ 
//form's been submitted
         // MySQL details
        
$mysql_host="localhost";
        
$mysql_user="nikon";
        
$mysql_pass="lol";
        
$mysql_dbname="nutrition_db";
 
 
        
//Connect to MySQL
        
$conn = @mysql_connect"localhost""nikon""lol" )
                or die(
"Could not connect to MySQL");
        
        
        
//Selects the database
        
$db = @mysql_select_db"nutrition_db"$conn )
                        or die(
"Could not select database");
        
        
//creates the query
        
$sql "insert into users (username, password) values ('".$username."', '".$password."')";
        
        
$result = @mysql_query$sql$conn )
                or die(
"Could not execute query");
        
        if( 
$result !== FALSE)  
                 echo( 
"New user $username added" ); 
}
?>

</body>
</html>
Logged

Posting a link is not always helping someone - it is showing your ability to google.
 

Page created in 0.054 seconds with 17 queries.