1

Alright so knocking some issues out one by one, now I am trying to get my dropdown menu data to submit. I don't know where to start with this one though.

here's my form.. anything wrong here? :

<form action="form.php" method="POST"> 

<div class="row"> 
<div class="large-4 columns"> 


<span id="spryfirstname">
<input name="firstname" type="text" placeholder="First Name"/>
<span class="textfieldRequiredMsg">A value is required.</span></span></div> 

<div class="large-4 columns"> 

<span id="sprylastname">
<input name="lastname" type="text" placeholder="Last Name"/>
<span class="textfieldRequiredMsg">A value is required.</span></span></div>

 <div class="large-4 columns">
  <div class="row collapse"> 

   <div class="small-9 columns"><span id="spryemail">
     <input name="email" type="text" placeholder="[email protected]"/>
    <span class="textfieldRequiredMsg">A value is required.</span></span></div>
  </div> 
      </div> 
      </div>

 <div class="row">
           <div class="large-12 columns">
           <label>Check all Products that you're interested in</label>

         <input name="products[]" type="checkbox" value="all">
           ALL PRODUCTS/SERVICES
          <input name="products[]" type="checkbox" vallue="trade">Trade-in
          <input name="products[]" type="checkbox" value="layaway">Layaway products
          <input name="products[]" type="checkbox" value="theatre">Home Theatre Systems
          <input name="products[]" type="checkbox" value="TV">HD TVs
          <input name="products[]" type="checkbox" value="Games">Video Game Consoles<br>
           <input name="products[]" type="checkbox" value="laptops"> Laptops
           <input name="products[]" type="checkbox" value="monitors"> Monitors
           <input name="products[]" type="checkbox" value="phones"> Phones
           <input name="products[]" type="checkbox" value="cameras"> Cameras
           <input name="products[]" type="checkbox" value="acoustic"> Acoustic Guitars
           <input name="products[]" type="checkbox" value="electric"> Electric Guitars
           <input name="products[]" type="checkbox" value="drums"> Drums
           <input name="products[]" type="checkbox" value="wind"> Wind Instruments <br>
           <input name="products[]" type="checkbox" value="pianos"> Pianos
           <input name="products[]" type="checkbox" value="violins"> Violins
           <input name="products[]" type="checkbox" value="diamonds"> Diamonds 
           <input name="products[]" type="checkbox" value="neck"> Necklaces
           <input name="products[]" type="checkbox" value="rings"> Rings
           <input name="products[]" type="checkbox" value="ear"> Ear Rings
           <input name="products[]" type="checkbox" value="gold"> Gold Jewelry
           <input name="products[]" type="checkbox" value="silver"> Silver Jewelry
                 <hr>

              </div>
              </div>
       <div class="row">
        <div class="large-12 columns">
         <label>How often would you like to have product updates? <select>
          <option value="daily" name="Updates">Daily</option>
          <option value="weekly" name="Updates">Weekly</option>
           <option value="monthly" name="Updates">Monthly</option>
             </select> 
             </label>
              </div> 
              </div>
                   <div class="row">
                   <div class="large-12 columns">
             <label>Tell us a little about yourself <textarea placeholder="Type here">
                    </textarea> 
                     </label>
                      </div> 
                      </div> 
                       <div class="row">

                <input class="button small large-3" type="submit" name="submit" />
                             </div>
                             </form>

Here is my connection to the database/php:

