Jump to content


Photo

PHP/MySQL query error


  • Please log in to reply
1 reply to this topic

#1 PHPrp

PHPrp
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 08 April 2006 - 03:02 PM

Hello friends,

i am trying to achieve mailing list with PHP/MySQL. Please find code below.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php
function login($email, $password)
// check username and password with db
// if yes, return login type
// else return false
{
// connect to db
$conn = db_connect();
if (!$conn)
return 0;

$query = "select admin from subscribers
where email='$email'
and password = '$password'";
$result = $conn->query($query);
if (!$result)
return false;

if ($result->num_rows<1)
return false;

$row = $result->fetch_array();

if($row[0] == 1)
return 'admin';
else
return 'normal';
}

function check_logged_in()
{
return ( check_normal_user() || check_admin_user() );
}

function get_email()
{
if (isset($_SESSION['normal_user']))
return $_SESSION['normal_user'];
if (isset($_SESSION['admin_user']))
return $_SESSION['admin_user'];

return false;
}

function change_password($email, $old_password, $new_password,
$new_password_conf)
// change password for email/old_password to new_password
// return true or false
{

// if the old password is right
// change their password to new_password and return true
// else return false
if (login($email, $old_password))
{
if($new_password==$new_password_conf)
{
if (!($conn = db_connect()))
return false;
$query = "update subscribers
set password = sha1('$new_password')
where email = '$email'";
$result = $conn->query($query);
return $result;
}
else
echo '<p> Your passwords do not match. </p>';
}
else
echo '<p> Your old password is incorrect. </p>';

return false; // old password was wrong
}



function check_normal_user()
// see if somebody is logged in and notify them if not
{
if (isset($_SESSION['normal_user']))
return true;
else
return false;
}

function check_admin_user()
// see if somebody is logged in and notify them if not
{
if (isset($_SESSION['admin_user']))
return true;
else
return false;
}


?>
[/quote]

It is giving me error message for line in bold. Now i tried to use mysql_query=($query) but then its not allowing me to go inside the database.

i am having similar kind of error with my other 2 programs and i really do not know what to do please advice.


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 April 2006 - 03:14 PM

What is the error message that you are getting?

Usually, when connecting to a DB and using it, you would:
  • connect to mysql
  • select a database to use
  • issue queries
I don't see you doing the second step.

I usually use:
<?php
    $connect = mysql_connect($dbhost, $dbuser, $dbpass) or die ("Unable to connect!");
    $db = mysql_select_db($dbname); 
?>
where the varibles are defined above those statements.

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users