-1

Im trying to make my school project and would like to make a login system and registration system...my login queries are fine but my registration is taking its time...ivev been here for 3-4 hours trying to figure this out im crying right now.... ive done everything....so in my desperate need i asked this community... please provide immediate answers i desperately need it... the problem is... i cannot seem to haul in the data that i type into my form...tahts it...i dont know whats the reason behind

if($_POST['registerbtn'])
{
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getconfirmation = $_POST['confirmation'];

            if($getemail){


             if($getuser){

                 if($getpass){

                     if($getconfirmation){

                         if( $getpass === $getconfirmation ){
                             if( (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, "."))) {

                                 require("./Connect.php");

                                 $query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                 $numrows = mysql_num_rows($query);

                                 if($numrows == 0){
                                 $query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
                                 $numrows = mysql_num_rows($query);

                                 if($numrows == 0){

                                      $date = date("F d, Y");
                                      $code = rand();

                                      mysql_query("INSERT INTO users VALUES('', '$getuser', '$getemail', '$getpass', '$date' )");
                                      mysql_query("SELECT * FROM users WHERE username='$getuser'");
                                      $numrows = mysql_num_rows($query);

                                     if($numrows == 1){



                                     }else
                                       $errormsg = "An Error Has Occurred. Account Not Processed";


                                 }else
                                     $errormsg ="There is already a user with that email.";


                                 }else
                                     $errormsg ="There is already a user with that username.";


                                 mysql_close();

                             }else
                                 $errormsg = "You must enter a valid email address";

                         }else
                             $errormsg = "Your passwords did not match";


                     }else
                     $errormsg = "Confirm your password";
                 }else
                  $errormsg = "You must enter your password";
             }else
               $errormsg = "You must enter your username";



            }else
             $errormsg = "You must enter your email address";

}





$form = "<form action='./register.php' method='post'>

<table>
<tr>
<td></td>
<td><font color='red'>$errormsg</font></td>
</tr>
</table>
<fieldset>
<legend>Account</legend>
<input type='text' name='user' size='15' value='$getuser'/>:Username<br/>
<input type='text' name='email' size='15'value='$getemail'>:Email<br/>
<input type='password' name='pass' size='15' value=''/>:Passcode<br/>
<input type='password' name='confirmation' size='15' value=''/>:Confirmation<br/>
<br/>
<input type='submit' name='registerbtn' value='EAT ME'/>
</fieldset>
</form>";
  echo "$form";
