sqlnoob Posted March 22, 2008 Share Posted March 22, 2008 OK I got a problem with a password checking form on the same page. Either I'm not fetching the sql table right, or it's not getting the POST variable. Eitherway I'm supposed to get some data from an sql table or recieve a message that the password is incorrect. Instead I get nothing when I click the submit. I'm quite new at this, so any help is greatly appreciated. I've been trying to get it to work, by looking at tutorials and walkthroughs, but somehow none are helpful, so that's why I post here. I have a similar problem with another page, where it just don't seem to be displaying something where it should have. The first page, is the persona.php page with the problem I just described. The second page is one with a similar problem. I can use help with both. Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 22, 2008 Author Share Posted March 22, 2008 <HTML> <HEAD> <TITLE>Administrator Table</TITLE> <META NAME="keywords" CONTENT="administrator"> <style type="text/css"> h1,p {font-family: verdana;} h1,p {text-align: center} body {background-color: #32CD3E;} </style> </HEAD> <BODY><H1>Persons Table</H1> <P><A HREF="index.htm">return</A> <P> <?php if ("view" != $submit) { echo "<FORM method='Post' action='persona.php'> <INPUT type='password' size=5 maxlength=5 name='viewcheck'> <INPUT type='Submit' value='view' name='submit'> </FORM>"; } else { $passgood = "hello"; $passcheck = $_POST['viewcheck']; if ($passgood == $passcheck){ $con = mysql_connect("localhost","shugonl","password"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("shugonl", $con); $result = mysql_query("SELECT * FROM persons"); while($row = mysql_fetch_array($result)) { echo $row['Password'] . " " . $row['Clan'] . " " . $row['Username']; echo "<BR/>"; } } else { echo "incorrect password"; } } ?> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 22, 2008 Author Share Posted March 22, 2008 <HTML> <HEAD> <TITLE>actions</TITLE> <META NAME="keywords" CONTENT="economy"> <style type="text/css"> h1,h2,h3,p {font-family: verdana;} h1,h2,h3,p {text-align: center} body {background-color: #2F7B3A;} a:link {color: #80FFFF} a:visited {color: #FF80C0} a:hover {color: #FFFF80} a:active {color: #80FFFF} </style> </HEAD> <BODY><H1>Provincial survey</H1> <P> <?php $iprov = $_GET['province']; if(!filter_var($iprov, FILTER_VALIDATE_INT)) { echo("Integer is not valid"); } else { $con = mysql_connect("localhost","shugonl","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("shugonl", $con); $resultor = mysql_query ("SELECT * FROM provinces WHERE Identifier ='$iprov'"); $rower = mysql_fetch_array($resultor); echo "The province " .$rower['Province']. " is ruled by " .$rower['Owner']. "<BR>The castle is a " .$rower['Castle']. " and the terrain is " .$rower['Machi']; $rebi = $rower['Attitude']; $owni = $rower['Owner']; $dateresult = mysql_query ("SELECT Taxyear FROM persons WHERE Clan ='$owni'"); $daterow = mysql_fetch_assoc($dateresult); $taxdate = $daterow['Taxyear']; $thisdate = idate("d"); if ($taxdate == $thisdate) { if ($rebi < 4) {echo "<P>the province is peaceful";} else {echo "<P>the province is rebellious";} } else { $taxiresult = mysql_query ("SELECT Taxheight FROM persons WHERE Clan ='$owni'"); $taxirow = mysql_fetch_assoc($taxiresult); $taxi = $taxirow['Taxheight']; switch ($taxi) { case 5: $angi = 2; break; case 4: $angi = 1; break; case 1: $angi = -1; default: $angi = 0; } $newrebi = $rebi + $angi; mysql_query("UPDATE provinces SET Attitude ='$newrebi' WHERE Identifier ='$iprov'"); if (rebi == 4) {echo "<P>the province is rebellious";} elseif (rebi < 4) {echo "<P>the province is peaceful";} else { echo "<P>the province is lost to the rebels"; // time calculation als de datum elfde maart dit jaar is $century = mktime(1, 0, 0, 3, 11, 2008); $today = time(); $timedifference = $today - $century; $moddifference = floor($timedifference / 86400); $gameyear = $moddifference + 1477; $seasonal = idate("H"); if ($seasonal == 18 || 19 || 20 || 21 || 22 || 23) {$season = "WIN";} elseif ($seasonal == 11 || 12 || 13 || 14 || 15 || 16) {$season = "AUT";} elseif ($seasonal == 05 || 06 || 07 || 08 || 09 || 10) {$season = "SUM";} else {$season = "SPR";} mysql_query("UPDATE provinces SET Owner='rebels' WHERE Identifier='$iprov'"); $messi = $season . " " . $gameyear . " the province of " . $nomprov . " is lost to the rebels"; $countmess = "SELECT * FROM person"; $countresult = mysql_query($countmess); $mrows = mysql_num_rows($countresult); $nrows = $mrows + 1; mysql_query("INSERT INTO Adventures (MessageID, MessageText) VALUES ('$nrows', '$messi')"); } } } ?> </BODY> </HTML> Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 22, 2008 Author Share Posted March 22, 2008 oh before I forget to mention I use phpadmin as to ore my sql tables and the second page I get too from a page with an imagemap of Japan (if that's any help) and example link in the imagemap will look like this: <AREA SHAPE="circle" HREF="province.php?province=1" COORDS="542,353,7" ALT="Sado (Sado)"> Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 well I managed to solve the problem with the second page. Turns out the column name in the table was wrong. but the first page still doesn't work. No matter what I try it just doesn't work. It will not get the POST password after I submit it to itself. So please help if you can, cause I'm really stuck there. Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 It must be something really easy, but I just don't see what I'm doing wrong there :'( Quote Link to comment Share on other sites More sharing options...
Lamez Posted March 23, 2008 Share Posted March 23, 2008 add or die (mysql_error()); at the end of all your querys example: mysql_query("SELECT * FROM table") or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 OK did that but unfortunately that's not where the problem is, as it's not even displaying an error message when the password is wrong, even though it supposed to. the problem is somewhere in here: <BODY><H1>Persons Table</H1> <P><A HREF="index.htm">return</A> <P><FORM method="Post" action="persona.php"> <INPUT type="password" size=5 maxlength=5 name="viewcheck"> <INPUT type="Submit" value="view" name="submit"> </FORM> <P> <?php if ("view" != $submit) { echo "need to submit password to view the table"; } else { $passcheck = $_POST['viewcheck']; if ($passcheck == eling) { $con = mysql_connect("localhost","shugonl","wZ7cEBx6"); if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("shugonl", $con); $result = mysql_query("SELECT * FROM persons"); while($row = mysql_fetch_assoc($result)) { echo $row['Password'] . " " . $row['Clan'] . " " . $row['Username']; echo "<BR/>"; } } else { echo "incorrect password"; } } ?> Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 It just doesn't seem to be doing anything after i submit it to the same page, no matter how I try to code it. Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 Clearly I'm doing something wrong with the way I'm determining if the submit button has been clicked, or the way I'm submitting it to the same page. but what? ??? Quote Link to comment Share on other sites More sharing options...
janim Posted March 23, 2008 Share Posted March 23, 2008 sqlnoob i can\t figure out what is the problem exactly is it that your form dosent submitted at all or it submits but generate error ?? Quote Link to comment Share on other sites More sharing options...
niwa3836 Posted March 23, 2008 Share Posted March 23, 2008 Cant quite work out from your code what is going on, however where is my login.php code that works fine. This code is written for SQL2000 rather than mysql but I am sure you can sort that out. <?php require_once "./niwa-includes/functions001.inc"; /* ----------HTML START ----------- */ pageheader($dbname,$dbusername,$dbpassword) ; ?> <style type="text/css"> <!-- .style1 {font-family: Verdana, Arial, Helvetica, sans-serif} --> </style> <BODY BACKGROUND="2e2images/back1.gif"> <h3 class="style1">2e2 Deployment Tool: Login</h3> <?php if(isset($_POST['name'])) $name = $_POST['name'] ; else $name = '' ; if(isset($_POST['password'])) $password = $_POST['password']; else $password =''; if(isset($_GET['reason'])) $reason = $_GET['reason'] ; else $reason = '' ; if(isset($_GET['sid'])) $sid = $_GET['sid'] ; else $sid = '' ; if ($name && $password ) { $conn = odbc_connect($dbname,$dbusername,$dbpassword) ; if($conn) { $sql = "select name,password from niwausertable where name = '"; $sql .= $name ; $sql .= "'" ; //this function will execute the sql satament $result=odbc_exec($conn, $sql); if(odbc_num_fields($result) == 0) { print("No username found <br />\n") ; niwaWriteLog("User: " . $name . " attempt login but not found","General"); odbc_close ($conn); } else { odbc_fetch_row($result) ; if(odbc_result($result,1) == $name && odbc_result($result,2) == $password) { $sid = md5(date('c')) ; $sql = "update niwausertable set sid = '"; $sql .= $sid ; $sql .= "' where name = '" ; $sql .= $name ; $sql .= "'" ; odbc_exec($conn, $sql); odbc_close ($conn); niwaWriteLog("User: " . $name . " logged in","General"); // $URL = "http://172.30.1.12/deploymain.php?sid=" ; $URL = "deploymain.php?sid=" ; $URL .= $sid ; header("Location: $URL") ; } } } /* if conn */ else { print("<br />\nERROR CONNECTING TO DATABASE<BR />\n" ); niwaWriteLog("There has been an error connecting to the database","General"); } /* bad connection */ } ?> <?php if($name) { print("Username / Password Incorrect<br />\n") ; } if($reason) { if($reason == "BADSID") print("Session has ended, please login again") ; if($reason == "LOGOUT") { $conn = odbc_connect($dbname,$dbusername,$dbpassword) ; $sql = "update niwausertable set sid = ' ' where sid = '"; $sql .= $sid ; $sql .= "'" ; odbc_exec($conn, $sql); odbc_close ($conn); print("User Logged Out") ; } } ?> <FORM METHOD="POST" ACTION="login.php"> <PRE> Your Name: <INPUT TYPE="text" NAME="name" SIZE="20" MAXLENGTH="50" VALUE=""> Your Password: <INPUT TYPE="password" NAME="password" SIZE="20" MAXLENGTH="20" VALUE=""> <input name="Reset" type="reset" id="Reset" value="Reset"> <INPUT TYPE="submit" VALUE="Login"> </PRE> </FORM> </body> </html> Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 it doesn't submit at all if it did, it supposed to echo something when in fact it does not Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 actually it isn't a login page the page "persona.php" has a form with a password field if I submit it to persona.php it supposed to echo an error message if the password is wrong, or echo data from an sql table if the password is correct Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 oh btw the password is retrieved from a variable on the page, not from an sql table so while it's indeed a nice code, it wouldn't work for me in this situation. But anyway thanks for trying to help. I'm definitely learning this way. Quote Link to comment Share on other sites More sharing options...
sqlnoob Posted March 23, 2008 Author Share Posted March 23, 2008 ok well tried it another way and it works now, but it's not exactly the way I want 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.