Solved

results from db

Posted on 2000-04-04
6
186 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to implement server side field validation and display customized error messages to the client.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

626 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