Note that there are some explanatory texts on larger screens.

plurals
  1. PONo values being sent to my php script from ajax
    text
    copied!<p>Alright, so I am trying to make a [relatively] simple contact form that uses ajax and php to write that data into a database once the form is submitted. I don't get any errors in my javascript or my php but the problem seems to lie within the php not receiving the data that ajax is sending. <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"&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" cols="80" rows="5"&gt;&lt;/textarea&gt; &lt;input type="submit" id="submit" name="send" value="Send!" class="send-button"&gt; &lt;/form&gt; </code></pre> <p><strong>Javascript</strong></p> <pre><code>&lt;script type="text/javascript"&gt; $("#submit").click(function() { var data_string = $("#contact").serialize(); $.ajax({ type: "POST", url: "database.php", data: data_string, success: function(){ alert(data_string); } }); }); &lt;/script&gt; </code></pre> <p><strong>PHP/MySQL</strong></p> <pre><code>&lt;?php $hostname = "foobase.db.9999.foobase.com"; $username = "foobase"; $dbname = "foobase"; $password = "password"; $con =mysqli_connect($hostname, $username, $password); //Connecting to database mysqli_connect($hostname, $username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysqli_select_db($con, $dbname); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else { echo "success!"; } //adding values into the database. $fname = $_POST['fname']; $lname = $_POST['lname']; $wholename = $fname . " " . $lname; $email = $_POST['email']; $address = $_POST['address']; $job = $_POST['job']; $message = $_POST['message']; mysqli_query($con, "INSERT INTO client_base (Name, Email, Address, Job)VALUES ('$wholename', '$email', '$address', '$job')"); </code></pre>
 

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