Jump to content

PHP/MySQL query error


PHPrp

Recommended Posts

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'";
[b] $result = $conn->query($query);[/b]
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.
Link to comment
https://forums.phpfreaks.com/topic/6880-phpmysql-query-error/
Share on other sites

What is the error message that you are getting?

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

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

Ken
Link to comment
https://forums.phpfreaks.com/topic/6880-phpmysql-query-error/#findComment-25038
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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