?>
  • 1
    Where does it go wrong? Which error message are you getting? We need to know which piece of code is causing the issue so we can answer the question easier for you. – Jordy Mar 03 '15 at 08:37
  • 1
    Wow that's some fancy spaghetti code!! =D Hey, maybe `$_POST['registerbtn']` is false, and everything is just skipped. – Jeremy Thille Mar 03 '15 at 08:38
  • @JeremyThille Is it really? why would it? – Jordy Mar 03 '15 at 08:42
  • I don't know. Why not? How do you know it's not? Debug your code by echoing values here and there. What does `echo $_POST['registerbtn'];` output? – Jeremy Thille Mar 03 '15 at 08:49
  • 1
    What does `var_dump($_POST)` show when you submit the form? – Barmar Mar 03 '15 at 08:49
  • @Barmar it shows this i dont know waht they are XD im only in 8th gradew trying to learn array(5) { ["user"]=> string(8) "Myname09" ["email"]=> string(17) "Myemail@gmail.com" ["pass"]=> string(8) "Myname09" ["confirmation"]=> string(8) "Myname09" ["registerbtn"]=> string(6) "EAT ME" } – Fawn Frauscht Mar 03 '15 at 08:55
  • @ Jeremy Thille it only displays "eat me" its the value i set for it – Fawn Frauscht Mar 03 '15 at 08:56
  • @Jordy Uhm....everything else works fine but the problem lies in if($numrows == 1){} – Fawn Frauscht Mar 03 '15 at 08:57
  • @Jordy they seem to execute the commands right before that... and the error code iset in for " if($numrows == 1) { }else echo"whatever i put iin there".... shows up – Fawn Frauscht Mar 03 '15 at 08:57
  • Are you sure the values in the `INSERT` query are in the right order? It's best to put the list of columns explicitly, e.g. `INSERT INTO users (id, username, email, ...) VALUES ('', '$getuser', '$email', ...)`. Also, make sure you escape all the values with `mysql_real_escape_string`. – Barmar Mar 03 '15 at 09:01
  • @Barmar escape all the values with what ? i dont know what they mean – Fawn Frauscht Mar 03 '15 at 09:04
  • `$getuser = mysql_real_escape_string($_POST['user'])`;' – Barmar Mar 03 '15 at 09:07
  • See http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – Barmar Mar 03 '15 at 09:08
  • None of my comments are solutions to your problem, they're just suggestions for better coding. Make sure you have error reporting enabled, with `error_reporting(E_ALL);` at the beginning of the script. – Barmar Mar 03 '15 at 09:16
  • @Barmar...thank sir for trying to help me...and btw i saw this from a tutorial in youtube https://www.youtube.com/watch?v=Y2NYbEjTzE8&list=PLF99B82E8685AA149&index=13 – Fawn Frauscht Mar 03 '15 at 09:21
  • i followed everything and yet...poof :( – Fawn Frauscht Mar 03 '15 at 09:22
  • @Jordy i was getting the numrows==1 else error msg – Fawn Frauscht Mar 03 '15 at 09:30

3 Answers3

0

if you are submitting form at same page.

$form = "<form action='' method='post'>

try this..


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

instead of

if($_POST['registerbtn'])

and if your Connect.php and registration is in same folder then use require("Connect.php"); if outside the folder then give proper path


Parag Soni
  • 713
  • 7
  • 14
0

First of all, you need to check if the variables are set if not set them to "" except for registerbtn.

Like this:

<?php
if(isset($_POST['registerbtn']))
{
  ...

} else {
  $getuser = $getemail = $errormsg = "";
}





$form = "<form action='./register.php' method='post'>

<table>
<tr>
<td></td>
<td><font color='red'>$errormsg</font></td>
</tr>
</table>
<fieldset>
<legend>Account</legend>
<input type='text' name='user' size='15' value='$getuser'/>:Username<br/>
<input type='text' name='email' size='15'value='$getemail'>:Email<br/>
<input type='password' name='pass' size='15' value=''/>:Passcode<br/>
<input type='password' name='confirmation' size='15' value=''/>:Confirmation<br/>
<br/>
<input type='submit' name='registerbtn' value='EAT ME'/>
</fieldset>
</form>";
  echo "$form";

It should work provided there isn't any problem with the db part.

In the one of the if-conditionals viz:

if($numrows == 1){
}else
    $errormsg = "An Error Has Occurred. Account Not Processed";

This is not needed because the else of if($numrows == 0 ) takes care of it.

Vagabond
  • 877
  • 1
  • 10
  • 23
  • i tried deleting it...but whenever i submit it only displays a blank error query – Fawn Frauscht Mar 03 '15 at 09:26
  • @tramp....im not certain of what im even saying XD im so sorry...i found out that im also using 1pv6 the ::1 thing....along with 127.0.0.1 and localhost....does these mean anything? – Fawn Frauscht Mar 03 '15 at 10:10
  • 127.0.0.1 works the same as localhost... Get back to your question... What did it mean when you said "whenever i submit it only displays a blank error query "...?? – Vagabond Mar 03 '15 at 10:20
  • Ok... Let's try debugging... before the mysql insert try doing this `echo "INSERT INTO users VALUES('', '$getuser', '$getemail', '$getpass', '$date' )";`... Let me know the o/p... – Vagabond Mar 03 '15 at 10:24
  • uhm..i tried making a new one...from a new tutorial and he asked me to do this if (empty($_POST) === flase){ echo 'Form Submitted'; } it only displays a blank page – Fawn Frauscht Mar 03 '15 at 10:38
  • im gonna try what you suggested now – Fawn Frauscht Mar 03 '15 at 10:38
0

change <form action='./register.php' method='post'> to <form action='' method='post'> or <form action='#' method='post'>

Akshaya Moorthy
  • 309
  • 3
  • 11