Its ok now, I solved it..the problem was that I didn´t made any tables or colums to the database, so I didn´t know that I had to do that,

still my next issue is that I get this kinda error:

Duplicate entry '' for key 1

any ideas what I did or didn´t wrong?

My scrip worked for the first time, but now whatever I do I get this same error...like im escaped to the outer space or smtg... :/

And thank you guys for helping me on the last issue (:

I have this problem and i am new so please go slow...

error on page

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/loyalist/public_html/shop/pages/0.php on line 17

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/loyalist/public_html/shop/pages/0.php on line 13

$query = "SELECT * FROM config WHERE id=3";

lexi

At first glance I would recommend using single quotes for values in your query.

$query = "SELECT * FROM config WHERE id = '3' ";

Different versions of MYSQL also may require tick marks around table and field names. The apostrophe like symbol next to #1 on the keyboard.

$query = "SELECT * FROM `config` WHERE `id` = '3' ";

A good way to troubleshoot is to echo $query; and copy it into the PHPMyAdmin and see what it does.

Its ok now, I solved it..the problem was that I didn´t made any tables or colums to the database, so I didn´t know that I had to do that,

still my next issue is that I get this kinda error:

Duplicate entry '' for key 1

any ideas what I did or didn´t wrong?

My scrip worked for the first time, but now whatever I do I get this same error...like im escaped to the outer space or smtg... :/

And thank you guys for helping me on the last issue (:

Check to see that you have a primary index and that it is set to auto_increment. There should be a unique value for each row.

Hi there,

I've been trying to work out a small problem but I keep getting the famous mysql_num_rows() error.

This is the error that the page itself spits out:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sevenxde/public_html/bfg/test3.php on line 21

And here's the code:

<?php require_once('../Connections/mbovg.php'); ?>
<?php
$maxRows_movies = 5;
$pageNum_movies = 0;
if (isset($_GET['pageNum_movies'])) {
  $pageNum_movies = $_GET['pageNum_movies'];
}
$startRow_movies = $pageNum_movies * $maxRows_movies;

mysql_select_db($database_mbovg, $mbovg);
$query_movies = "SELECT ID, Title FROM mbovg ORDER BY Rating DESC";
$query_limit_movies = sprintf("%s LIMIT %d, %d", $query_movies, $startRow_movies, $maxRows_movies);
$movies = mysql_query($query_limit_movies, $mbovg) or die(mysql_error());
$row_movies = mysql_fetch_assoc($movies);

if (isset($_GET['totalRows_movies'])) {
  $totalRows_movies = $_GET['totalRows_movies'];
} else {
  $all_movies = mysql_query($query_movies);
  $totalRows_movies = mysql_num_rows($all_movies); //LINE 21
}
$totalPages_movies = ceil($totalRows_movies/$maxRows_movies)-1;

?>

Any suggestions on how to fix this problem?

Thanks in advance!

Try echoing your query, and see if it makes sense.

Try pasting it directly into mySQL (not via PHP) and see what happens also.

Try echoing your query, and see if it makes sense.

Try pasting it directly into mySQL (not via PHP) and see what happens also.

I wasn't able to fully comprehend the second suggestion (sorry, still going through the beginner to intermediate phase). How may I do that, exactly?

Also, are there any other ways of fixing it as well?

Thanks again!

I'm in need of some help with the above code. Can anybody help me, please?

I use Dreamweaver 8 and this code is automatically generated with it, but for some odd reason it wont work for me and I can't entirely understand why.

Thanks again,

yes :( , i'm taking same error

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/h/o/s/myhosting/html/templates/default/index.php on line 38

my code is ;

<? 
    require_once("class/gold.php");
    $sqlinfo = mysql_fetch_assoc(mysql_query("SELECT * FROM settings"));

    $phpgold = new phpgold($sqlinfo['gold_id']);


    if(empty($_GET['page'])){ $currentpage = 1; } else { $currentpage = $_GET['page']; }
    if(empty($_GET['tag'])){ $tag = $sqlinfo['default_tag']; } else { $tag = $_GET['tag']; }
    $source = $phpgold->videos_listbytag($tag, $currentpage, 11);
    $pages = ceil($source['total']/10);
    $string = array('-', ' ', '(', ')', ':', '.', '/', '\'', '"', '[', ']', 'ı', 'ç', 'ÄŸ', 'ü', 'ÅŸ', 'ö', 'Ä°', 'Ä?', 'Ãœ', 'Å?', 'Ö', 'Ç', '+', '™');
    $replace = array('', '-', '', '', '', '', '', '', '', '', '', 'i', 'c', 'g','u','s','o','I','G','U','S','O','C',' ','');



    function randtag($str){
        $font_size = rand(1,5);
        $color_array = array('black', 'blue', 'green', 'white');
        shuffle($color_array);
        $font_color = $color_array[0];
        $link = ' <a href="index.php?tag='.$str.'" style="text-decoration:none"><font size="'.$font_size.'" color="'.$font_color.'">'.$str.',</font></a> ';
        return $link;
    }

    //Update Tags
    if(isset($_GET['tag'])){
        if(ctype_alnum($_GET['tag'])){
            if(!is_numeric($_GET['tag'])){
                $check = mysql_num_rows(mysql_query("SELECT tagid FROM tags WHERE tag='$_GET[tag]'"));
                if($check == 0){
                    mysql_query("INSERT INTO tags (tag) VALUES ('$_GET[tag]')");
                }
            }
        }
    }
    $get_tags = mysql_query("SELECT tag FROM tags WHERE tag != '' ORDER BY tagid DESC LIMIT 0,30");
    $sqlinfo = mysql_fetch_assoc(mysql_query("SELECT * FROM settings"));
?>

what can i do? , any suggestions?

Hi everyone,

I have same problem as above described.
I have tried to repair table via phpmyadmin there seems ok .I have not touch php code either but this morning i received below message.Any help appreciated.

Warning: mysql_query(): Unable to save result set in C:\Inetpub\vhosts\mydm.com\httpdocs\Eyl\admin\update_tours.php on line 309

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\Inetpub\vhosts\mydm.com\httpdocs\Eyl\admin\update_tours.php on line 310
Kayıt yok !

here is the codes

<?php
include "header.php";
?>
<?php
$empty = $post = array();
foreach ($_POST as $varname => $varvalue) {
if (empty($varvalue)) {
$empty[$varname] = $varvalue;
} else {
$post[$varname] = $varvalue;
}
}
?>
<HTML>
<HEAD>
<TITLE>content.gif</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1254">
<LINK href="images/styles.css" type=text/css rel=stylesheet>
</head>
<BODY bgColor=#ffffff leftMargin=0 topMargin=0 rightMargin=0 marginwidth="0" marginheight="0" bottomargin="0">
<TABLE height=100% cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top width=49 bgColor=#888c88 height=9>&nbsp;</TD>
<TD colSpan=2 height=9>&nbsp;</TD>
<TD width=600 height=9>&nbsp;</TD>
<TD width=179 bgColor=#9fc03f><IMG height=20
src="images/home_title.gif" width=111></TD>
<TD width=17 bgColor=#9fc03f>&nbsp;</TD>
<TD width=4>&nbsp;</TD>
<TD width=30 bgColor=#8b8b8b>&nbsp;</TD></TR>
<TR>
<TD vAlign=top width=49 bgColor=#8b8b8b></TD>
<TD vAlign=top colSpan=7 rowSpan=3>
<TABLE cellSpacing=0 cellPadding=0 width="90%" align=center border=0>
<TBODY>
<TR>
<TD vAlign=top height=317>
<FONT class=title face="BankGothic Md BT" color=#888c88>Tur Gncelle</FONT><BR>
<br>
<?
/*
This script generated by CodeMaker 0.2
[email]sonate@bsdt.net[/email]
*/
include "config.php";
include "lang_turlar.php";
function searchform_turlar(){
echo "<table>\n";
echo "<form name=searchturlar method=post action=\"update_tours.php?act=search\">\n";
echo "<tr>
<td><b>"._SEARCHDATABASE."</b></td>\n";
echo "        <td><input class=\"inputbox\" type=\"text\" name=\"keyword\"> <input class=\"button\" type=submit name=Submit value=\""._SEARCH."\"></td>
</tr>\n";
echo "</form>\n";
echo "</table>\n";
} // end function searchform_turlar
function search_turlar(){
global $keyword,$offcolor,$oncolor,$tblhead;
echo ""._SEARCHRESULT."<br>";
if ($keyword=="") {echo ""._WRITEKEYWORD."";}
else{
$querysearch = "select * from turlar where tur_adi like '%$keyword%' or facility like '%$keyword%' or fiyati like '%$keyword%'";
$resultsearch = mysql_query($querysearch);
$numbersearch = mysql_numrows($resultsearch);
if ($numbersearch==0) {echo ""._RECORDNOTFOUND."";}
else if ($numbersearch>0) {
$x=0;
echo "<table border=0 cellspacing=1 cellpadding=1>\n";
echo "        <tr bgcolor=\"$tblhead\"><td>NO</td>";
echo "        <td><b>"._ID."</b></td>\n";
echo "        <td><b>"._TUR_ADI."</b></td>\n";
echo "        <td><b>"._FACILITY."</b></td>\n";
echo "        <td><b>"._FIYATI."</b></td>\n";
echo "        <td><b>"._IP."</b></td>\n";
echo "        <td><b>"._TARIH."</b></td>\n";
echo "        </tr>";
while ($x<$numbersearch)
{
if (($x%2)==0) { $bgcolor="$offcolor"; } else { $bgcolor="$oncolor"; }
$no=$x+1;
echo "<tr bgcolor=\"$bgcolor\"><td>$no</td>\n";
$id=mysql_result($resultsearch,$x,"id");
echo "        <td>$id</td>\n";
$tur_adi=mysql_result($resultsearch,$x,"tur_adi");
echo "        <td>$tur_adi</td>\n";
$facility=mysql_result($resultsearch,$x,"facility");
echo "        <td>$facility</td>\n";
$fiyati=mysql_result($resultsearch,$x,"fiyati");
echo "        <td>$fiyati</td>\n";
$ip=mysql_result($resultsearch,$x,"ip");
echo "        <td>$ip</td>\n";
$tarih=mysql_result($resultsearch,$x,"tarih");
echo "        <td>$tarih</td>\n";
echo "                </tr>\n";
$x++;
} // end while
echo "</table>\n";
} // end if
} // end else
} // end function search_turlar
function view_turlar(){
global $id;
$queryupdate = "select * from turlar where id = '$id'";
$resultupdate = mysql_query($queryupdate);
$numberupdate = mysql_numrows($resultupdate);
if ($numberupdate>0) {
$x=0;
echo "<table border=0 cellspacing=0 cellpadding=2>\n";
while ($x<$numberupdate)
{
echo "                 <tr>\n";
$id=mysql_result($resultupdate,$x,"id");
echo "<td align=right><b>Id :</b></td>\n";
echo "<td>$id</td></td>\n";
echo "                </tr>\n";
echo "                 <tr>\n";
$tur_adi=mysql_result($resultupdate,$x,"tur_adi");
echo "<td align=right><b>Tur_adi :</b></td>\n";
echo "<td>$tur_adi</td></td>\n";
echo "                </tr>\n";
echo "                 <tr>\n";
$facility=mysql_result($resultupdate,$x,"facility");
echo "<td align=right><b>Facility :</b></td>\n";
echo "<td>$facility</td></td>\n";
echo "                </tr>\n";
echo "                 <tr>\n";
$fiyati=mysql_result($resultupdate,$x,"fiyati");
echo "<td align=right><b>Fiyati :</b></td>\n";
echo "<td>$fiyati</td></td>\n";
echo "                </tr>\n";
echo "                 <tr>\n";
$ip=mysql_result($resultupdate,$x,"ip");
echo "<td align=right><b>Ip :</b></td>\n";
echo "<td>$ip</td></td>\n";
echo "                </tr>\n";
echo "                 <tr>\n";
$tarih=mysql_result($resultupdate,$x,"tarih");
echo "<td align=right><b>Tarih :</b></td>\n";
echo "<td>$tarih</td></td>\n";
echo "                </tr>\n";
$x++;
} // end while
echo "</table>\n";
} // end if
} // end function view_turlar
function add_turlar(){
global $id,$tur_adi,$facility,$fiyati,$ip,$tarih;
$query="insert into turlar (id,tur_adi,facility,fiyati,ip,tarih) VALUES ('$id','$tur_adi','$facility','$fiyati','$ip','$tarih')";
$result = mysql_query($query);
echo ""._INSERTOK."<br>\n";
echo "<a href=update_tours.php?>turlar</a>";
} // end function add_turlar
function edit_turlar(){
global $id;
echo "<center><b>"._UPDATERECORD."</b></center>";
$queryupdate = "select * from turlar where id = '$id'";
$resultupdate = mysql_query($queryupdate);
$numberupdate = mysql_numrows($resultupdate);
if ($numberupdate>0) {
$x=0;
while ($x<$numberupdate)
{
echo "<table>\n";
echo "<form name=updateturlar method=post action=\"update_tours.php?act=upd&id=$id\">";
$id=mysql_result($resultupdate,$x,"id");
$tur_adi=mysql_result($resultupdate,$x,"tur_adi");
echo "<tr valign=top>\n";
echo "<td align=right><b>"._TUR_ADI." :</b></td>\n";
echo "<td>\n";
echo "        <input class=\"inputbox\" type=\"text\" name=\"tur_adi\" value=\"$tur_adi\">";
echo "</td>\n";
echo "</tr>\n";
$facility=mysql_result($resultupdate,$x,"facility");
echo "<tr valign=top>\n";
echo "<td align=right><b>"._FACILITY." :</b></td>\n";
echo "<td>\n";
echo "    <textarea name=\"facility\" id=\"facility\">$facility</textarea>\n";
#                echo "        <input class=\"inputbox\" type=\"text\" name=\"facility\" value=\"$facility\">";
echo "</td>\n";
echo "</tr>\n";
$fiyati=mysql_result($resultupdate,$x,"fiyati");
echo "<tr valign=top>\n";
echo "<td align=right><b>"._FIYATI." :</b></td>\n";
echo "<td>\n";
echo "    <textarea name=\"fiyati\" id=\"facility\">$fiyati</textarea>\n";
//                echo "        <input class=\"inputbox\" type=\"text\" name=\"fiyati\" value=\"$fiyati\">";
echo "</td>\n";
echo "</tr>\n";
/*
$ip=mysql_result($resultupdate,$x,"ip");
echo "<tr valign=top>\n";
echo "<td align=right><b>"._IP." :</b></td>\n";
echo "<td>\n";
echo "        <input class=\"inputbox\" type=\"text\" name=\"ip\" value=\"$ip\">";
echo "</td>\n";
echo "</tr>\n";
*/
$tarih=mysql_result($resultupdate,$x,"tarih");
echo "<tr valign=top>\n";
echo "<td align=right><b>"._TARIH." :</b></td>\n";
echo "<td>\n";
echo "        <input class=\"inputbox\" type=\"text\" name=\"tarih\" value=\"$tarih\">";
echo "</td>\n";
echo "</tr>\n";
$x++;
} // end while
echo "</table>\n";
} // end if
echo "<input class=\"button\" type=submit name=Submit value=\""._UPDATE."\">\n";
echo "<input class=\"button\" type=reset name=Submit2 value=\""._RESET."\">\n";
echo "</form>\n";
} // end function edit_turlar
function upd_turlar(){
global $id, $tur_adi, $facility, $fiyati, $ip, $tarih;
$query="update turlar set id='$id', tur_adi='$tur_adi', facility='$facility', fiyati='$fiyati', ip='$ip', tarih='$tarih' where id = '$id'";
$result = mysql_query($query);
echo "<center><b>"._RECORDUPDATED."</b></center>\n";
echo "<center><b><A HREF=\"update_tours.php\">Geri</a></b></center>\n";
} // end function upd_turlar
function del_turlar(){
global $id;
$queryconfirmation = "select * from turlar where id = '$id'";
$resultconfirmation = mysql_query($queryconfirmation);
$numberconfirmation = mysql_numrows($resultconfirmation);
if ($numberconfirmation==0) {
echo "<center><b>"._RECORDNOTFOUND."</b></center>\n";
}
else if ($numberconfirmation>0) {
$x=0;
echo "<center><b>"._YOUSURE."</b></center><br><br>\n";
echo "<center><a href=update_tours.php?act=delete&id=$id>"._YES."</a> - <a href=update_tours.php?>"._NO."</a></center>";
} // end if
} // end function del_turlar
function delete_turlar(){
global $id;
$querydelete = "delete from turlar where id = '$id'";
$resultdelete = mysql_query($querydelete);
echo "<center><b>"._RECORDDELETED."</b></center>";
echo "<meta http-equiv=\"refresh\" content=\"2;URL=update_tours.php\">";
} // end function delete_turlar
function index_turlar(){
global $offcolor,$oncolor,$tblhead,$sortby,$start,$pagelimit,$id,$tur_adi,$facility,$fiyati,$ip,$tarih;
#                echo "<a href=turlar.php?act=new>"._NEWRECORD."</a><br>\n";
$pagelimit = 30;
$initstart = 0;
if (!isset($start)){$start = $initstart;}
$querylimit = " limit $start,$pagelimit ";
$nextstart = $start + $pagelimit;
$previousstart = $start - $pagelimit;
if ($sortby!=""){$sorted = " order by $sortby ";}
$query_turlar = "select  id,tur_adi,facility,fiyati,ip,tarih from turlar ";
$queryall = $query_turlar.$sorted.$querylimit;
$resultall = mysql_query($queryall);
$numberall = mysql_numrows($resultall);
if ($numberall==0) {echo ""._NORECORD."";}
else if ($numberall>0) {
$x=0;
echo "<b>"._TURLAR." "._LIST."</b>\n";
echo "<table border=0 cellspacing=1 cellpadding=1>\n";
echo "        <tr bgcolor=\"$tblhead\">\n";
echo "        <td><b><a href=\"update_tours.php?sortby=tur_adi&start=$start&pagelimit=$pagelimit\">"._TUR_ADI."</a></b></td>\n";
echo "        <td><b><a href=\"update_tours.php?sortby=facility&start=$start&pagelimit=$pagelimit\">"._FACILITY."</a></b></td>\n";
echo "        <td><b><a href=\"update_tours.php?sortby=fiyati&start=$start&pagelimit=$pagelimit\">"._FIYATI."</a></b></td>\n";
echo "        <td><b><a href=\"update_tours.php?sortby=ip&start=$start&pagelimit=$pagelimit\">"._IP."</a></b></td>\n";
echo "        <td><b><a href=\"update_tours.php?sortby=tarih&start=$start&pagelimit=$pagelimit\">"._TARIH."</a></b></td>\n";
echo "        <td colspan=3><b>"._ACTIONS."</b></td>\n";
echo "        </tr>\n";
while ($x<$numberall)
{
// changing background color for each alternate row
if (($x%2)==0) { $bgcolor="$offcolor"; } else { $bgcolor="$oncolor"; }
// retreiving data and putting it in local variables for each row
$id=mysql_result($resultall,$x,"id");
$tur_adi=mysql_result($resultall,$x,"tur_adi");
$facility=mysql_result($resultall,$x,"facility");
$fiyati=mysql_result($resultall,$x,"fiyati");
$ip=mysql_result($resultall,$x,"ip");
$tarih=mysql_result($resultall,$x,"tarih");
echo "<tr bgcolor=\"$bgcolor\">\n";
echo "        <td>$tur_adi</td>\n";
echo "        <td>$facility</td>\n";
echo "        <td>$fiyati</td>\n";
echo "        <td>$ip</td>\n";
echo "        <td>$tarih</td>\n";
echo "<td>\n";
echo "<a href=\"update_tours.php?act=edit&id=$id\">"._EDIT."</a>\n";
echo "</td>\n";
echo "<td>\n";
echo "<a href=\"update_tours.php?act=del&id=$id\">"._DELETE."</a>\n";
echo "</td>\n";
#                echo "<td><a href=\"update_tours.php?act=view&id=$id\">"._DETAIL."</a></td>\n";
echo "</tr>\n";
$x++;
} // end while
echo "</table>\n";
echo "<br><br><a href=\"update_tours.php?start=$nextstart&pagelimit=$pagelimit&sortby=$sortby\">"._NEXT." $pagelimit "._RECORD."</a>\n";
echo "&nbsp;&nbsp;&nbsp;&nbsp;\n";
echo "<a href=\"update_tours.php?start=$previousstart&pagelimit=$pagelimit&sortby=$sortby\">"._PREVIOUS." $pagelimit "._RECORD."</a>\n";
} // end if numberall > 0
} // end function index_turlar
switch($act) {
case "new":
new_turlar();
break;
case "add":
add_turlar();
break;
case "edit":
edit_turlar();
break;
case "upd":
upd_turlar();
break;
case "del":
del_turlar();
break;
case "delete":
delete_turlar();
break;
case "search":
search_turlar();
break;
case "view":
view_turlar();
break;
case "reserve1":
reserve1_turlar();
break;
default:
searchform_turlar();
index_turlar();
break;
}
?>        </TD>
</TR></TBODY></TABLE></TD></TR>
<TR>
<TD vAlign=top width=49 bgColor=#9fc03f rowSpan=2><IMG height=49 alt=""
src="images/sidecross.gif" width=49 border=0
name=sidecross></TD></TR>
<TR></TR>
</TBODY></TABLE>
</BODY></HTML>

Hi Boronia,

I have noticed that in Line 159 of the above code you have use mysql_numrows(). Please not that this is now depreciated, try changing this to: mysql_num_rows(). If you have coded it this way through all your scripts, then go through and change them to. I hope this helps:)

I am having the same problem as the original guy for my database code....can someone help please? here is the code.

<body>
<?php

	include("../misc.inc");
	mysql_connect($host,$user,$pass);
	mysql_select_db($database);
	if($HTTP_GET_VARS['id'])
	{
		$query = "SELECT * FROM guestlist WHERE eventID = '".$HTTP_GET_VARS['id']."'";
		$result = mysql_query($query);
		$nrows = mysql_num_rows($result);
		if($nrows > 0){
		$i = 0;
		$myGuests = array();
		while($row = mysql_fetch_array($result))
		{
			extract($row);
			$totalGuests += $guests;
			$myGuests[$i] = "<tr><td>".($i+1)."</td><td>$guestName</td><td>$guests</td><td>$email</td></tr>";
			$i++;
		}
		echo "<p>$nrows on guestlist, ".($nrows+$totalGuests)." expected for event.</p>";
		echo "<table width =\"600\" border=\"1\">";
		echo "<tr><th>&nbsp;</th><th>Name</th><th width=\"50\">Guests</th><th>Email</th></tr>";
		for($i=0;$i<sizeof($myGuests);$i++)
		{
			echo $myGuests[$i];
		}
		echo "</table>";
		}
		else
		{
		echo "<p>No guests.</p>";
		}
	}
	else
	{
		$currentDate = date("Y-m-d",time());
		$query = "SELECT * FROM events_entries WHERE eventDate >= '$currentDate' ORDER by eventDate";
		$result = mysql_query($query);
		$nrows = mysql_num_rows($result);
		while($row = mysql_fetch_array($result))
		{
			extract($row);
			echo "<p>-<a href=\"getguests.php?id=$id\">$eventDate: $eventName @ $eventLocation</a></p>";
		}
	}

?>
<p>-<a href="index.php?<?php echo session_id(); ?>">Back To Main</a><br />
-<a href="logout.php?<?php echo session_id(); ?>">Logout</a></p>
</body>

I am getting these 2 error messages:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Please advise....thanks a lot guys!!

i got this error plz tell me what is main problem in code

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\login\checklogin.php on line 34
Wrong Username or Password

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>


</body>
</html>

There is something wrong with your query. Print out your query (print $sql ) and tell us what does it print.

Hello, I'm new to html not to even mention mysql. I've gotten roped into keeping the company website updated and have run into an error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/thesoun1/public_html/used.php on line 206

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/thesoun1/public_html/used.php on line 325

Here is the code for the database query:

<td valign="top" colspan="3"><img src="/images/clearpixel.gif" width="15">
<center><table align="center" border="2" cellpadding="2" cellSpacing="2" bgcolor="#63c6de">
<tr>

<?php

$user = 'thesoun1_dbuser';
$pass = 'dbuserpw';
$host = 'localhost';
$db_name = 'thesoun1_soundwave';


$dbc = @mysql_connect($host, $user, $pass) or die ('Could not connect to database ' . mysql_error());

@mysql_select_db ($db_name) or die ('Could not select the database ' . mysql_error());

//echo 'Database connection succeded and table ' . $db_name . ' was selected OK.';

$query = "select * from inventory where condition = 'used' order by brand asc";

$result = @mysql_query($query);
$num_rows = mysql_num_rows($result);

if($result)
{
// echo '<td>';
echo "<tr>
<td align=\"center\"><font color=\"BLUE\">Brand</td>
<td align=\"center\"><font color=\"BLUE\">Model</td>
<td align=\"center\"><font color=\"BLUE\">Serial</td>
<td align=\"center\"><font color=\"BLUE\">Category</td>
<td align=\"center\"><font color=\"BLUE\">Condition</td>
<td align=\"center\"><font color=\"BLUE\">MSRP</td>
<td align=\"center\"><font color=\"BLUE\">Price</td>
<td align=\"center\"><font color=\"BLUE\">Comments</td>
<td align=\"center\"><font color=\"BLUE\">Website</a></td>
<td align=\"center\"><font color=\"BLUE\">Images</a></td>
<td align=\"center\"><font color=\"BLUE\">Sales</a></td>
<td align=\"center\"><font color=\"BLUE\">Buy</a></td>
</tr>\n";


while($row = mysql_fetch_array($result, MYSQL_NUM))
{
echo "<tr>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[1]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[2]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[3]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[4]</td>
<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[5]</td>";
if($row[6] == 0)
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
}
else
{
$row[6] = number_format($row[6],2);
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">$row[6]</td>";
}

if($row[7] == 0)
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>call</p></td>";
}
else
{
$row[7] = number_format($row[7],2);
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">$row[7]</td>";
}

echo "<td align=\"left\" bgcolor=\"LIGHTYELLOW\">$row[8]</td>";

if($row[9] != "")
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:website_window('$row[9]',800,600);\" onmouseover=\"if(Rollover) document['web$row[0]'].src=WEBMover.src\" onmouseout=\"if(Rollover) document['web$row[0]'].src=WEBMout.src\"><img src=\"/images/website.gif\" border=\"0\" name=\"web$row[0]\"></a></td>";
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
}

if($row[10] != "")
{
$linknumber=1;
$loopcount=0;
$gallery = explode(' ',$row[10]);
// $arr_count = sizeof($gallery);
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\">";
foreach($gallery as $imgname)
{
echo "<a href=\"javascript:create_window('$imgname',5,5);\" class=linkcolor>$linknumber</a>&nbsp;";
++$linknumber;
++$loopcount;
if($loopcount == 3)
{
echo "<br>";
$loopcount=0;
}
}
echo "</td>";
// echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"/images/$row[10]\" class=linkcolor>Image</a></td>";
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/no_images.html',500,400);\" onmouseover=\"if(Rollover) document['noimage$row[0]'].src=NO_IMAGESMover.src\" onmouseout=\"if(Rollover) document['noimage$row[0]'].src=NO_IMAGESMout.src\"><img src=\"/images/noimages.gif\" border=\"0\" name=\"noimage$row[0]\"></a></td>";
// echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><p>N/A</p></td>";
}

if($row[12] != 0)
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/sale_restrictions.html',500,400);\" onmouseover=\"if(Rollover) document['sales$row[0]'].src=R_SALESMover.src\" onmouseout=\"if(Rollover) document['sales$row[0]'].src=R_SALESMout.src\"><img src=\"/images/rs.gif\" border=\"0\" name=\"sales$row[0]\"></a></td>";
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
// echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/nosale_restrictions.html',500,400);\" onmouseover=\"if(Rollover) document['sales$row[0]'].src=NS_SALESMover.src\" onmouseout=\"if(Rollover) document['sales$row[0]'].src=NS_SALESMout.src\"><img src=\"/images/ns.gif\" border=\"0\" name=\"sales$row[0]\"></a></td>";
}

if($row[7] != 0)
{
if($row[13] == 1)
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"/cart.php?pid=$row[0]&do=Add\" onmouseover=\"if(Rollover) document['cart$row[0]'].src=CARTMover.src\" onmouseout=\"if(Rollover) document['cart$row[0]'].src=CARTMout.src\"><img src=\"/images/addtocartgreen.gif\" border=\"0\" name=\"cart$row[0]\"></a></td>";
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
// echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"><a href=\"javascript:new_window('/sale_restrictions.html',500,400);\" onmouseover=\"if(Rollover) document['cart$row[0]'].src=RS_SALESMover.src\" onmouseout=\"if(Rollover) document['cart$row[0]'].src=RS_SALESMout.src\"><img src=\"/images/rsales.gif\" border=\"0\" name=\"cart$row[0]\"></a></td>";
}
}
else
{
echo "<td align=\"center\" bgcolor=\"LIGHTYELLOW\"></td>";
}


echo "</tr>\n";
}
}
// echo '</td>';
mysql_free_result($result);


//echo '<br>Got ' . $num_rows . ' records from database.';
mysql_close($dbc);

?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.