InsidiousMennace Posted March 16, 2013 Share Posted March 16, 2013 Hey there guys, I think I'm just being a spastic, but I do not know what to do anymore, my javascript does not want to work, before the prepared statements are even ran, where the $_GET['action'] is checked, it already throws out my error that the action can't be run. What am I missing. <?php require_once 'config.php'; error_reporting(E_ALL); //Connection to my database $mysqli = new mysqli(DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE); if(mysqli_connect_errno()) { printf("Connection failed: %s\n", mysqli_connect_errno()); exit(); } if($_GET['action'] == 'UserLogin') { $stmt = $mysqli->stmt_init(); //prepared statement if($stmt = $mysqli->prepare("select * from login where username = ? and password = ?")) { //bind my parameters $stmt->bind_param("ss",$username,$password); $username = $_POST["username"]; $password = $_POST["password"]; //execute query $stmt->execute(); //bind the result variables $stmt->bind_result($username,$password); //Store my values $stmt->store_result(); //fetch values if($stmt->fetch()) { $_SESSION["username"] = $username; alert("Authenticated"); header("location : Main_menu.php"); exit(); } else { alert("username or password is incorrect"); } $stmt->close(); $stmt->free_result(); } else { echo "Username or password incorrect"; } } else { echo "no"; } $mysqli->close(); ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <script language = "javascript"> function UserLogin() { document.login.submit(); } </script> <form name="login" action="login.php?action=UserLogin" method="post"> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Radius Login </strong></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="username" type="text" id="username"></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="button" name="Submit" value="Login" onclick="javascript:UserLogin();"/></td> </tr> </table> </td> </tr> </table> </form> </html> Link to comment https://forums.phpfreaks.com/topic/275730-loginsubmit-not-working/ Share on other sites More sharing options...
ginerjm Posted March 24, 2013 Share Posted March 24, 2013 You certainly are a newbie. Your html is not setup properly at all. Try looking at a book and learn the structure of an html page and you'll quickly see why your js is not working. Also you are missing other important tags. (quick answer - scripts must go in the head section of an html page along with css) Link to comment https://forums.phpfreaks.com/topic/275730-loginsubmit-not-working/#findComment-1420796 Share on other sites More sharing options...
kicken Posted March 25, 2013 Share Posted March 25, 2013 Using javascript at all in the above example is rather pointless. Just use a normal submit button and remove all the javascript. By using JS to submit your form like that you are doing nothing other than unnecessarily limiting your site to only people who have JS enabled. Link to comment https://forums.phpfreaks.com/topic/275730-loginsubmit-not-working/#findComment-1420815 Share on other sites More sharing options...
haku Posted March 25, 2013 Share Posted March 25, 2013 You certainly are a newbie. Your html is not setup properly at all. Try looking at a book and learn the structure of an html page and you'll quickly see why your js is not working. Also you are missing other important tags. (quick answer - scripts must go in the head section of an html page along with css) Sorry, but this is not only wrong, it is often bad practice. Scripts can go anywhere on the page, and often it's best to have them as the last thing on the page for faster page loads. Usually it is best not to include them until they are necessary. Link to comment https://forums.phpfreaks.com/topic/275730-loginsubmit-not-working/#findComment-1420820 Share on other sites More sharing options...
haku Posted March 25, 2013 Share Posted March 25, 2013 To the OP - it's always best to explain both exactly what you are trying to do (this does NOT mean how you are trying to do it), an what is happening now that is different to what you want. When you run into errors, you should copy and paste the entire error, as these often help us help you diagnose the issue. Be as descriptive as possible. The surest way to ensure you get a specific answer is to be as clear as possible about what is happening. The more vague the initial post, the less specific our responses will be. Link to comment https://forums.phpfreaks.com/topic/275730-loginsubmit-not-working/#findComment-1420822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.