Jump to content

webguync

Members
  • Posts

    951
  • Joined

  • Last visited

Everything posted by webguync

  1. I just get [name] => name [code=php:0] doesn't evaluate to anything, but like I say it is there on the form page, just doesn't post.
  2. when you say at the start of the script, do you mean the line above mail()?
  3. There is a lot to it. login page <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr"> <head> <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" /> <title> Candidate Test </title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script language="javascript"> // Developed by Roshan Bhattarai // Visit http://roshanbh.com.np for this script and more. // This notice MUST stay intact for legal use $(document).ready(function() { $("#login_form").submit(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000); //check the username exists or not from ajax $.post("login.php", {username:$('#username').val(),password:$('#password').val()} ,function(data) { //alert(data); if(data==1) //if correct login detail { $("#msgbox").fadeTo(200,0.1,function(data) //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('Success!..Logging in.....').addClass('messageboxok').fadeTo(900,1, function() { //redirect to secure page document.location='EditorExam.php'; }); }); } else { $("#msgbox").fadeTo(200,0.1,function(data) //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('You have entered an incorrect login<br /> please try again!').addClass('messageboxerror').fadeTo(900,1).delay(5000).fadeTo(900,0); }); } }); return false; //not to post the form physically }); //now call the ajax also focus move from $("#password").blur(function(data) { $("#login_form").trigger('submit'); }); }); </script> <body> <div id="LoginContainer"> <h1 class="login">Candidate Login</h1> <div id="form_align"> <form enctype="multipart/form-data" method="post" action="" id="login_form" > <fieldset> <legend>Please enter your email address and password to login to your test.</legend> <div class="loginwrapper"> <label for="username">Username:<span class='red_small'> (email address) </span></label><br /> <input type="text" name="username" id="username" size="20"><br /><br /> <label for="password">Password:<span class='red_small'> (you should have been given this)</span> </label><br /> <input type="password" name="password" id="password" size="20"><br /><br /> <div class="buttondiv"> <input class="button" type="submit" name="submit" value="Login" /><span id="msgbox" style="display:none"></span> </div> </div><!--end login wrapper--> </form> </fieldset> </div> </div><!--end container div--> </body> </html> login processing <?php session_start(); $db_user = "User"; $db_pass = "Pass"; $db = "DB"; mysql_connect('localhost',$db_user,$db_pass); mysql_select_db($db); $username = mysql_real_escape_string($_POST['username']); $password =(md5($_POST['password'])); $sql = "SELECT username,password,name FROM Candidates WHERE password = '$password' AND username='$username'"; $dat = time() + 3600; $sql_update ="UPDATE Candidates SET login_timestamp = DATE_ADD(NOW(), INTERVAL 2 HOUR) WHERE username = '$username' AND password = '$password'"; $query = mysql_query($sql) or die("Query Failed: $sql - " . mysql_error()); $num_rows = mysql_num_rows($query); $row = mysql_fetch_array($query) or die(mysql_error()); if ($num_rows == '1') { $_SESSION['name'] = $row['name']; $_SESSION['username'] = $username; $_SESSION['sid'] = session_id(); // Make it more secure by storing the user's IP address. $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; echo '1'; } else { echo '0'; } ?> login brings you to a secure form page I am only posting the PHP part at the top of the page. The rest is HTML <?php session_start(); ini_set("display_errors","1"); ERROR_REPORTING(E_ALL); // Start a session. If not logged in will be redirected back to login screen. if(!isset($_SESSION['username'])){ header("Location:Login.php"); exit; } print_r($_SESSION); ?> the code to process the form on this page. <?php session_start(); $con = mysql_connect("localhost","username","pw") or die('Could not connect: ' . mysql_error()); mysql_select_db("ETSI_Internal") or die(mysql_error()); $_SESSION['name'] = $row['name']; $name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file $A1=mysql_real_escape_string($_POST['Answer1']); //This value has to be the same as in the HTML form file $A2=mysql_real_escape_string($_POST['Answer2']); //This value has to be the same as in the HTML form file $A3=mysql_real_escape_string($_POST['Answer3']); //This value has to be the same as in the HTML form file $A4=mysql_real_escape_string($_POST['Answer4']); //This value has to be the same as in the HTML form file $A5=mysql_real_escape_string($_POST['Answer5']); //This value has to be the same as in the HTML form file $sql="INSERT INTO Responses (`name`,`Answer1`,`Answer2`,`Answer3`,`Answer4`,`Answer5`)"; /*form_data is the name of the MySQL table where the form data will be saved. name and email are the respective table fields*/ if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } else{ print($name); mail('email@email.com','Exam Completed',$name.' has completed the exam',$body); echo "Your information has been submitted successfully."; } mysql_close($con); ?>
  4. I think that is being set after name is extracted via SQL and set as a session var. $_SESSION['name'] = $row['name'];
  5. well not sure why the $variable is empty, but that appears to be the problem. The variable holds from the login to the form page, b/c i use Welcome! You are now logged in <span class='name'>" . $_SESSION['name'] . "</span> and the value is there. In my form process page I use. session_start(); at the top of my page and $_SESSION['name'] = $row['name']; the info is originally achieved when the user logs in with SQL $sql = "SELECT username,password,name FROM Candidates WHERE password = '$password' AND username='$username'"; $row = mysql_fetch_array($query) or die(mysql_error());
  6. thanks for the reply. I changed to this mail('email@email.com','Exam Completed',$name.' has completed the online exam',$body); but the variable doesn't come through. Just shows up in the email as [space]has completed the online exam. I know the variable info is holding the right value through print_r(_$SESSION); I have the email script in a separate PHP processing file from the form page. Any ideas why the variable info is not coming through?
  7. hi, wanted to bump this back to the forefront. Need to get this resolved, thanks!
  8. with the second timestamp submit_timestamp isn't set until the data hits the database. Can I still use the Session variables? The first timestamp for login is set like this. $sql_update ="UPDATE Candidates SET login_timestamp = DATE_ADD(NOW(), INTERVAL 2 HOUR) WHERE username = '$username' AND password = '$password'";
  9. Hi, I have a variable $name and I want the information in that variable emailed in the body of the email. I know that the variable session is working with print_r($_SESSION); but when I try to get the info mailed to me it just shows up as "$name has completed the exam". Here is what I am trying. mail('email@email.com','Application Completed','$name has completed the exam',$body); any ideas on what I need to add/change?
  10. MYSQL query might be easier. I want something like SELECT TIMESTAMPDIFF(MINUTE,'2010-05-17 12:26:13','2010-05-17 11:32:45'); except will need to use PHP to determine which record to use from WHERE username = '$username' and also the two fields I need to do the addition are in two different tables(Candidates.login_timestamp and Responses.submit_timestamp). Want to be able to echo out the results in PHP
  11. I have two tables with two fields, both timestamps. I need to set up a Query to subtract the difference in minutes between the two fields (login_timestamp and submit_timestamp). login_timestamp is in a table called 'Candidates' and submit_timestamp is in a table called 'Responses'. I believe I would need to use. SELECT TIMESTAMPDIFF(MINUTE,'2010-05-17 12:26:13','2010-05-17 11:32:45'); but a little unsure about how to from two different tables. Thanks in advance!
  12. so I would just use SQL to extract the info from the database with $row = mysql_fetch_assoc($result) and display the info, something like <td>{$row['Timestamp']}</td> then where would strtotime need to go? Also, how would I set up the subtraction between the two fields? Thanks
  13. Hi, I am using a timestamp in MySQL to determine when a user logs-in and submits data from a form, What I would like to do is determine the time difference between the login and submit timestamps and echo out the results. "The time taken to complete is 45 minutes." for example. How is this done? The timestamp(s) will look something like 2010-05-17 11:32:45
  14. thanks for the replies to this point. My code now looks like this, but I still am not getting the candidate_name variable to display on the next page. <?php session_start(); $db_user = "user"; $db_pass = "pass"; $db = "DB_Name"; mysql_connect('localhost',$db_user,$db_pass); mysql_select_db($db); $username = mysql_real_escape_string($_POST['username']); $password =(md5($_POST['password'])); $sql = "SELECT username,password,candidate_name FROM Candidates WHERE password = '$password' AND username='$username'"; $dat = time() + 3600; $sql_update ="UPDATE Candidates SET login_timestamp = DATE_ADD(NOW(), INTERVAL 2 HOUR) WHERE username = '$username' AND password = '$password'"; $query = mysql_query($sql) or die("Query Failed: $sql - " . mysql_error()); $num_rows = mysql_num_rows($query); $row = mysql_fetch_array($query) or die(mysql_error()); if ($num_rows == '1') { $_SESSION['candidate_name'] = $row->candidate_name; $_SESSION['username'] = $username; $_SESSION['sid'] = session_id(); // Make it more secure by storing the user's IP address. $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; echo '1'; } else { echo '0'; } ?>
  15. ok, here is the PHP login script I am using to process the info and set the SESSION var for candidate_name. The SQL seems to be working, and I have started a session at the top. <?php session_start(); $db_user = "user"; $db_pass = "pass"; $db = "DBName"; mysql_connect('localhost',$db_user,$db_pass); mysql_select_db($db); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string(md5($_POST['password'])); $sql = "SELECT username,password,candidate_name FROM Candidates WHERE password = '$password' AND username='$username'"; $dat = time() + 3600; $sql_update ="UPDATE Candidates SET login_timestamp = DATE_ADD(NOW(), INTERVAL 2 HOUR) WHERE username = '$username' AND password = '$password'"; $query = mysql_query($sql); $num_rows = mysql_num_rows($query); $query = mysql_query($sql) or die("Query Failed: $sql - " . mysql_error()); if ($num_rows == '1') { $_SESSION['candidate_name'] = $sql->candidate_name; $_SESSION['username'] = $username; $_SESSION['sid'] = session_id(); // Make it more secure by storing the user's IP address. $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; echo '1'; } else { echo '0'; } ?>
  16. I am trying to store a session variable just from a SQL query, but it's not holding. I am probably doing it wrong. I am not getting the info from any kind of form input so the info is only coming from the Query. My Query code is: $sql = "SELECT username,password,candidate_name FROM Candidates WHERE password = '$password' AND username='$username'"; then further down the page I have... $_SESSION['candidate_name'] = $sql->candidate_name; and then on a different page I have at the top... session_start(); and further down You are now logged in <span class='red'>" . $_SESSION['candidate_name'] . "</span> nothin for candidate_name BTW candidate name is a field in the MySQL table.
  17. I there a way of simplifying this? I am wanting to display a row of data from a mysql table into an HTML table with each column in a <td> and a new row for each record. Also a header for each column. Started doing it like below but thinking this is really cumbersome and there is prolly a better way :-) while ($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo"<th>Name</th>"; echo "</tr>"; echo "<tr>"; echo "<td>"; echo $row["name"]; echo "</td>"; echo "</tr>"; echo "<tr>"; echo"<th>Answer 1</th>"; echo "</tr>"; echo "<tr>" echo "<td>"; echo $row["Answer1"]; echo "</td>"; echo "<td>"; echo $row["Answer2"]; echo "</td>"; echo "<td>"; echo $row["Answer3"]; echo "</td>"; echo "<td>"; echo $row["Answer4"]; echo "</td>"; echo "<td>"; echo $row["Answer5"]; echo "</td>"; echo "<td>"; echo $row["Answer6"]; echo "</td>"; echo "<td>"; echo $row["Answer7"]; echo "</td>"; echo "<td>"; echo $row["Answer8"]; echo "</td>"; echo "<td>"; echo $row["Answer9"]; echo "</td>"; echo "<td>"; echo $row["Answer10"]; echo "</td>"; echo "<td>"; echo $row["Answer11"]; echo "</td>"; echo "<td>"; echo $row["Answer12"]; echo "</td>"; echo "<td>"; echo $row["submit_timestamp"]; echo "</td>"; echo "</tr>"; } mysql_free_result($result); ?>
  18. any ideas on why my setting a cookie isn't allowing me to go to secured page?
  19. Since I am setting a COOKIE with successful login, I tried doing this, but doesn't work either. if(!isset($_COOKIE['username'])){ header("Location:secure_page.php"); exit; } when I do this... print_r($_COOKIE); the username is successfully being set as a cookie from here. if ($num_rows == '1') { setcookie("logged_in",$password, time()+3600); echo '1'; } else { echo '0'; }
  20. well in the JQuery it's saying if login is successful go to secure page. if(data==1) //if correct login detail { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('Success!..Logging in.....').addClass('messageboxok').fadeTo(900,1, function() { //redirect to secure page document.location='securepage.php'; }); }); } and on the secure page I am trying to retrieve session var from login page $_SESSION['username'] = $username; the middle part of the code I posted checks the database for the username and password and if ==1 is redirecting to secure page. This part appears to be working fine.
  21. I have a login script using JQuery with PHP and MySQL back-end which seems to work, but the secure page that should be directing to when login successful directs me right back to the login script. I believe this was working ok, prior to adding the JQuery. The variable not holding is for username. The login success/fail part works fine, so only the displaying the secure page when login is successful is not working. How can I debug? Code below. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr"> <head> <meta http-equiv="Content-type" content="text/html; charset=ISO-8859-1" /> <title> ETSI Editor Candidate Test </title> <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/niceforms.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> <script language="javascript"> $(document).ready(function() { $("#login_form").submit(function() { //remove all the class add the messagebox classes and start fading $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000); //check the username exists or not from ajax $.post("login.php",{ username:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data) { alert(data); if(data==1) //if correct login detail { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('Success!..Logging in.....').addClass('messageboxok').fadeTo(900,1, function() { //redirect to secure page document.location='EditorExam.php'; }); }); } else { $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox { //add message and change the class of the box and start fading $(this).html('You have entered an incorrect login, please try again!').addClass('messageboxerror').fadeTo(900,1); }); } }); return false; //not to post the form physically }); //now call the ajax also focus move from $("#password").blur(function() { $("#login_form").trigger('submit'); }); }); </script> </head> <body> <div id="LoginContainer"> <h1 class="login">Login Page</h1> <div id="form_align"> <form enctype="multipart/form-data" method="post" action="" id="login_form" class="niceform"> <fieldset> <legend>Please enter your email address and password to login to your test.</legend> <div class="loginwrapper"> <label for="username">Username:<span class='red_small'> (email address) </span></label><br /> <input type="text" name="username" id="username" size="20"><br /><br /> <label for="password">Password:<span class='red_small'> (you should have been given this)</span> </label><br /> <input type="password" name="password" id="password" size="20"><br /><br /> <div class="buttondiv"> <input class="button" type="submit" name="submit" value="Login" /><span id="msgbox" style="display:none"></span> </div> </div><!--end login wrapper--> </form> </fieldset> </div> </div><!--end container div--> </body> </html> <?php $db_user = "username"; $db_pass = "pw"; $db = "DBName"; mysql_connect('localhost',$db_user,$db_pass); mysql_select_db($db); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string(md5($_POST['password'])); $sql= "SELECT * FROM tablename WHERE username = '$username' AND password = '$password'"; $query = mysql_query($sql); $num_rows = mysql_num_rows($query); $query = mysql_query($sql) or die("Query Failed: $sql - " . mysql_error()); if ($num_rows == '1') { setcookie("logged_in", $username, time()+3600); echo '1'; } else { echo '0'; } ?> and the secured page <?php session_start(); $db_user = "username"; $db_pass = "password"; $db = "DBName"; mysql_connect('localhost',$db_user,$db_pass); mysql_select_db($db); $_SESSION['editor_name'] = $row->editor_name; $_SESSION['username'] = $username; $_SESSION['sid'] = session_id(); // Make it more secure by storing the user's IP address. $_SESSION['ip'] = $_SERVER['REMOTE_ADDR']; // Now give the success message. // $_SESSION['username'] should print out your username. //move this to after your redirect further below.. //Update record with current time IF the account has never logged in before $dat = time() + 3600; $query = "UPDATE table SET login_timestamp = DATE_ADD(NOW(), INTERVAL 2 HOUR) WHERE username = '$username' AND password = '$password'"; //echo $query; //for debugging test $result = mysql_query($query) or die(mysql_error()); // Start a session. If not logged in will be redirected back to login screen. // if session is not set redirect the user if(empty($_SESSION['username'])) header("Location:login.php"); ?> <head>Secured Page</head> <body> Secured content page goes here </body> </html>
  22. ok, yea, that is what I was looking for. Thanks!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.