jay_bo Posted February 27, 2010 Share Posted February 27, 2010 For some reason this piece of code as stopped working... its not reading in the valuse from login table. <?PHP include("dblogin.php");//Includes the database connection details // value sent from form $email_to=$_POST["email_to"]; $result=mysql_query("SELECT * FROM login WHERE email='$email_to'"); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row $row = mysql_fetch_row($result); if($count==0){ $_SESSION["incorrectemail"]==true; header('location: main_login.php?incorrectemail=true');//Sends the user back to the sign up page due to incorrect details } else{ // Random confirmation code $confirm_code=md5(uniqid(rand())); //new password $random_password=(uniqid(rand())); $new_password=substr($random_password, 0, ; $title=$row["title"]; $username=$row['username']; $firstname=$row['firstname']; $lastname=$row['lastname']; $email=$row['email']; $number=$row['number']; $street=$row['street']; $postcode=$row['postcode']; $town=$row['town']; $county=$row['county']; $telephone=$row['telephone']; $alternative_telephone=$row['alternative_telephone']; // Insert data that retrieves from "temp_members_db" into table "registered_members" $sql2="INSERT INTO temp_members(id, confirm_code, title, username, password, firstname, lastname, email, number, street, postcode, town, county, telephone, alternative_telephone)VALUES ('NULL', '$confirm_code', '$title','$username', '$new_password', '$firstname', '$lastname','$email','$number','$street','$postcode','$town','$county','$telephone', '$alternative_telephone')"; $result2=mysql_query($sql2); } if($result2==true){ // send e-mail to ... $to=$email_to; // Your subject $subject="Your password here"; // From $header="from: your name <your email>"; // Your message $messages= "Your password for login to our website \r\n"; $messages.="Your password is $new_password \r\n"; $messages.="Please go to http://www.sweet-explosions.co.uk/forgot_pass_confirmation.php?passkey=$confirm_code \r\n"; // send email $sentmail = mail($to,$subject,$messages,$header); } // if your email succesfully sent if($sentmail){ $_SESSION["email"]==true; header('location: main_login.php?email=true'); } else { echo "Cannot send password to your e-mail address"; echo $title; } ?> Quote Link to comment Share on other sites More sharing options...
harristweed Posted February 27, 2010 Share Posted February 27, 2010 Are you sure you are connecting to the database? Do you get any error messages ? ini_set('error_reporting', E_ALL); ini_set('display_errors', 'On'); Quote Link to comment Share on other sites More sharing options...
jay_bo Posted February 27, 2010 Author Share Posted February 27, 2010 Yea i'm connected i get these errors ... Notice: Undefined index: lastname in .... on line 40 Quote Link to comment Share on other sites More sharing options...
fantomel Posted February 27, 2010 Share Posted February 27, 2010 Yea i'm connected i get these errors ... Notice: Undefined index: lastname in .... on line 40 you are getting data from a form no ? if yes did you checked if the data comes from the $_POST ? i don't see there any type of checking for a submit.... Quote Link to comment Share on other sites More sharing options...
jay_bo Posted February 27, 2010 Author Share Posted February 27, 2010 Im trying to get this information out of the logins database $title=$row["title"]; $username=$row['username']; $firstname=$row['firstname']; $lastname=$row['lastname']; $email=$row['email']; $number=$row['number']; $street=$row['street']; $postcode=$row['postcode']; $town=$row['town']; $county=$row['county']; $telephone=$row['telephone']; $alternative_telephone=$row['alternative_telephone']; Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 27, 2010 Share Posted February 27, 2010 Have you changed your fetch to mysql_fetch_assoc in order to get your results as an associative array? Quote Link to comment Share on other sites More sharing options...
jay_bo Posted February 27, 2010 Author Share Posted February 27, 2010 No not as i know of. Quote Link to comment Share on other sites More sharing options...
jay_bo Posted February 27, 2010 Author Share Posted February 27, 2010 This is the part of the code that has stopped working.... // value sent from form $email_to=$_POST['email_to']; $result=mysql_query("SELECT * FROM login WHERE email='$email_to'"); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row $row = mysql_fetch_row($result); if($count==1){ $title=$row["title"]; $username=$row['username']; $firstname=$row['firstname']; $lastname=$row['lastname']; $email=$row['email']; $number=$row['number']; $street=$row['street']; $postcode=$row['postcode']; $town=$row['town']; $county=$row['county']; $telephone=$row['telephone']; $alternative_telephone=$row['alternative_telephone']; } Quote Link to comment Share on other sites More sharing options...
jl5501 Posted February 27, 2010 Share Posted February 27, 2010 in order for $title=$row["title"]; to mean anything, change $row = mysql_fetch_row($result); to $row = mysql_fetch_assoc($result); Quote Link to comment Share on other sites More sharing options...
jay_bo Posted February 27, 2010 Author Share Posted February 27, 2010 Thank you very much, its working again now. Quote Link to comment Share on other sites More sharing options...
fantomel Posted February 27, 2010 Share Posted February 27, 2010 try this one not if it's working wrote it on fly.. <?php error_reporting(E_ALL); ini_set('display_errors', 'On'); $mysql_server = 'localhost'; $mysql_username = 'userusername'; $mysql_password = 'yourpassword'; $mysql_db_name = 'yourdb'; $link = mysql_connect('$mysql_server', '$mysql_username', '$mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } else { $db = mysql_select_db($mysql_db_name); if(!$db = mysql_select_db($mysql_db_name)) { die('Could not choose database' . mysql_error()); } } if(isset($_POST['submit'])) { $email_to = $_POST['email_to']; $sql = "SELECT * FROM `login` WHERE `email` = '".$email_to."'"; $result = mysql_query($sql, $link) or die(mysql_error()); if(mysql_num_rows($result) == '1') { while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $username = $row['username']; $firname = $row['firstname']; $lastname = $row['lastname']; $email = $row['email']; $number = $row['number']; $street = $row['street']; $postcode = $row['postcode']; $town = $row['town']; $country = $row['country']; $telephone = $row['telephone']; $alternative_telephone = $row['alternative_telephone']; $title = $row['title']; } } else { echo "Ok mate, we got a problem here check the mysql connection"; if(!mysql_ping()) { echo "No connection to MySQL Database check your credentials."; exit; } } } // die() and exit() aren't the best solution they are many other solutions out there but for testing purpose i think it's a good choice good luck. ?> 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.