-
$sql_result=mysql_query($query) or die("Error in Checking User".mysql_error());
-
echo $no=mysql_num_rows($sql_result);
-
if($no<>1)
-
{
-
return(false);
-
}
-
else
-
{
-
return (true);
-
}
-
In this code i have get this type of error: -
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\my\test\query\function.php on line 2
-
Can any one guide me. How is error occured?
Thank you
14 1960
You are not doing the query well.
you should pass a mysql connection to the query so that it knows where to query. - $link = mysql_connect('hostName', 'userName', 'passWord');
-
-
//then select the db
-
-
mysql_select_db('databaseName', $link);
-
-
//then you can make your queries passing the $link
-
-
$resultSet = mysql_query('SELECT * FROM Table1', $link);
-
-
//now you can check if there are results
-
if(mysql_num_rows(0 < $resultSet)){
-
echo 'yeah coolm, i have a result'
-
}
-
else{
-
echo 'wtf nothing from db';
-
}
-
Your mysql_query() doesn't return a valid resource - what is the query?
Also, you if/else block can be shortened like so: -
return ($no !== 1);
-
-
// as opposed to this:
-
if($no <> 1) {
-
return FALSE;
-
}
-
else {
-
return TRUE;
-
}
-
Billibytes beat me to it.
Anyway, couple of things: You do not have to pass a link resource to the mysql_* functions - if you do not, mysql will use the last opened connection.
Also: -
if(mysql_num_rows(0 < $resultSet)){
-
echo 'yeah coolm, i have a result'
-
}
-
else{
-
echo 'wtf nothing from db';
-
}
-
will not work, but I think that's just a typing error on your part ;) -
if(mysql_num_rows($resultSet) < 0){
-
echo 'yeah coolm, i have a result'
-
}
-
else{
-
echo 'wtf nothing from db';
-
}
-
@Markus
right, i have answered too quickly...
ok yet i have not solved my problem. so i send my three php page content.
1. index.php -
<form id="form1" name="form1" method="post" action="check.php?id=tbl1">
-
<table width="200" border="1">
-
<tr>
-
<td colspan="2">Pesonal Info Table 1 </td>
-
</tr>
-
<tr>
-
<td width="72">Name:</td>
-
<td width="112"><input name="name" type="text" id="name" value="Ashok" /></td>
-
</tr>
-
<tr>
-
<td>Address</td>
-
<td><input name="address" type="text" id="address" value="Kathmandu" /></td>
-
</tr>
-
<tr>
-
<td><input name="tbl1" type="submit" id="tbl1" value="Submit" /></td>
-
<td><input type="reset" name="Submit2" value="Reset" /></td>
-
</tr>
-
</table>
-
</form>
-
-
2. check.php -
<?php
-
foreach($_POST as $key=>$value)
-
{
-
//echo "</br>";
-
$key.":".$$key=$value;
-
//echo "</br>".$key;
-
}
-
include_once("function.php");
-
$tblname= $_GET['id'];
-
$db=new Functions;
-
$db->dbconnection();
-
if(isset($tbl1))
-
{
-
$field=array('name','address');
-
$value=array($name,$address);
-
$y=$result=$db->InsertData($tblname,$field,$value);
-
/*if($y==true)
-
{
-
echo "Success";
-
}
-
else
-
{
-
echo "Failed";
-
}*/
-
}
-
if(isset($tbl2))
-
{
-
$field=array('phone','email');
-
$value=array($phone,$email);
-
$result=$db->InsertData($tblname,$field,$value);
-
}
-
?>
-
3. function.php -
<?php
-
class Database
-
{
-
function dbconnection()
-
{
-
$link=mysql_connect("localhost","root","") or die("Failed Connecting to Database");
-
mysql_select_db("query",$link) or die("Failed Connecting To Database");
-
}
-
}
-
class Functions extends Database
-
{
-
function InsertData($TblName,$Fields,$Values)
-
{
-
$query="INSERT INTO `{$TblName}` (`".(is_array($Fields)?implode("`,`",$Fields):$Fields)."`)
-
VALUES (".(is_array($Values)?"'".implode("','",$Values)."'":$Values).")";
-
$sql_result=mysql_query($query) or die("Error in Checking User".mysql_error());
-
echo $no=mysql_num_rows($sql_result);
-
if($no<>1)
-
{
-
return(false);
-
}
-
else
-
{
-
return (true);
-
}
-
}
-
}
-
?>
-
-
But Still Error is same -
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\my\test\query\function.php on line 17
-
Try this as function.php -
class Database
-
{
-
private $link;
-
function dbconnection()
-
{
-
$this->link=mysql_connect("localhost","root","") or die("Failed Connecting to Database");
-
mysql_select_db("query",$this->link) or die("Failed Connecting To Database");
-
}
-
}
-
class Functions extends Database
-
{
-
function InsertData($TblName,$Fields,$Values)
-
{
-
$query="INSERT INTO `{$TblName}` (`".(is_array($Fields)?implode("`,`",$Fields):$Fields)."`)
-
VALUES (".(is_array($Values)?"'".implode("','",$Values)."'":$Values).")";
-
$sql_result=mysql_query($query, $this->link) or die("Error in Checking User".mysql_error());
-
-
/* This line is to debug your query */ echo "<!-- QUERY: {$query} -->";
-
-
$no = mysql_num_rows($sql_result);
-
echo ($no != 1);
-
}
-
}
-
I suggest that you go step by step.
first check that you get the data from the brower, and try to echo it.
then try to connect to the db and make a query with data you write in your file, not from $_POST
and try to output it.
and so on, you have to narrow down the search until you know where the problem comes from.
once you know where your code fails, come back and we will guide you.
This error is occur Canabeez sir, -
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampp\htdocs\my\test\query\function.php on line 18
-
Error in Checking User
-
echo() the $query variable, and post the output here. Your SQL is wrong, most likely.
-
INSERT INTO `tbl1` (`name`,`address`) VALUES ('Ashok','Kathmandu')
-
The Query vairable carried right value. but the out put error is same. -
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in D:\xampp\htdocs\my\test\query\function.php on line 18
-
Error in Checking User
-
put the $link as i told you... or a password
I have change little bit on Private into Public then it works but the new problem is aries: -
<?
-
class Database
-
{
-
public $link;
-
function dbconnection()
-
{
-
$this->link=mysql_connect("localhost","root","") or die("Failed Connecting to Database");
-
mysql_select_db("query",$this->link) or die("Failed Connecting To Database");
-
}
-
}
-
class Functions extends Database
-
{
-
function InsertData($TblName,$Fields,$Values)
-
{
-
$query="INSERT INTO `{$TblName}` (`".(is_array($Fields)?implode("`,`",$Fields):$Fields)."`)
-
VALUES (".(is_array($Values)?"'".implode("','",$Values)."'":$Values).")";
-
$sql_result=mysql_query($query, $this->link) or die("Error in Checking User".mysql_error());
-
/* This line is to debug your query */ //echo "QUERY:{$query}";
-
$no = mysql_num_rows($sql_result);
-
echo ($no != 1);
-
}
-
}
-
?>
-
-
Error is : -
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\my\test\query\function.php on line 19
-
-
Now i need to return True or False value to - $y=$result=$db->InsertData($tblname,$field,$value);
which is call from check.php page.
Ok thank you i have solved this way.. -
<?
-
class Database
-
{
-
public $link;
-
function dbconnection()
-
{
-
$this->link=mysql_connect("localhost","root","") or die("Failed Connecting to Database");
-
mysql_select_db("query",$this->link) or die("Failed Connecting To Database");
-
}
-
}
-
class Functions extends Database
-
{
-
function InsertData($TblName,$Fields,$Values)
-
{
-
$query="INSERT INTO `{$TblName}` (`".(is_array($Fields)?implode("`,`",$Fields):$Fields)."`)
-
VALUES (".(is_array($Values)?"'".implode("','",$Values)."'":$Values).")";
-
$d=$sql_result=mysql_query($query, $this->link) or die("Error in Checking User".mysql_error());
-
if($d==1)
-
{
-
return true;
-
}
-
else
-
{
-
return false;
-
}
-
/* This line is to debug your query */ //echo "QUERY:{$query}";
-
//$no = mysql_num_rows($sql_result);
-
//echo ($no != 1);
-
}
-
}
-
?>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Arjan |
last post by:
I've got the following error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/wbdfdart/public_html/wbdfforum/verwijder.php on line 13
verwijder.php
...
|
by: David Nikel |
last post by:
I am attempting to create a login script.
The following snippet of code:
$query = "select * from auth where username='$username' and
password=password('$password')";
$result =...
|
by: Fish44 |
last post by:
Ive got the following code which works great on my localserver, but
when i upload it to my service provider i get an error
"Warning: mysql_num_rows(): supplied argument is not a valid MySQL...
|
by: Dejan |
last post by:
Hi
Sorry for my terreble english.
On my local (win) comp i have apache+mysql+php 4.05
I'm counting rows using mysql_num_rows function, and everything works fine.
When i upload php file on...
|
by: 00webman |
last post by:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/html/scripts/07/view_users.php on line 15
Can anyone spot my error?!? Thanks.
<?php # Script 7.6 -...
|
by: The1corrupted |
last post by:
Okay, this has blown my entire perception of reality way out of order. First, a page was working and not five minutes later, I get this error,
Warning: mysql_num_rows(): supplied argument is...
|
by: d3vkit |
last post by:
Alright I can not figure this one out, so I'm guessing it's some simple typo and some extra eyes will help me spot it.
Here's the query (already connected to DB everything works in that respect):...
|
by: Sandman |
last post by:
Hi,
So I read the manual where it says to use mysql_affected_rows() for
everything except SELECT and SHOW, and use mysql_num_rows() for those
two, which actually return a result.
However, I...
|
by: seigaku |
last post by:
Hi everyone,
I've recently begun learning PHP and it looks like I took on too much so soon.
I'm attempting to fix a php script that detects whether or not a person is Eligible to join a...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |