Jump to content

Post Issues


Recommended Posts

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);
}

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...