0

My form connects and inserts to my database just fine--except none of the values of the form are inserted. It's all blank. Please take a look at my code and see if there is anything I'm missing. I don't remember changing anything that would make this happen. I'll only include the form area (which I think is relevant. If that looks fine, I'll include more that may be affecting it. THANKS!

(edited with PHP and Html changes as they are suggested)

PHP

<?php

     $link = mysqli_connect("localhost","eativft2_steven","sgmexican", "eativft2_artistsdb");


array_walk_recursive( $_POST, 'mysqli_real_escape_string' );

$Fname = $_POST['Fname'];

$Lname = $_POST['Lname'];

$Website = $_POST['Website'];

    $Phone = $_POST['Phone'];

$Email = $_POST['Email'];

$Interests1 = $_POST['Interests1'];

    $Interests2 = $_POST['Interests2'];

$Interests3 = $_POST['Interests3'];

$PersonalStatement = $_POST['PersonalStatement'];


if($link === false){

    die("ERROR: Could not connect. " . mysqli_connect_error());

}

$result = mysqli_query($link,"INSERT INTO User (Fname, Lname, Website, Phone, Email, Interest1, Interest2, Interest3, PersonalStatement) VALUES('$Fname', '$Lname', '$Website', '$Phone', '$Email', '$Interests1', '$Interests2', '$Interests3', '$PersonalStatement')");

if(!$result){

  echo "ERROR: Could not execute $result. " . mysqli_error($link);

} else{

            echo "<h2>We got you.</h2>";

}


mysqli_close($link);

?>

HTML

<div class="modal-box" id="modal-box">

  <div class="modal-content">
    <span class="close"> X </span>

     <h2 id="modal-title">Create a profile</h2>
<form action="/Collaborate/indexxx.php" method="post" name="User">

  <label for="Fname">FIRST NAME</label><br>
  <input type="text" name="Fname" placeholder="first name" required> <br>

  <label for="Lname">LAST NAME</label><br>
  <input type="text" name="Lname" placeholder="last name" required> <br>

  <label for="Website">WEBSITE URL</label><br>
  <input type="text" name="Website" placeholder="show your work" required> <br>

  <label for="Phone">PHONE NUMBER</label><br>
  <input type="text" name="Phone" placeholder="1234567890" required> <br>

  <label for="Email">EMAIL ADDRESS</label><br>
  <input type="text" name="Email" placeholder="you@awesome.com" required><br>

      <label for="Interests1">INTERESTS</label><br>
      <select class="Interest1" id="Interests1" name="Interests1">
    <optgroup label="Audio">
        <option>ADR</option>
        <option>Audio Post</option>
        <option>Composer</option>
        <option>Electrician</option>
   <option>Foley</option>
        <option>Mixer</option>
        <option>On-Set</option>
        <option>Sound Design</option>
        <option>Studio</option>
        <option>Learning Audio</option>
</optgroup>
    <optgroup label="Animation">
    <option>Modeling</option>
    <option>Motion</option>
    <option>Lighting</option>
    <option>Backgrounds</option>
    <option>Learning Animation</option>
</optgroup>
<optgroup label="Culinary">
    <option>Baker</option>
    <option>Catering</option>
    <option>Cuisine (specify)</option>
    <option>Management</option>
    <option>Learning Culinary</option>
</optgroup>
<optgroup label="Fashion">
    <option>Costume</option>
    <option>Design</option>
    <option>Marketing</option>
    <option>Tailor</option>
    <option>Wardrobe</option>
    <option>Learning Fashion</option>
</optgroup>
<optgroup label="Gaming">
    <option>3D Artist</option>
    <option>Animator</option>
    <option>Art Director</option>
    <option>Concept Artist</option>
    <option>Environment Artist</option>
    <option>Game Tester</option>
    <option>Modeler</option>
    <option>Motion Capture</option>
    <option>Project Manager</option>
    <option>Programmer</option>
    <option>UI Artist</option>
    <option>Learning Gaming</option>
</optgroup>
<optgroup label="Industrial Design">
    <option>Product</option>
    <option>Learning Industrial Design</option>
</optgroup>
<optgroup label="Interior Design">
    <option>Commercial</option>
    <option>Drafting</option>
    <option>Environment</option>
    <option>Hospitality</option>
    <option>Institution</option>
    <option>Residential</option>
    <option>Learning Interior Design</option>
</optgroup>
<optgroup label="Photo">
    <option>Commercial</option>
    <option>Event</option>
    <option>Fashion</option>
    <option>Narrative</option>
    <option>Nature</option>
    <option>Real Estate</option>
    <option>Sports</option>
    <option>Wedding</option>
    <option>Learning Photo</option>
</optgroup>
<optgroup label="Video">
    <option>Cinematography</option>
    <option>Director</option>
    <option>Editor</option>
    <option>Producer</option>
    <option>Production Assistant</option>
    <option>Scriptwriter</option>
    <option>Learning Video</option>
</optgroup>
<optgroup label="Web Design">
    <option>Developing</option>
    <option>Interface</option>
    <option>Typography</option>
    <option>User Experience</option>
    <option>Learning Web Design</option>
</optgroup>
      </select>
      <label for="Interests2">INTERESTS</label><br>
      <select class="Interest2" id="Interests2" name="Interests2">
    <optgroup label="Audio">
        <option>ADR</option>
        <option>Audio Post</option>
        <option>Composer</option>
        <option>Electrician</option>
   <option>Foley</option>
        <option>Mixer</option>
        <option>On-Set</option>
        <option>Sound Design</option>
        <option>Studio</option>
        <option>Learning Audio</option>
</optgroup>
    <optgroup label="Animation">
    <option>Modeling</option>
    <option>Motion</option>
    <option>Lighting</option>
    <option>Backgrounds</option>
    <option>Learning Animation</option>
</optgroup>
<optgroup label="Culinary">
    <option>Baker</option>
    <option>Catering</option>
    <option>Cuisine (specify)</option>
    <option>Management</option>
    <option>Learning Culinary</option>
</optgroup>
<optgroup label="Fashion">
    <option>Costume</option>
    <option>Design</option>
    <option>Marketing</option>
    <option>Tailor</option>
    <option>Wardrobe</option>
    <option>Learning Fashion</option>
</optgroup>
<optgroup label="Gaming">
    <option>3D Artist</option>
    <option>Animator</option>
    <option>Art Director</option>
    <option>Concept Artist</option>
    <option>Environment Artist</option>
    <option>Game Tester</option>
    <option>Modeler</option>
    <option>Motion Capture</option>
    <option>Project Manager</option>
    <option>Programmer</option>
    <option>UI Artist</option>
    <option>Learning Gaming</option>
</optgroup>
<optgroup label="Industrial Design">
    <option>Product</option>
    <option>Learning Industrial Design</option>
</optgroup>
<optgroup label="Interior Design">
    <option>Commercial</option>
    <option>Drafting</option>
    <option>Environment</option>
    <option>Hospitality</option>
    <option>Institution</option>
    <option>Residential</option>
    <option>Learning Interior Design</option>
</optgroup>
<optgroup label="Photo">
    <option>Commercial</option>
    <option>Event</option>
    <option>Fashion</option>
    <option>Narrative</option>
    <option>Nature</option>
    <option>Real Estate</option>
    <option>Sports</option>
    <option>Wedding</option>
    <option>Learning Photo</option>
</optgroup>
<optgroup label="Video">
    <option>Cinematography</option>
    <option>Director</option>
    <option>Editor</option>
    <option>Producer</option>
    <option>Production Assistant</option>
    <option>Scriptwriter</option>
    <option>Learning Video</option>
</optgroup>
<optgroup label="Web Design">
    <option>Developing</option>
    <option>Interface</option>
    <option>Typography</option>
    <option>User Experience</option>
    <option>Learning Web Design</option>
</optgroup>
      </select>
      <label for="Interests3">INTERESTS</label><br>
      <select class="Interest3" id="Interests3" name="Interests3">
    <optgroup label="Audio">
        <option>ADR</option>
        <option>Audio Post</option>
        <option>Composer</option>
        <option>Electrician</option>
   <option>Foley</option>
        <option>Mixer</option>
        <option>On-Set</option>
        <option>Sound Design</option>
        <option>Studio</option>
        <option>Learning Audio</option>
</optgroup>
    <optgroup label="Animation">
    <option>Modeling</option>
    <option>Motion</option>
    <option>Lighting</option>
    <option>Backgrounds</option>
    <option>Learning Animation</option>
</optgroup>
<optgroup label="Culinary">
    <option>Baker</option>
    <option>Catering</option>
    <option>Cuisine (specify)</option>
    <option>Management</option>
    <option>Learning Culinary</option>
</optgroup>
<optgroup label="Fashion">
    <option>Costume</option>
    <option>Design</option>
    <option>Marketing</option>
    <option>Tailor</option>
    <option>Wardrobe</option>
    <option>Learning Fashion</option>
</optgroup>
<optgroup label="Gaming">
    <option>3D Artist</option>
    <option>Animator</option>
    <option>Art Director</option>
    <option>Concept Artist</option>
    <option>Environment Artist</option>
    <option>Game Tester</option>
    <option>Modeler</option>
    <option>Motion Capture</option>
    <option>Project Manager</option>
    <option>Programmer</option>
    <option>UI Artist</option>
    <option>Learning Gaming</option>
</optgroup>
<optgroup label="Industrial Design">
    <option>Product</option>
    <option>Learning Industrial Design</option>
</optgroup>
<optgroup label="Interior Design">
    <option>Commercial</option>
    <option>Drafting</option>
    <option>Environment</option>
    <option>Hospitality</option>
    <option>Institution</option>
    <option>Residential</option>
    <option>Learning Interior Design</option>
</optgroup>
<optgroup label="Photo">
    <option>Commercial</option>
    <option>Event</option>
    <option>Fashion</option>
    <option>Narrative</option>
    <option>Nature</option>
    <option>Real Estate</option>
    <option>Sports</option>
    <option>Wedding</option>
    <option>Learning Photo</option>
</optgroup>
<optgroup label="Video">
    <option>Cinematography</option>
    <option>Director</option>
    <option>Editor</option>
    <option>Producer</option>
    <option>Production Assistant</option>
    <option>Scriptwriter</option>
    <option>Learning Video</option>
</optgroup>
<optgroup label="Web Design">
    <option>Developing</option>
    <option>Interface</option>
    <option>Typography</option>
    <option>User Experience</option>
    <option>Learning Web Design</option>
</optgroup>
      </select>
<br>
      <label for="PersonalStatement">PERSONAL STATEMENT</label><br>
      <textarea name="PersonalStatement" id="PersonalStatement" minlength="800" maxlength="1500" rows="5" cols="20" placeholder="Let us get to know you better." required></textarea><br />

      <button id="submit" name="submit"> Submit my profile </button>
    </form>
  </div>

</div>
  • I recommend using prepared statements. – Universus May 08 '18 at 09:59
  • Did you try my answer @steven? – Himanshu Upadhyay May 08 '18 at 10:01
  • I've tried everyone's answers and nothing is working still. Even stranger--I can't insert into my database that often. I can send my form maybe once every 5 minutes (and yes, it still sends blank). I can run SQL in phpMyAdmin and insert just fine there... I use Bluehost if that matters at all (such as if there's any permissions I need to look at). – Steven Guerrero May 09 '18 at 09:05
  • Checked my error log--when I'm unable to submit the form too often, it's due to: [09-May-2018 08:21:30 UTC] PHP Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, null given in *****/*****/*****/Collaborate/indexxx.php on line 29 Line 29 is die("ERROR: Could not connect. " . mysqli_connect_error()); Hmm.... I'm at a loss... – Steven Guerrero May 09 '18 at 09:21

4 Answers4

1

Do not put ' for variables.

Check this:

$sql = "INSERT INTO User (Fname, Lname, Website, Phone, Email, Interest1, Interest2, Interest3, PersonalStatement) VALUES($Fname, $Lname, $Website, $Phone, $Email, $Interest1, $Interest2, $Interest3, $PersonalStatement)";
Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33
1

Expanding on Sohrab Yousefi's answer, you can shorten your code with recursively iterating on $_POST to use mysqli_real_escape_string().

array_walk_recursive( $_POST, 'mysqli_real_escape_string' );

See here for reference.

Hope this helps.

navidanindya
  • 158
  • 1
  • 6
0

First: The method mysqli_real_escape_string() get only one argument like this:

$Fname = mysqli_real_escape_string($_REQUEST['Fname']);

Second: Use $_POST instead of $_REQUEST. You can see the reason here.

Third: In your HTML, set property value="some value" for the elements <option> of the <select>.

Hope it will help you.

0

If anyone is like me and wanting to make their URL look pretty. Make sure NOT to do it with php files. Once I edited my .htaccess to not snip the .php, everything was working again. I don't know if changing form action to [file](without .php) would work. But I am not trying!