webdogjcn Posted May 13, 2010 Share Posted May 13, 2010 I could just be over looking something incredibly simple here but im processing this form from one page: <form action="search_classes_process.php" method="post"> <input name="desc" type="hidden" value="number"> Unique KU Class Number: <input type="text" name="classid"><br> <input type="Submit" value="Search"> </form> NOTE: the purpose of the hidden input value is because there are several forms on this page all being processed through the same "search_classes_process.php" file. And the hidden value is to identify which form we are processing. Now on our "search_classes_process.php" file we have: mysql_select_db($database, $con); if ($_Post["desc"] == "number") { $query="Select KUclassID from classes where KUclassID='$_Post[number]'"; if ($query){ echo" Exists"; } else{ echo"DNE"; } } else { echo "error"; echo $_Post["desc"]; } Now Im not getting any PHP errors or anything. I have tried eliminating all the db checking and gone with simple isset($_Post["desc"]) checks and it isset but if i try echo $_Post["desc"]; I still get nothing. NOTE: I have tried changing the type of field out of hidden as well Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 It's spelled $_POST, not $_Post Ken Quote Link to comment Share on other sites More sharing options...
webdogjcn Posted May 13, 2010 Author Share Posted May 13, 2010 alright thanks i feel really dumb. One more question...This code is being used to search a database for specific entries so Im using this right now elseif ($_POST["desc"] == 'info') { $query=mysql_query("SELECT * from classes WHERE Category=$_POST[subject] && Number=$_POST[course]"); if (mysql_num_rows($query) > 0){ echo" Entry Found Redirecting to Class Page..."; } else{ header('Location: http://somesite.com/search_classes.php?error=dne'); } I search for values I know exist in the database and it still redirects me. If I eliminate the $_POST[subject] search however, it can find it. I think it has to do with the type of variables in the table. the $_POST[course] is an integer value in the table and I converted it early using if (isset($_POST["course"])) {$_POST["course"] = intval ($_POST["course"]);} //converts form value to integer however the Category field is classified as a VARCHAR string in the table. Could this be the reason why it cannot locate the entry? if so how do I convert a $_POST string to VARCHAR? or am I making another simple error Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted May 13, 2010 Share Posted May 13, 2010 Change your query to this and see what happens. "SELECT * FROM classes WHERE Category='" . $_POST['subject'] . "' AND Number= '" . $_POST['course'] . "'"; Quote Link to comment Share on other sites More sharing options...
webdogjcn Posted May 13, 2010 Author Share Posted May 13, 2010 tight. thanks guys Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 No, strings in PHP are fine as VARCHARs in MySQL. What you should do is enclose the value in quotes since it is a string and check if you're getting an error with the query. You also never trust user input. <?php $q = "SELECT * from classes WHERE Category='" . mysql_real_escape_string($_POST['subject']) . "' && Number=$_POST[course]"; $query = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); ?> Since Number is an integer, it doesn't need to be in quotes. Ken 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.