Note that there are some explanatory texts on larger screens.

plurals
  1. POsubmitting ajax form through php without results?
    primarykey
    data
    text
    <p>I've got a form that I'm trying to submit without a page refresh and as far as I can tell, everything on the jQuery side works (I mean the alert at the end of code went through, so I'm assuming everything is functioning as it should be) but since it's not actually showing up in the WAMPserver database, there must be a problem with my php code.</p> <p>Regardless, here is the important sections of the jquery code that show what is being submitted to the php page - and then the code for the php page where everything should be sent to the database.</p> <pre><code>//set form data to variable (including website) if(undefined != projectInfo &amp;&amp; typeof website != 'undefined' &amp;&amp; (website != 'http://' || website != '') &amp;&amp; null != website) { var dataString = 'name='+ name + '&amp;email=' + email + '&amp;website=' + website + '&amp;info=' + projectInfo; var radioType = $("input.radio1").val(); } //set form data to variable (excludes website) else { var dataString = "name=" + name + "&amp;email=" + email + "&amp;info=" + projectInfo; var radioType = $("input.radio1").val(); } //set form data to variable (including chat box) if(undefined != chitChat &amp;&amp; null != chitChat &amp;&amp; (chitChat !="what's on your mind?")) { var dataString = 'name='+ name + '&amp;email=' + email + '&amp;info=' + chitChat; var radioType = $("input.radio1").val(); } $.ajax ({ type: "POST", url: "process.php", data: dataString, success: function() { alert('success!'); } }); return false; </code></pre> <p>and then the php code:</p> <pre><code>&lt;?php // Create connection $con=mysqli_connect("localhost:3306","root","admin","test"); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } else { echo "Connection Successful!"; } ?&gt; &lt;?php # Variables for field names. $_name = $_POST['name']; $_email = $_POST['email']; $_request = $_POST['radioType']; $_website = $_POST['website']; if(empty $_POST['projectInfo']) { $_info = $_POST['chitChat']; } else { $_info = $_POST['projectInfo']; } # Inserting information into table. $sql = "INSERT INTO `contactform` (`name`,`email`,'request_type`,`website`,`info`) values (".$_name.",'".$_email.",'".$_request.",'".$_website.",'".$_info.")"; $query = mysql_query($sql); if (!$query) { echo "Failed " .mysql_error(); } else { echo "Data entered "; } ?&gt; </code></pre> <p>Now I'm not entirely certain on the php code (admittedly it's been a while since I've worked with php, so I'm very rusty) but I think my main issue is the if statement in the php code - I'm not sure if I'm even allowed to do that and when I check the php page itself (without submitting anything) I get these two errors:</p> <blockquote> <p>( ! ) SCREAM: Error suppression ignored for</p> <p>( ! ) Parse error: syntax error, unexpected '$_POST' (T_VARIABLE), expecting '(' in process.php on line 22</p> </blockquote> <p>I'm not entirely sure what the first means, but I'm guessing the second one does have to do with the if statmeent - though I can't for the life of me figure out what it's trying to say.</p> <p>I know this is a bit to take in, so I don't expect an answer soon, but any help would be appreciated, I'm willing to give as much extra code is needed.</p> <p>(for completion sake, here is a <a href="http://jsfiddle.net/xNFHp/" rel="nofollow">jsfiddle</a> containing all the code for the page itself)</p>
    singulars
    1. This table or related slice is empty.
    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.
    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