Note that there are some explanatory texts on larger screens.

plurals
  1. POphp only writing some values into database
    primarykey
    data
    text
    <p>I am having an issue with my php not writing the values it is getting from my ajax script into my MySQL database. I know that the php script is getting the values because they are being echoed in my browser. but when i check my database, only two out of the five values are being inputted. I am sure this isn't a nuance, but I can't seem to crack this. </p> <p><strong>==============EDIT=============</strong></p> <p>The values that aren't being written are first name, last name, and job. ($fname, $lname, and $job respectively)</p> <p><strong>==============EDIT=============</strong></p> <p><strong>PHP</strong></p> <pre><code>&lt;?php //db connecting variables $hostname = "foobase"; $username = "foobase"; $dbname = "contactformbase"; $password = "password"; $con = new mysqli($hostname, $username, $password, $dbname); $tbl_name = "client_base"; //Connecting to your database if ($con-&gt;connect_error) { die('Connect error (' . mysqli_connect_errno() . ')' . mysqli_connect_errno()); } echo 'success!...' . $con-&gt;host_info . "\n"; print_r($_POST); $fname = $_POST['fname']; $lname = $_POST['lname']; $email = $_POST['email']; $address = $_POST['address']; $job = $_POST['job']; $message = $_POST['message']; //adding values into the database. $sql="INSERT INTO $tbl_name (First Name, Last Name, Email, Address, Job)VALUES('POST_['first_name']', '$lname', '$address', '$email')"; $result = mysqli_query($con, $sql); if($result){ echo "success"; } else { echo "error"; } </code></pre> <p><strong>Javascript</strong></p> <pre><code>&lt;script type="text/javascript"&gt; $("#submit").click(function(e) { e.preventDefault(); var data_string = $("form#contact").serializeArray(); alert(data_string); $.ajax({ type: "POST", url: "database.php", data: data_string, success: function(){ alert(data_string); } }); return false; &lt;/script&gt; </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;form action="" method="POST" id="contact"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;h2&gt;First Name: &lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;Last Name: &lt;/td&gt; &lt;td&gt;&lt;h2&gt;Email Address: &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" name="first_name" placeholder="Johnny"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="last_name" placeholder="Appleseed"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="email" placeholder="johnny@email.com"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;h2&gt;Street Address:&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;What's Dirty?&lt;/h2&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" name="address" placeholder="123 Applegrove Rd. Appletown, VA 12345"&gt;&lt;/td&gt; &lt;td&gt; &lt;select name="job" form="contact"&gt; &lt;option value="house"&gt;House&lt;/option&gt; &lt;option value="roof"&gt;Roof&lt;/option&gt; &lt;option value="garage-shed"&gt;Garage/shed&lt;/option&gt; &lt;option value="other"&gt;Other&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;h2&gt;Message: &lt;/h2&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;textarea name="message"&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload