Registration form


Joined
Jun 14, 2018
Messages
22
Reaction score
0
hi all basically i'm making a php and sql registration form?

and i'm getting this error $p2 = $_POST['p2'];

my code is this


PHP:
<?php
$error = NULL;

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

    //Get form data
    
    $u = $_POST['u'];
    $p = $_POST['p'];
    $p2 = $_POST['p2'];
    $e = $_POST['e'];
    
    
    
    
    if(strlen($u) < 5){
        $error = "<p>Your username must be at least 5 characters</p>";
    }elseif($p2 != $p){
        $error .= "<p>Your passwords do not match</p>";   
    }else{
        //Form is valid
        
        //Connect to the database
        $mysqli = NEW MYSQLi('localhost','root','','profiles');
        
        //Sanitize form data
        $u = $mysqli->real_escape_string($u);
        $p = $mysqli->real_escape_string($p);
        $p2 = $mysqli->real_escape_string($p2);
        $e = $mysqli->real_escape_string($e);

        //Generate Vkey
        $vkey = md5(time().$u);
        
        //insert account into the database
        $p = md5($p);
        $insert = $mysqli->query("INSERT INTO accounts(usname,password,email,vkey)
        VALUES('$u','$p','$e','$vkey')");
        
        if($insert){
            echo "Success";
        }else{
            
        }
        
        
    }
}   
        

?>
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<form method="POST" action="">
  <table border="0" align="center" cellpadding="5">
  <tr>
 
    <td align="right">Username:</td>
    <td><input type="TEXT" name="u" required/></td>
  </tr>
  <tr>
    <td align="right">Password:</td>
    <td><input type="PASSWORD" name="p" required/></td>
  </tr>
  <tr>
    <td align="right">Repeat Password:</td>
    <td><input type="REPEATPASSWORD" name="r" required/></td>
  </tr>
  <tr>
  <td align="right">Email Address:</td>
    <td><input type="EMAIL" name="e" required/></td>
  </tr>
  <tr>
 
  <tr>
 
    <td colspan="2" align="center"><input type="SUBMIT" name="submit" value="Register" required/></td>
  </tr>
</table>
</form>
<center>
 <?php
$error = NULL;
?>
</center>
</body>
</html>

i have tried and tried to search the error but can't find any answers to it
 
Ad

Advertisements

Joined
Nov 13, 2020
Messages
48
Reaction score
8
i'm getting this error $p2 = $_POST['p2'];
That is not an error code, it's the third line of collecting data from your form. Your PHP code has a problem with that statement.
You should do a test and print the '$p' and '$p2'. If you still get an error research the correct one and not $p2 = $_POST['p2'];
 
Joined
Jun 14, 2018
Messages
22
Reaction score
0
That is not an error code, it's the third line of collecting data from your form. Your PHP code has a problem with that statement.
You should do a test and print the '$p' and '$p2'. If you still get an error research the correct one and not $p2 = $_POST['p2'];
funny! i register my username and i get and error over here http://coolvibes.hopto.org/loginnew/register.php
error Notice: Undefined index: p2 in C:\wamp64\www\loginnew\register.php on line 10
 
Joined
Jun 14, 2018
Messages
22
Reaction score
0
Please post the form that is calling this php file.
here is the register form. but when i go to try and do a test register the test username
don't show up in phpmyadmin? anyway check out the code, by the way everything is in this file .
 

Attachments

  • register - Copy.zip
    937 bytes · Views: 14
Ad

Advertisements

Joined
Nov 13, 2020
Messages
48
Reaction score
8
If your running this as a single file that's what happens, because the first time through you haven't defined those. Set the PHP as a separate file and call it from the HTML form.
 
Joined
Jun 14, 2018
Messages
22
Reaction score
0
If your running this as a single file that's what happens, because the first time through you haven't defined those. Set the PHP as a separate file and call it from the HTML form.
ok i have started on another project rite this time im making a profile system
but i am getting an error Parse error: syntax error, unexpected '}' in C:\wamp64\www\test\profile.php on line 37
 

Attachments

  • profile - Copy.zip
    900 bytes · Views: 12
Joined
Nov 13, 2020
Messages
48
Reaction score
8
strawbs you allways need to be mindful that PHP run at the server and HTML runs in the browser. This file will not run as you want. This line:
<title><?php echo $firstname; ?> <?php echo $lastname; ?>s Profile</title>
Needs to know $firstname and $lastname which is not known until line 17 and 18:
Code:
while($row = mysqli_fetch_array($userquery, MYSQLI_ASSOC)){
    $firstname = $row['firstname'];
    $lastname = $row['lastname'];

Your error is caused by a missing ; at the end of line 36.
You'll get more errors in the table because of this:
<? php echo $firstname: ?>
in all rows. Notice the space after the ?. Should be <?php

FYI -> Back in ver 5.4 of PHP a short hand way of writing <?php echo was introduced <?= Easier right?
 
Ad

Advertisements

Joined
Jun 14, 2018
Messages
22
Reaction score
0
strawbs you allways need to be mindful that PHP run at the server and HTML runs in the browser. This file will not run as you want. This line:
<title><?php echo $firstname; ?> <?php echo $lastname; ?>s Profile</title>
Needs to know $firstname and $lastname which is not known until line 17 and 18:
Code:
while($row = mysqli_fetch_array($userquery, MYSQLI_ASSOC)){
    $firstname = $row['firstname'];
    $lastname = $row['lastname'];

Your error is caused by a missing ; at the end of line 36.
You'll get more errors in the table because of this:
<? php echo $firstname: ?>
in all rows. Notice the space after the ?. Should be <?php

FYI -> Back in ver 5.4 of PHP a short hand way of writing <?php echo was introduced <?= Easier right?
im getting error on line 9 syntax error unexpected if
 
Joined
Nov 13, 2020
Messages
48
Reaction score
8
Have you never been taught to troubleshoot strawbs?

If you read my last post you made a new program, you did re-program right, because I told you you fetch data in the wrong place. So post both the calling form and new form you just re-wrote.
 
Ad

Advertisements

Joined
Jun 14, 2018
Messages
22
Reaction score
0
Have you never been taught to troubleshoot strawbs?

If you read my last post you made a new program, you did re-program right, because I told you you fetch data in the wrong place. So post both the calling form and new form you just re-wrote
Have you never been taught to troubleshoot strawbs?

If you read my last post you made a new program, you did re-program right, because I told you you fetch data in the wrong place. So post both the calling form and new form you just re-wrote.
i do try and troubleshoot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top