This question already has answers here:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result [duplicate]
(6 answers)
Closed 8 years ago.
I am getting a warning message which I don't understand why and unable to resolve, (see below)
Warning: Supplied argument is not a valid MySQL result resource in /detail.php on line 34
Here is my code:
$rs = mysql_query($strSQL);
$strSQL = "SELECT * FROM <tablename> WHERE id=" . $_GET["serviceName"];
// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) **(line 34) here ***
{
echo $row['ID']."<br />";
echo $row['serviceName']."<br />";
// Close the database connection
mysql_close();
?>
</dl>
<p>Return to the list</p>
</body>
</html>
thanks in advance, I am not getting any of the data on this webpage either,thanks...singhy
The query is failing - you need to wrap quotes around strings in MySQL:
$strSQL = "SELECT * FROM gu_service_cat WHERE id = '" .
$_GET["serviceName"] . "'";
plus, the $rs should be BELOW the $strSQL...
You need to do it like this
$strSQL = "SELECT * FROM gu_service_cat WHERE id=" . $_GET["serviceName"];
$rs = mysql_query($strSQL);
Because before setting value to the variable you are using it in the query. This is why it is throwing the error.
Related
This question already has answers here:
Can I mix MySQL APIs in PHP?
(4 answers)
Closed 5 years ago.
Cant figure out why my query isn't returning the 'make'. I've checked the SQL many times.
$DBConnect = #mysqli_connect("host.com", "name","pass", "database")
Or die ("<p>Unable to connect to the database server.</p>". "<p>Error code ". mysqli_connect_errno().": ". mysqli_connect_error()). "</p>";
$query = "SELECT make FROM inventory";
$makeresult= #mysql_query($DBConnect, $query);
while($row = mysql_fetch_array($makeresult)) {
$options .="<option>" . $row['make'] . "</option>";
}
You're using a mysqli connection but trying the deprecated mysql functions.
try mysqli_fetch_array() instead
This question already has answers here:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result [duplicate]
(6 answers)
Closed 9 years ago.
<?php
{
session_start();
include "dbconnect.php";
$target1=$_SESSION['target1'];
echo $target1;
$query = "SELECT * FROM userpictures where pictures = $target1";
$result = mysql_query($query);
var_dump($result);
while($row=mysql_fetch_object($result))
echo $row;
{
$_SESSION['picid1']=$row['picid'];
//$_SESSION['picid1']=$row->picid;
echo $_SESSION['picid1'];
}
}
?>
it is returning me the output as
images/2101.jpgbool(false)
Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource
it is giving the target1 but not the picid
please help.
Try this, Added ' - pictures = '$target1'
$query = "SELECT * FROM userpictures where pictures = '$target1' ";
$result = mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_object($result))
{
$_SESSION['picid1']=$row->picid;
echo $_SESSION['picid1'];
}
Use,
$row->picid;
instead of
$row['picid']
Note: Use mysqli_* fucntions or PDO instead of mysql_* functions(deprecated)
This question already has answers here:
Warning: mysql_query(): 3 is not a valid MySQL-Link resource
(4 answers)
Closed 9 years ago.
ERROR:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /var/www/247QC/system/core.php on line 21
Invalid query: Whole query: SELECT * FROM users WHERE username='matt' AND password='5657572fc913e2d2a9548ba4f4'
From my knowledge I have not done anything wrong in my code but I thought I would ask, since the last time I used MySQL was 2 years ago, things might of changed.
I am wondering what is the error and how do i fix it, I am at the point after googling for the last hour and results saying it was a connection issue and after testing it was connecting to the server correctly (using the hostname not IP address)
The MySQL engine it is using is InnoDB and Collation latin1_swedish_ci
code
$r_hostname = "monitor";
$r_username = "QCSYSTEM";
$r_password = "123456";
$link = mysql_connect($r_hostname,$r_username,$r_password);
$db = mysql_select_db('QCSYSTEM', $link);
$Password = sha1($_POST['password']);
$username = $_POST['username'];
$query = sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'",
mysql_real_escape_string($username),
mysql_real_escape_string($Password));
$result = mysql_query($query,$db);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
} else {
print "success";
}
The second argument to mysql_query should be a link identifier. You are using $db as the second argument, which is nothing but a boolean value. Try this..
$result = mysql_query($query,$link);
or just don't pass any second argument.
This question already has answers here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(2 answers)
Closed 6 years ago.
I am at prototype stage so I have error_reporting(-1); at my 1st row. Despite this, I have no php error but php prints 'could not get data'.
As I understood from php.net manual and stackoverflow similar cases, my $sorgula returns FALSE. But why? Can you help, regards
//i am sure that i am connected to db
if ($sorgula = mysqli_query($dbc, "SELECT * FROM tb_yazilar ORDER BY kolon_sn"))
{
while ($satir = mysqli_fetch_array($sorgula, MYSQLI_ASSOC))
{
echo $satir['kolon_yazar'].' - '.$satir['kolon_baslik'].' - '.$satir['kolon_yazi'].' - '.$satir['kolon_etiketler'].' - '.$satir['kolon_ytarihi'].' - - - - ';
}
}
else
{
echo 'could not get data';
}
mysqli_close($dbc);
try to use mysqli_error in your code .
procedural example:
$sorgula = mysqli_query($dbc, "SELECT * FROM tb_yazilar ORDER BY kolon_sn")
or error_log(mysqli_error($dbc));
I used this and it worked: without the if, once it extracts, go back and add the if. :)
require 'db.php';
$query = "SELECT * FROM thoughts";
$result = mysqli_query($conn, $query);
while($row=mysqli_fetch_assoc($result)) {
echo "<td>" . "TEXT: ". $row['text'] . "</td>";
}
mysqli_close($conn);
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
okay so here is my code.
<?php
include 'connect.php';
$id = addslashes($_REQUEST['id']);
$image = "SELECT * FROM images WHERE id=$id";
$result = mysql_query($image);
$imagearray = mysql_fetch_assoc($result);
$realimage = $imagearray['image'];
header("Content-type: image/jpeg");
echo $realimage;
?>
the page uses GET to get the id but then it gives me this error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a6289454/public_html/get.php on line 9
var_dump(mysql_error()); will help you find the error message. But most likely thing is you need quotes:
$image = "SELECT * FROM `images` WHERE `id`='".$id."'";
I think the problem might be in addslashes(), try mysql_real_escape_string() instead.
Why are you adding slashes to $_REQUEST['id']? It should be an integer
Try this code:
if(is_numeric($_REQUEST['id'])){
$q = "SELECT * FROM images WHERE id = " . $id; // Don't put variables in strings!
$rs= mysql_query($q) or die("There is an error in the query:<br>" . $q . "<br><br>The error is: ". mysql_error()); // Throw and error if there is one.
$result = mysql_fetch_assoc($rs);
} else { die('Not a valid ID'); }
Also for good practice use require_once('connect.php'); rather than include 'connect.php';
$image = "SELECT * FROM images WHERE id=$id";
$result = mysql_query($image) or die(mysql_error());
Try that
Also for your $id use type casting it's a simple solution to a simple problem
$id = (int) $_REQUEST['id'];