Solved

results from db

Posted on 2000-04-04
6
176 Views
Last Modified: 2006-11-17
im trying to get results from database.
i want to write "good" if the $username
variable is show in the db,and "bad"
if it isn't.
here's the code:
$sql="select name,passwd from user where name=$username";
mysql_connect("haag","elad");
$result=mysql_db_query("appscan",$sql);
$row=mysql_fetch_object($result);
if ($row){
echo ("good");
}else{
echo ("bad");
}
....

it is not working...
0
Comment
Question by:eladr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 8

Expert Comment

by:us111
ID: 2684268
mysql_db_query needs 3 parameters:

int mysql_db_query(string database, string query, int [link_identifier] );

try:

$row = mysql_query($query, $sql);
0
 
LVL 8

Expert Comment

by:us111
ID: 2684299
Oops other mistakes

$sql="select name,passwd from user where name=$username";
$conn = mysql_connect("database", "login", "password");
$result=mysql_query($sql, $conn);

$row=mysql_fetch_row($result);
if ($row){
     echo ("good");
}else{
     echo ("bad");
}
0
 
LVL 1

Author Comment

by:eladr
ID: 2684350
not working...
where im "telling" what is the database name?
sorry...completley new to php.
know ASP...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:eladr
ID: 2684360
that's the error:
Warning: Supplied argument is not a valid MySQL result resource in /home/elad/public_html/index.php on line 8

8 $row=mysql_fetch_row($result);
0
 
LVL 1

Author Comment

by:eladr
ID: 2684380
that's the error:
Warning: Supplied argument is not a valid MySQL result resource in /home/elad/public_html/index.php on line 8

8 $row=mysql_fetch_row($result);
0
 
LVL 8

Accepted Solution

by:
us111 earned 2 total points
ID: 2684467
Sorry mistake, try that:

<?
$sql="select * from table";
$conn = mysql_connect("localhost", "", "");

$result = mysql("yourdatabase",$sql,$conn);

$row=mysql_fetch_row($result);
if ($row){
        echo ("good");
}else{
        echo ("bad");
}
?>
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question