Jump to content

Archived

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

garry27

mysql problem

Recommended Posts

ok so i'm trying to get the following code to verifiy $email and $pwd as part of a login process:


<?php

session_start();

// Initiates php script containing functions
  require_once('common.php');
  require_once('user_auth_fs.php');

$email = $_GET['email'];
$pwd = $_GET['pwd'];

// turn off run-time error notices
$old_level = error_reporting(E_ALL & ~E_NOTICE);


if ($email && $pwd)
// they have just tried logging in
{
  try
  {
    login($email, $pwd);
    // if they are in the database register the user id
    $_SESSION['valid_user'] = $email;
  }
  catch(Exception $e)
  {
    // unsuccessful login
    echo  'You could not be logged in. You must be logged in to view this page.';
    exit;
  }     
}
?>




but i'm not getting anything outputted to my $sql variable. the sql doesn't seem to be working but the db connection is fine.

<?php    //user_auth_fs.php   

  function login ($email, $pwd)
  {
  // check username and password with db
  // if yes, return true
  // else throw exception


  // turn off run-time error notices
  $old_level = error_reporting(E_ALL & ~E_NOTICE);
 
  // connect to db

  $conn = db_connect();
 
  $sql = $conn->query("SELECT * from members;");

  echo $sql;
?>


please can someone tell me how to fix this?
 

Share this post


Link to post
Share on other sites
connect like:

[code]
$connection = mysql_connect(host,dbuser,dbpass);
$db = mysql_select_db(dbname,$connection);
//then
$sql = "SELECT * FROM members";
$result = mysql_query($sql);
$result2 = mysql_fetch_assoc($result);
[code]

then whatever you want to echo do

[code]
echo $result2[user];
[/code]

just change user to a field in your database[/code][/code]

Share this post


Link to post
Share on other sites
it doesn't work when i use the long hand way of connecting to db- i get:

Fatal error: Call to a member function query() on a non-object in /home/unn_p921847/public_html/pa_home.php on line 59

...but when i use the short hand method which i copied from a book, it seems to connect ok (or at least doesn't spit back any errors) but then the i get no results with the mysql.

im fed up of this. i've spent over a day trying to solve this. i never had a problem connecting before when i was using request. ever since i'm having to use sessions to pass on data, i'm having problems.



Share this post


Link to post
Share on other sites

×

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.