Jump to content

MYSQL and PHP Problem


jay_bo

Recommended Posts

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;
}

?>

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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'];


}

Link to comment
Share on other sites

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.
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.