Jump to content

mysql problem


garry27

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?
 
Link to comment
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]
Link to comment
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.



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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