Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting a Database for TRUE/FALSE using AJAX/PHP/SQL
    primarykey
    data
    text
    <p>Let me begin with stating that you are about to see that I am still using some Mysql code in this question. It is only because I am new to PDO and in an effort to troubleshoot, I wanted to make sure my sql and queries were working so I went with what I know. Once I get the function working and the scripts running, I will convert to PDO.</p> <p>Heres the question I have. I am submitting a form that subscribes a user to a email list (database). It takes all their info and inserts it into a DB. So far this all works. My Call back function is then supposed to check to see if this user was already in the DB or not. </p> <p>I was testing to see if a row got returned from the DB based off of the email column being set as a unique column. The problem is that even though the user is already in the DB, the sql returns a line saying "Duplicate entry", so my code is reading the line DUPLICATE ENTRY as a result. Can someone point me in the right direction? </p> <p>My jQuery code...</p> <pre><code>$('#contForm').submit(function() { //contForm is the name of my form var formData = $(this).serialize(); $.post('contact.php',formData,dispAdd); //dispAdd is the callback function dispAdd(result) { if (!result) { $('#main').html('&lt;div&gt;Your have been added to the mailing list&lt;/div&gt;'); } else { if ($('#fail').length==0) { $('#main').append('&lt;div id="fail"&gt;This email address is already subscribed to our mailing list&lt;/div&gt;'); } } } return false; }); </code></pre> <p>My PHP/SQL script</p> <pre><code>function dispAdd() { $email= $_POST['email']; $sql= "SELECT * FROM mailList WHERE email = '$email'"; $result= mysql_query($sql) or die(mysql_error()); $rows = array(); if(mysql_num_rows($result) &gt; 0) { while ( $row = mysql_fetch_assoc($result)) { $rows[] = $row; } echo json_encode( $rows ); } </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.
    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