Solved

results from db

Posted on 2000-04-04
6
161 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 dynamically set the form action using jQuery.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now