scarhand Posted August 1, 2008 Share Posted August 1, 2008 im trying to get this code to, on form submission, check in a mysql database if their IP exists and then show a message under the submit button. if it exists, show a message under the submit button that says "you already reported this" if it doesnt exist, show a message that says "you havent reported this" heres what i have so far that doesnt work: the page with the form: <form method="post" onsubmit="sendReport(); return false;"> <input type="submit" value="Click here to report"> </form> <div id="reportmsg"></div> the javascript/ajax: function ajaxFunction() { var ajaxRequest; try { ajaxRequest = new XMLHttpRequest(); } catch (e) { try { ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { // browser does not support alert("Browser does not support Shoutbox requests."); return false; } } } return ajaxRequest; } function handleReportResponse() { if (htmlRequest.readyState==4 && htmlRequest.status==200) { document.getElementById("reportmsg").innerHTML = htmlRequest.responseText; } } function sendReport() { htmlRequest = ajaxFunction(); htmlRequest.open('POST', 'report.php'); htmlRequest.onreadystatechange = handleReportResponse; htmlRequest.send(null); } the php script: <?php include "connect.php"; // connect to the database $ip = $_SERVER["REMOTE_ADDR"]; $sql = mysql_query("SELECT * FROM reports WHERE ip='$ip'") $sql_count = mysql_num_rows($sql); if ($sql_count != 0) echo "You have already reported"; else echo "You have not reported"; ?> Quote Link to comment Share on other sites More sharing options...
scarhand Posted August 1, 2008 Author Share Posted August 1, 2008 nevermind i got it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.