amycoll Posted March 7, 2010 Share Posted March 7, 2010 Hi. Today I was about to code a page which will let you to go to another page ONLY if you have inserted correct code. Code is from database, mysql one, so this is how the "CODE" page looks like. First there is an PHP(html) page with form in which you insert the code, then submit button. Form action is this code under, which IDK if is correct. <?php $post = $_POST["id"]; $con = mysql_connect("localhost", "root", "ascent"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("trac", $con); $res = mysql_fetch_array(mysql_query("SELECT entry FROM extra")); if ($post == $res) { echo "Your code was correct, proceed?"; } if (empty($post)) { echo "You did NOT type Code."; } echo "$res"; mysql_close($con); ?> Hope ya got to understand what I said. Link to comment https://forums.phpfreaks.com/topic/194454-code-authentication-help/ Share on other sites More sharing options...
Anti-Moronic Posted March 7, 2010 Share Posted March 7, 2010 No, that's not correct. Your sql query is not making any checks. You need to use a WHERE clause. This should work better: <?php $post = $_POST["id"]; $con = mysql_connect("localhost", "root", "ascent"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("trac", $con); $post = mysql_real_escape_string($post); $res = mysql_query("SELECT entry FROM extra where entry='$post'"); if(mysql_num_rows($res)>0){ echo "Your code was correct, proceed?"; }else{ echo "You did NOT type Code."; } echo "$res"; ?> You don't need to use mysql_close - the connection will be closed automatically. Only the query is right - this is assuming you have already successfully connected to database host and selected the database. Link to comment https://forums.phpfreaks.com/topic/194454-code-authentication-help/#findComment-1022792 Share on other sites More sharing options...
amycoll Posted March 8, 2010 Author Share Posted March 8, 2010 Now this issue appears, ? "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wwwserver\www\www-wow\trac\check.php on line 47" LINE 47: if(mysql_num_rows($res)>0){ EDIT. Ok nevermind, I found problem, BUT. Now it says "You did NOT type Code. Resource id #4" This resource id is pissing me.. EDIT #2: That's fixed, it was ECHO $POST. Now if anyone can tell me how can I echo submit button that will proceed to tool.php ? And maybe that tool.php can't be accessed if you directly go on it? Link to comment https://forums.phpfreaks.com/topic/194454-code-authentication-help/#findComment-1022933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.