Jump to content

[SOLVED] Getting multiple fields into DB.


aztec

Recommended Posts

Hello

 

I am having a problem getting multiple fields posted from a form using PHP into a MYSQL database.

 

The following code will only allow me to input the first field, ie first_name into the database.

 

I do not get any errors and after I click submit the form regenerates but without informing me that a new person as been added.

 

Any help would be appreciated.

 

Kind Regards

 

 

 


<?php if (isset($_POST['first_name'])):
  $dbcnx = @mysql_connect('xxxxxx', 'yyyyyy', 'zzzzzz');
  if (!$dbcnx) {
    exit('<p>Unable to connect to the ' .
        'database server at this time.</p>');
  }

  if (!@mysql_select_db('xxxxxx')) {
    exit('<p>Unable to locate the xxxxxx ' .
        'database at this time.</p>');
  }

$first_name = $_POST['first_name'];  
  $second_name = $_POST['second_name'];
  $surname = $_POST['surname'];

  

$sql = "INSERT INTO QQQQQQ SET  		
      	first_name='$first_name',
      	second_name='$second_name',
      	surname = '$surname'”;

<?php else: // Allow the user to enter a new person ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<table> 
   
   <tr>  <!--<label>First Name:<input type="varchar" name="first_name" /></label><br />-->
     <td colspan="2" class="lablecell"><label>First Name</label></td> 
     <td colspan="2" class="fieldcell"> <input type="varchar" name="first_name" /></td> 
   </tr> 
   <tr>  
     <td colspan="2" class="lablecell"><label>Second Name</label></td> 
     <td colspan="2" class="fieldcell"> <input type="varchar" second_name="second_name" /></td> 
   </tr> 
   <tr>  
<td colspan="2" class="lablecell"><label>Surname</label></td> 
     <td colspan="2" class="fieldcell"> <input type="varchar" surname="surname" /></td> 
   </tr> 
   <tr>  
     <td colspan="2"><input type="submit" name="Submit" value="Submit"  /></td> 
   </tr> 
</table> 
</form>
     	<?php endif; ?>		

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.