...

View Full Version : mysql query not selecting correctly



amcf1992
09-15-2011, 06:58 PM
<?php session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Account Dashboard</title>
</head>
<body>
<?php
include('dbsettings.php');

$con = mysql_connect("$host","$user","$password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("$db_name", $con);

$username=$_POST['username'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$email=$_POST['email'];
$password=$_POST['password'];
$pass2=$_POST['password2'];
$account=$_POST['account'];
$secretquestion1=$_POST['secretquestion1'];
$secretanswer1=$_POST['secretanswer1'];
$date= date("m-d-y");

$result = mysql_query("SELECT * FROM $tbl_name WHERE email='$email'");

while($row = mysql_fetch_array($result))
{
echo $row['firstname'] . " " . $row['lastname'];
echo "<br />";
}

mysql_close($con);
?>
<a href="logout.php"> Log Out </a>
</body>
</html>

myfayt
09-15-2011, 07:01 PM
Where is your post method at?

amcf1992
09-15-2011, 07:05 PM
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<titleLogin</title>
</head>
<body>

<form method="POST" action="dologin.php">
Username: <br /><input type="text" name="username" size="30" style="width:250px; height:50px; font-size: 18px;"> <br />
Password:<br /><input type="password" name="password" size="30" style="width:250px; height:50px; font-size: 18px;">
<br /> <br />
<div align="left">
<p><input type="submit" value="Login" /></p>


</body>
</html>

Old Pedant
09-15-2011, 07:28 PM
Where is the definition of $tbl_name ??

I don't see that you ever assign to a variable of that name.

And, given the <form> you showed, the *ONLY* $_POST values you can get are


$username=$_POST['username'];
$password=$_POST['password'];

Which means that your use of $email is also invalid.

Looks to me like you are trying to piece together code from two different places and you are trying to put a square peg into a round hole.

amcf1992
09-15-2011, 07:31 PM
$tbl_name is inside dbsettings.php
here is the code for the register, which contains the $email value



<?php
session_start();
include('dbsettings.php');
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form

$username=$_POST['username'];
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$address=$_POST['address'];
$email=$_POST['email'];
$password=$_POST['password'];
$pass2=$_POST['password2'];
$account=$_POST['account'];
$secretquestion1=$_POST['secretquestion1'];
$secretanswer1=$_POST['secretanswer1'];
$date= date("m-d-y");


function rand_string( $length ) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

$size = strlen( $chars );
for( $i = 0; $i < $length; $i++ ) {
$str .= $chars[ rand( 0, $size - 1 ) ];
}

return $str;
}
$activationkey= rand_string( 45 );

//md5 password
$md5password=md5("$password");





// Insert data into mysql
$sql="INSERT INTO $tbl_name(id, username, firstname, lastname, address, email, password, account, secretquestion1, secretanswer1, activationkey)
VALUES('', '$username', '$firstname', '$lastname', '$address', '$email', '$md5password', '$account', '$secretquestion1', '$secretanswer1', '$activationkey')";
$result=mysql_query($sql) or die(mysql_error());

// if successfully insert data into database, displays message "Successful".
if($result){

echo "You have successfully registered. You will be redirected to the login page.";
echo '<META HTTP-EQUIV="Refresh" Content="3; URL=login.php">';
}
else
echo "There was a problem with the database. We'll fix this as soon as possible.";


// close connection
mysql_close();
?>

Old Pedant
09-15-2011, 09:18 PM
Fine, but that has NOTHING at all to do with the <form> you showed us in your post #3.

*THAT* <form> will post *ONLY* username and password, so you can *NOT* use $email.

amcf1992
09-15-2011, 09:21 PM
okay then can i do:

$result = mysql_query("SELECT * FROM $tbl_name WHERE username='$username");

is that correctly formatted?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum