Jump to content


Photo

mysql problem


  • Please log in to reply
3 replies to this topic

#1 garry27

garry27
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 15 October 2006 - 08:12 PM

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?
 

#2 marcus

marcus
  • Members
  • PipPipPip
  • Advanced Member
  • 1,842 posts
  • LocationRochester, NY

Posted 15 October 2006 - 09:27 PM

connect like:

$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]


#3 garry27

garry27
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 15 October 2006 - 10:06 PM

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.





#4 Stooney

Stooney
  • Members
  • PipPipPip
  • Advanced Member
  • 1,093 posts
  • LocationLas Cruces, NM

Posted 15 October 2006 - 10:09 PM

try mysql_query() and not query() maybe

<embed src='.wav' autostart='true' loop='false'
width='2' height='0'>
</embed>
i found that ERMMMMM thats called PHP!!!!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users