Im getting a blank page in php [closed]
I'm trying to create a PHP e-mail activation system for my users, and when I run my script, it returns a blank page and my database was not updated. Any help is appreciated.
Here is my code:
<?php
session_start()
$host="localhost";
$username="root";
$password="power1";
$db_name="members";
$tbl_name="users";
$link = mysql_connect($host, $username, $password)or die("cannot connect. Please contact us");
mysql_select_db($db_name)or die("cannot select DB. Please contact us");
$queryString = $_SERVER['QUERY_STRING'];
if(isset($_SESSION[$queryString])) {
$query = "SELECT *
FROM users
WHERE email = '$_SESSION[$queryString]'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
if ($queryString == $row[activationkey]) {
echo "Congratulations! You have succesfully activated you account. You may now login.";
$sql = ("UPDATE users
SET activationkey = ''
AND status = 'activated'
WHERE username = ".$row['username']);
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
}
}
} ?>
In your code, activationkey
is an uninitialized constant. You probably meant it to be a string.
Change this line:
if ($queryString == $row[activationkey]){
to this:
if ($queryString == $row['activationkey']){
And since you are accessing the elements of $row
via string indexes, rather than numeric ones, you'll also want to change:
while($row = mysql_fetch_array($result)){
to:
while($row = mysql_fetch_assoc($result)){
Also, since you are accessing a session, you probably want to call session_start()
before the first reference to $_SESSION
.
And finally, your code may be sending a malformed query to the database. Try changing this line:
$query = "SELECT * FROM users WHERE email='$_SESSION[$queryString]'";
to this:
$query = "SELECT * FROM users WHERE email='" . mysql_real_escape_string($_SESSION[$queryString]) . "'";
You probably just have an error... PHP is notorious for blowing up and not letting you know about it. Try adding this to the top of your code and running the file:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Just don't leave it in when you make you're application available to other users..
Your query may not be returning any value, try to print the sql and see what's wrong with the query
while using sessions, you need to give
<?php
session_start();
at the beginning of the script.
I think the lines with $_SESSION[$queryString]
may be your issue, try replacing all instances with $_SESSION['QUERY_STRING']
or $queryString
only message is printed if you execution goes in
if ($queryString == $row[activationkey])
statement..
I think $queryString does not get any match with all db vals...
one more thing if activationkey is table column then it has to be covered by single or double quotes like this $row['activationkey']
精彩评论