bgearig Posted February 1, 2010 Share Posted February 1, 2010 I am using AJAX to send form information to a PHP script for a database transaction. The transaction is successful, but now I am "proof-reading" the information sent to prevent certain information from being sent to the script, such as empty strings or strings with JUST SPACES. The Javascript is as follows: function foo(form_name) { if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","./bar.php?action=add&value="+escape(document.forms[form_name].some_select_menu.value)+"|"+escape(document.forms[form_name].some_text_box.value)+"&rand="+Math.floor(Math.random()*1001),false); xmlhttp.send(null); if (xmlhttp.responseText == "0") { alert("Error inserting into Database. Please check your entry!"); } else { alert("Success! "+xmlhttp.responseText); document.forms[form_name].some_text_box.value = ""; reload_select_menu(form_name); } } The bar.php file contains the following relevant function: elseif ($_GET['action'] == "add") { $temp = explode("|",urldecode($_GET['value'])); if (trim($temp[1]) != "" || $temp[1] != NULL) { some_sql_query(); echo("1"); } else { echo("0"); } } So when I send the information with nothing in the textbox, I get the proper error message, "Error inserting into Database. Please check your entry!". However, when I just place a space in the textbox and submit that, I receive the message "Success! 1". What should I be checking in the if statement differently? Link to comment https://forums.phpfreaks.com/topic/190526-need-help-checking-_get-variable-reference-code-included/ Share on other sites More sharing options...
bgearig Posted February 1, 2010 Author Share Posted February 1, 2010 Oh dear... Maybe someone should add to the guidelines to drink your morning coffee before asking dumb questions. I will answer my own question. Hey bgearig! You should try changing || to && and finish your morning coffee! Thanks Link to comment https://forums.phpfreaks.com/topic/190526-need-help-checking-_get-variable-reference-code-included/#findComment-1004971 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.