Jump to content

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.

 

 

<?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>
<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/90087-solved-posting-multiple-fields-using-php/
Share on other sites

Hello

 

Sorry the info is cryptic but I was having problems getting a preview.

 

The form is styled using an external CCS script.

 

I have been trying to get by this problem for some time now, I think it needs a new pair of eyes to spot the error.

 

Kind Regards

Hello Barand

 

I thought that each field type had to match the field type in the database, how wrong I was.

 

Thanks very much for setting me right, I changed everything to name and all 23 fields on the actual database were input correctly.

 

The problem is now solved

 

Kind Regards

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.