Jump to content

Recommended Posts

Posted

Basically I'm trying to create a new user and save the user=>pass pair and leaving apache to handle the login process, but I've run into a silly snag. The html has the user field as a required field, so for newuser.php to ever be called it has to have a value, it's not passing over into newuser.php though

 

create.htm:

<form id="new_user" method="post" action="newuser.php">
  <table>
   <tr>
 <td>
  <h2>Username:</h2>
 </td>
 <td>
  <input type="text" id="user" size="20" max="20" required="required">
 </td>
   </tr>
   <tr>
 <td>
  <h2>Password:</h2>
 </td>
 <td>
  <input type="text" id="pass" size="20" max="20" required="required">
 </td>
   </tr>
   <tr>
 <td>
  <h2>Contact Email:</h2>
 </td>
 <td>
  <input type="email" id="email" size="20" max="40" required="required">
 </td>
   </tr>
   <tr>
 <td>
  <h2>Retype Email:</h2>
 </td>
 <td>
  <input type="email" id="email2" size="20" max="40" required="required">	 
 </td>
   </tr>
   <tr>
 <td colspan="2">
  <h4>Additionally if you prefer contact through text messages provide your phone number and mobile carrier</h4><h5>(For US only)</h5>
 </td>
   </tr>
   <tr>
 <td>
  Phone:<input type="tel" id="tele">
 </td>
 <td>
  Carrier:<input type="text" size="20" id="carrier">
 </td>
   </tr>
   <tr>
 <td colspan="2">
  <h4>Finally please provide your birthdate to give a demographic statistic.</h4>
 </td>
   </tr>
   <tr>
 <td>
  <h2>Birthday</h2>
 </td>
 <td>
  <input type="date" id="bday">
 </td>
   </tr>
   <tr>
 <td colspan="2"><input type="submit">
   </tr>
  </table>
 </form>

 

newuser.php:

<?php
$user=$_POST['user'];
$pass=$_POST['pass'];
$email=$_POST['email'];
$email2=$_POST['email2'];
if($email==$email2){
if(isset($_POST['user'])){
$pass=crypt($pass);
$user=(string)$user;
$output = $user.":".$pass.$nl;
file_put_contents("passwd", $output, FILE_APPEND);
}

Posted

In the html input, you need to replace id with name.

The name attribute is used to fill the $_POST array when sending data from a form, not the id.

ID is used for style (CSS).

 

Also, it is best to use some validations in the PHP code on the input, since not all browsers support the required field.

See: http://www.w3schools.com/html5/att_input_required.asp

 

<html>
<form id="new_user" method="post" action="newuser.php">
  <table>
   <tr>
        <td>
         <h2>Username:</h2>
        </td>
        <td>
         <input type="text" name="user" size="20" max="20" required="required">
        </td>
   </tr>
   <tr>
        <td>
         <h2>Password:</h2>
        </td>
        <td>
         <input type="text" name="pass" size="20" max="20" required="required">
        </td>
   </tr>
   <tr>
        <td>
         <h2>Contact Email:</h2>
        </td>
        <td>
         <input type="email" name="email" size="20" max="40" required="required">
        </td>
   </tr>
   <tr>
        <td>
         <h2>Retype Email:</h2>
        </td>
        <td>
         <input type="email" name="email2" size="20" max="40" required="required">        
        </td>
   </tr>
   <tr>
        <td colspan="2">
         <h4>Additionally if you prefer contact through text messages provide your phone number and mobile carrier</h4><h5>(For US only)</h5>
        </td>
   </tr>
   <tr>
        <td>
         Phone:<input type="tel" name="tele">
        </td>
        <td>
         Carrier:<input type="text" size="20" name="carrier">
        </td>
   </tr>
   <tr>
        <td colspan="2">
         <h4>Finally please provide your birthdate to give a demographic statistic.</h4>
        </td>
   </tr>
   <tr>
        <td>
         <h2>Birthday</h2>
        </td>
        <td>
         <input type="date" name="bday">
        </td>
   </tr>
   <tr>
        <td colspan="2"><input type="submit">
   </tr>
  </table>
 </form>
</html>

Posted

Oh, I was told they were interchangeable heh :/. Thanks for the clearing that up Tjoene

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...