Jump to content

Need help with first ever php code


daveh24706

Recommended Posts

hello,

 

im new to php,only at it a week and im writing a registration script. I cant figure out what im doing wrong. When i enter my details and click register nothing happens and its just goes back to original register form. i dont even get an error message. my code is below.

 

 


<?php


// set a submit variable
    
    $submit = $_POST['submit'];
    
// other values that need to be obtained from the form   

    $fullname = $_POST['fullname'];

    $username = $_POST['username'];

    $password = $_POST['password'];

    $repeatpassword = $_POST['repeatpassword'];

    $date = date("y-m-d");

    $email = $_POST['email'];

  
if ($submit)
{


//Open database
$connect = mysql_connect("localhost","root","");
mysql_select_db("phplogin");//select database

$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
$count = mysql_num_rows($namecheck);

if($count!=0)
{
die("Username already taken!");

if ($fullname&&$username&&$password&&$repeatpassword&&$email)

   {
     if ($password==$repeatpassword)
     {
     if (strlen($username)>25 || strlen ($fullname)>25)
     {
     echo "username/fullname is too long. Max 25 characters";
     
     }
      else
      {
      if (strlen($password) >25 || strlen ($password) <6)
      {
      echo "password must be between 6 and 25 characters";
      
      }
        else
        {
      //register the user
        
        
        $queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$email')");
        
        die ("you have been registered! <a href='index.php'>return to login page </a>");
        
        }
      
      }
     }
     else
          echo "your passwords do not match";
   }
    
  else
  echo "please fill in all fields";
}
     }


  
?>


Link to comment
Share on other sites

I know your problem, where you have

$submit = $_POST['submit'];

and then

if ($submit)

if checks to see if it is true or false, what your putting inside it is if(submit), which won't do anything.

I am assuming your making it check to see if the person submitted the page, use this:

<?php
if(isset($_POST['submit'])) {
//do register stuff
}
else {
//show register form
}
?>

And as a side note, what you have here is VERY insecure, so i'm hoping your not uploading that script somewhere. It's open to SQL Injection.

Link to comment
Share on other sites

get rid of the submit variable, you won't be using it.

replace:

if ($submit)

with

if(isset($_POST['submit']))

this checks to see if submit is set. If it is set then it will produce 'true', if it's not true, it will be false.

The 'if' statement checks to see if the condition is true or false. that's ALL it checks.

If you still need more help look up booleans

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.