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
https://forums.phpfreaks.com/topic/90098-solved-getting-multiple-fields-into-db/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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