Jump to content


Photo

Searching a mysql database


  • Please log in to reply
3 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 17 September 2006 - 02:21 AM

Hello, Im wondering how do i search a mysql database (code wise) when i want to know the username "p0001" 's name and password.

would it be like:

SELECT WHERE "p0001" = $username AND name = NULL AND password = NULL

?

- Cheers, Daniel

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 September 2006 - 03:37 AM

SELECT name, password from tablename WHERE username = 'p0001'
Legend has it that reading the manual never killed anyone.
My site

#3 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 17 September 2006 - 03:54 AM

like this:

<html>
<head>
</head>

<body>

<p>
My Profile:
</p>

<?php
if (isset($_COOKIE['user'])) {
include('connect.php');
$user = $_COOKIE['user'];
	
$sql = "SELECT * FROM users WHERE user='$user'";
$result = mysql_query($sql);
$count=mysql_num_rows($result);

if ($count = 1)
{
echo "Welcome to your profile, $user";

$sql = "SELECT name FROM users WHERE user = '$user'";
$name = mysql_query($sql);
$sql = "SELECT email FROM users WHERE user = '$user!";
$email = mysql_query($sql);
echo "$name, $email";
}
if ($count = 0)
{
?>

<meta http-equiv="refresh" content="0;url=logout2.php">;

<?php
}

}
?>

</body>
</html>

- Cheers, Daniel

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 17 September 2006 - 05:08 AM

$sql = "SELECT name FROM users WHERE user = '$user'";
$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql);
$row = mysql_fetch_array($result);
$name = $row['name'];
$email = $row['email'];
echo $name,  $email;

Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users