Program executes even with warning in php [duplicate] - php

This question already has answers here:
Mysql_fetch_assoc(): supplied argument is not a valid MySQL result … [duplicate]
(3 answers)
Closed 8 years ago.
I have a php code where I just query to insert rows into table via POST method every thing happens fine with WARNING ,I couldn't figure out why is that a warning message
WARNING MESSAGE IS:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a266/public_html/poster.php on line 9
CODE IS:
include "db.php";
$sql=mysql_query("INSERT INTO tb1 (col1,col2) VALUES ('$_val1', '$_val2')");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
$result="inserted";
NOTE :Value is perfectly inserted into table and returns "inserted" message But why is that warning..?

INSERT just returns true or false.There is no result to fetch with INSERT query.

Related

PHP Fatal error: Uncaught Error: Call to a member function execute() on boolean [duplicate]

This question already has answers here:
Call to a member function execute() on boolean in [duplicate]
(5 answers)
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 1 year ago.
I am trying to SELECT data from 1 database and insert into another, but I have problem in INSERT.
I get this error PHP Fatal error: Uncaught Error: Call to a member function execute() on boolean when I run my code.
MY CODE
<?php
include 'db_acc.php';
include 'db_sat.php';
$sql = "SELECT created_at,updated_at
FROM satellite1.show_activity";
$result=$conn1->query($sql);
while($row = $result->fetch_assoc()) {
echo "$row[updated_at]"; // I can get the value
$sql2 = "INSERT INTO analysis_account.currency SET
id=0,
currency_code='MYR',
currency_rate= 3.500,
currency_unit= 100,
base_currency= 1,
created_by= 2,
updated_by= 2,
created_at= '2021-05-17 14:10:32',
updated_at = ".$row["updated_at"].", // But I cant insert the value
curr_hidden = 1 ";
$query=$conn2->query($sql2);
}
$conn2->close();
?>
The problem is I can get the value of $row[updated_at] but I cant insert it into other database table, the connection is no problem because if I change $row[updated_at] into '2021-05-17 14:10:32' then the insert statement work.
I checked my connection, column names, symbols there are no problem of them. I really dont know what to do to solve the error.
Your INSERT query is missing quotes around the timestamp value. Just change
updated_at = ".$row["updated_at"].",
to
updated_at = '".$row["updated_at"]."',
This would fix the insert functionality but your code remains susceptible to SQL injection attacks. Please avoid simple string concatenation in your SQL queries and prefer prepared statements with placeholders.

Mistake deal with mysql query: "Warning: mysql_fetch_array() expects parameter 1 to be resource" [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 8 years ago.
When I restart my page I received following mistake:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
on this string:
while($row=mysql_fetch_array($emp_query)){ $id=$row['history_id'];"
What I did wrong in this code? Without following words in my MySQL query:
"WHERE user Like"
my code is work.
My code
<?php
$emp_query=mysql_query("SELECT * FROM `history` WHERE user LIKE $login_session");
while($row=mysql_fetch_array($emp_query)){ $id=$row['history_id'];
?>
<td>........</td>
<?php }?>
There is a problem with your SELECT query that's why it through error on mysql_fetch_array , try this way & use % if you want to match like '$login_session%' or '%$login_session' or '%$login_session%'
$emp_query=mysql_query("SELECT * FROM `history` WHERE user LIKE '".$login_session."'");
NB: move on to mysqli or PDO as adeneo advised

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource 22 [duplicate]

This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource
(31 answers)
Closed 8 years ago.
I don't understand why I am getting this error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL
result resource
My code is:
$alreadyMember = mysql_fetch_assoc(mysql_query("SELECT id FROM members WHERE emailAddress='{$_SESSION['register']['email']}'"));
I am also getting the error here:
$alreadyRegistered = mysql_fetch_assoc(mysql_query("SELECT confirm_code FROM memberstemp WHERE emailAddress='{$_SESSION['register']['email']}'"));
If mysql_query() fails, it returns FALSE instead of a MySQL result resource.
So basically mysql_query() is failing and you are passing FALSE to mysql_fetch_assoc() instead of the resource you are supposed to.
You have to run mysql_query() separately and check if it returns FALSE before proceeding, in which case you print mysql_error() to learn what went wrong.
It is best to separate query and the fetching of result for easier debugging and prevent unnecessary error, like:
$query = "SELECT id FROM members WHERE emailAddress='{$_SESSION['register']['email']}'";
$result = mysql_query($query) or die("Error : ".mysql_error.__LINE__);
if ($result) // Test if result has no error
{
$alreadyMember = mysql_fetch_assoc($result);
}
However, it is highly recommended to use prepared statements using PDO to prevent sql injection instead of simple mysql() extensions.

Mysql_fetch_array(): supplied argument is not a valid MySQL result [duplicate]

This question already has answers here:
Mysql_fetch_array supplied argument is not a valid MYSQL result
(4 answers)
Closed 9 years ago.
$query_user2 = mysql_query("SELECT TOP 1 * FROM $var WHERE id = (rand() * (SELECT MAX(id) FROM $var))");
$estrai2 = mysql_fetch_array($query_user2);
Problem: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Why? :/
TOP 1 is a sql server ( not MySQL ) command to select the first row, remove that and add LIMIT 1 to the end of the query.
you might want to alter your question. The problem is your query, not the "supplied argument is not a valid mysql result"

Linking PHP with mySQL problem [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home2/wizardso/public_html/tab1_content.php on line 6
this is the error that i am getting when i uploaded my db-driven webpage to my web-hosting. The same webpage was running smoothly on my localhost/ server. But its not working over the internet. Please HELP.
UPDATE
These are the contents of my file tab1_content.php
<?php
$query="select * from subcatagory where catagory_id='c001'";
$res=mysql_query($query,$con);
$query_cat="select * from catagory where catagory_id='c001'";
$res_cat=mysql_query($query_cat,$con);
$current_cat=mysql_fetch_assoc($res_cat);
?>
That error most likely results from the fact that there is something wrong with the mysql_query ("result resource") that you are calling mysql_fetch_assoc() on. Try running just the query and see what errors are returned.
All the error you posted tells you is that something went wrong with the query, it could be anything from a MySQL database connection problem to a typo in your script. Please show us your code so we can see what exactly is causing the error.
echo mysql_error();
Edit
Your code appears to look OK- are you sure that there is table within your database called "catagory" (then again- are you sure it's not "category"?), and that within that database is a record with a catagory_id of "c001"?
To test this, try echoing mysql_affected_rows(); , this gives the number of rows "affected" by the last query. If you get 0, then that means that there is no such record.
Whatever result set you're passing to mysql_fetch_assoc() is invalid because the query with mysql_query() did not complete. Check the mysql error with mysql_error()
Check your Database connectivity settings i hope that it may be one of the reason for the empty result set.
Thanks

Categories