<?php
if(isset($_POST['submit'])){
$con = mysqli_connect("localhost","dxh6110","tcqfoz7","dxh6110") 
   or die("Error " . mysqli_error($con)); 

$first = stripslashes($_POST['firstname']);
$last = stripslashes($_POST['lastname']);
$email = stripslashes($_POST['email']);
$checkbox = stripslashes($_POST['products']);

$first = mysqli_real_escape_string($con,$_POST['firstname']);
$last = mysqli_real_escape_string($con,$_POST['lastname']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$checkbox = mysqli_real_escape_string($con,$_POST['products']);

$checkbox = implode(',', $_POST['products']);


$sql = "INSERT INTO Register (Firstname,Lastname,Email,Product)  
    VALUES('".$firstname."','".$lastname."','".$email."','".$checkbox."')";
}

mysqli_query($con,$sql);
mysqli_close($con);

?>
2
  • 1
    So what do you get in $_POST after submission and what does $sql looks like after adding in parameters? Commented Dec 8, 2014 at 6:34
  • thank you for the post, Nate Nevins figured out what my issue was! if(isset($_Post['submit'])){} needed to be there! Commented Dec 8, 2014 at 7:16

2 Answers 2

2

Well, part of your problem is that every time you visit the page, it will add another row. regardless of a submit or not so add this:

if(isset($_POST['Submit'])){
}

just wrap that around all the php you go there ^.^ so go ahead and delete all the blank rows it got ya and try again. That way you can debug it a little bit better.

So this explains the blank row problem you are having. ;) what of the 3 are not going through?

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, so do I put the if(isset($_POST['submit'])){ } around everything? Where I define my variables and then after the $sql insert? I figured out the 3 issue. My variables weren't the same.. $firstname =/= $first and $lastname =/= $last but $email was working just fine
yep, just go ahead and wrap all your current php the if(isset($_POST['Submit'])){ php stuff } anything outside of it is if you want to display or do something before the submit happens
Yes sir, that fixed my issue with the double entry. thank you sir!! i'm wondering though... maybe you can help me with this also.... I'm trying to get my checkboxes into my database...and my dropdown menu i'm not sure where to start... i'm going to edit my main post
Perfect, no problem! Just let me know if you have any other php/mysql problems. Happy to help!
welp actually I have found out the issue for checkboxes! yay!!!! I needed to have $checkbox = implode(',', $_POST['products']);
0

Welp I have figured my issues out. Thanks all for helping.

Basically when I first posted my issue it was 1 of 3 fields were being submitted to my DB the reason for this was because my variables were not the same I had it out like this and also I was getting double entries... 1 blank entry and another with the 1 of 3 entries:

$first = stripslashes($_POST['firstname']);
$last = stripslashes($_POST['lastname']);
$email = stripslashes($_POST['email']);


$first = mysqli_real_escape_string($con,$_POST['firstname']);
$last = mysqli_real_escape_string($con,$_POST['lastname']);
$email = mysqli_real_escape_string($con,$_POST['email']);








$sql = "INSERT INTO Register (First,Last,Email,Product,Updates)  
    VALUES('".$firstname."','".$lastname."','".$email."');
 }

$first did not equal $firstname, $last did not equal $lastname $email did equal $email.... so only 1 of 3 were being submitted to the db.

after this issue i didn't know how to add checkboxes and dropdown data... this is what I did to change it and also the double entries (1 blank) thanks to Nate Nevins.

if(isset($_POST['submit'])){
$con = mysqli_connect("localhost","dxh6110","tcqfoz7","dxh6110") 
   or die("Error " . mysqli_error($con)); 


$first = stripslashes($_POST['firstname']);
$last = stripslashes($_POST['lastname']);
$email = stripslashes($_POST['email']);
$checkbox = stripslashes($_POST['products']);
$update = stripslashes($_POST['updates']);

$first = mysqli_real_escape_string($con,$_POST['firstname']);
$last = mysqli_real_escape_string($con,$_POST['lastname']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$checkbox = mysqli_real_escape_string($con,$_POST['products']);
$checkbox = mysqli_real_escape_string($con,$_POST['updates']);

$checkbox = implode(',', $_POST['products']);






$sql = "INSERT INTO Register (First,Last,Email,Product,Updates)  
    VALUES('".$first."','".$last."','".$email."','".$checkbox."','".$update."')";
  }

mysqli_query($con,$sql);
mysqli_close($con);

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.