I keep getting the following errors. The $query produces a 1300 result list. When I run echo $query I get the following MySQL error:
[25-Aug-2016 21:38:32 America/New_York] PHP Warning: mysql_fetch_row() expects parameter 1 to be resource, null given in song.php on line 285
[25-Aug-2016 21:38:32 America/New_York] PHP Notice: Undefined variable: song_hash in song.php on line 292
$query = "select " . $query_data . " from " . $query_tables . " where " . $query_where;
//echo $query;
$result = mysql_query($query,$database);
while($row = mysql_fetch_row($result)){
$key = $row[0];
$song_hash[$key] = ($song_hash[$key] + 1);
}
$largest = max($song_hash);
In order to help you the contents of $query_data, $query_tables and $query_where needed. You can also print the error with mysql_error(). More likely you will be able to find out the solution from that output.
http://php.net/mysql_error
when you run echo query and you get those errors it simply means you don't have a query..
try hardcoding the query for debugging,
also you need to initialize your song_hash array
Related
I'm having trouble updating my postgressdb using update clause where itemid = "$_get['itemid'];
here's my sql code but it returns Warning: pg_query(): Query failed: ERROR:
$sql="UPDATE tbl_item SET itemname='".$_POST['ItemName']."', highqntythreshold='".$_POST['HQThreshold']."', lowqntythreshold='".$_POST['LQThreshold']."', qntyperunit='".$_POST['QPUnit']."', itemtype='".$_POST['IT']."', description='".$_POST['Description']."', WHERE itemid='". $_GET['itemid'] . "';";
$iteminfo = pg_query($sql);
and it also returns "Warning: pg_affected_rows() expects parameter 1 to be resource, boolean given in D:\Wamp\wamp\www\Php\CTea\UpdateItem.php on line 303"
if(pg_affected_rows($iteminfo)==1)
{
$msg = "Successfully added new Item, ".ucfirst($_POST['ItemName'])."!";
}
else
{
$msg = "Error: in saving Item data!...";
}
i think i messed up something but can't figure it out where and what i messed up.
The problem is (at least) in this part:
$_POST['Description']."', WHERE itemid='". $_GET['itemid'] . "'
There is a comma before the where, so you want:
$_POST['Description']."' WHERE itemid='". $_GET['itemid'] . "'
In general, though, you should just print out the query string after variable substitution. About 98% of the time, the error is obvious and you can fix it quickly.
i got this error message while running my Php codeigniter project :
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for mtree::insert_to_right(), called in
C:\AppServ\www\News\application\controllers\bcontroller.php on line 20
and defined
Filename: models/mtree.php
Line Number: 28
this is my model function :
function insert_to_right($row, $direct_id) {
$left_parent = $this->get_right_parent($direct_id);
$row->members_direct_id = $left_parent;
$this->db->insert('table1', $row);
$sql = "INSERT INTO table2 (child, parent)
VALUES (" . $this->db->escape($row->members_id) . ", " . $this->db->escape($left_parent) . ")";
$this->db->query($sql);
}
function get_right_parent($id) {
return $id;
}
Since the function insert_to_right($row, $direct_id) requires two arguments, either you can pass in those two variables when you call them, or you can assign default values for it like insert_to_right($row = '....', $direct_id = '...'). I don't think you can just pass in any default variable as this would insert it into the database, so I would recommend you pass in the argument from the controller.
I got this error message when running PHP Code Igniter project:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$members_id
Filename: models/mtree.php
Line Number: 33
In line 33 ($row->members_id) refer to field in my database
VALUES (" . $this->db->escape($row->members_id) . ", " . $this->db->escape($left_parent) . ")";
My model function is:
function insert_to_right($direct_id='members_direct_id') {
$left_parent = $this->get_right_parent('members_id');
$row->members_direct_id = $left_parent;
$row->members_spillover_id = $left_parent;
$this->db->insert('ajmatrix_members_table', $row);
$sql = "INSERT INTO ayman_mot (child, parent)
VALUES (" . $this->db->escape($row->members_id) . ", " . $this->db->escape($left_parent) . ")";
$this->db->query($sql);
}
Your code don't have the members_id property in row.
$row variable have only 2 properties:
$row->members_direct_id = $left_parent;
$row->members_spillover_id = $left_parent;
Somewhere in your Model where you have the db select statement, for example:
$this->db->select('field1, field2, field3, field4');
try and replace it with:
$this->db->select('*');
Worked out for me, after battling it out for weeks through forums.
Though my initial mistake was putting the statement like this:
$this->db->select('field1', 'field2', 'field3', 'field4');
~ Mistakes are the ones we make ~ (speaking for myself here, don't hit me ^_^ )
Best Regards
You're not defining $row->members_id in your code - elsewhere you're referencing a members_direct_id - is that what you meant to use perhaps?
I'm trying to calculate the number of students who've completed an their homework for an online gradebook, and I can't figure the code out...
// SELECT THE TOTAL
$gettotal = "SELECT enroll FROM student_course WHERE classID = $classID";
$showtotal = #mysqli_query ($dbc, $gettotal); // Run the query.
//THIS IS LINE 108
$numtotal = mysql_num_rows($showtotal);
echo '$numtotal';
// SELECT THOSE PASSED
$getpassed = "SELECT entry FROM grades WHERE classID = $classID AND test_result >= 80";
$showpassed = #mysqli_query ($dbc, $getpassed); // Run the query.
$numpassed = mysql_num_rows($showpassed);
//THIS IS LINE 117
echo '$numpassed';
// PERFORM THE PERCENTAGE FUNCTION
function percent($numpassed, $numtotal) {
$count1 = $numpassed / $numtotal;
$count2 = $count1 * 100;
$count = number_format($count2, 0);
echo $count;
}
//THIS IS LINE 124
percent($numpassed, $numtotal);
I get the following error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 108
$numtotal
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 117
$numpassed
Warning: Division by zero in on line 124
0
Okay - while I thank everyone for their concern removing the # ... no one noticed that the problem was using mysqli_query and then mysql_num_rows. It needed to be changed to mysqli_num_rows.
Thanks though :)
Chances are the query has failed.
Also mysql_query will return FALSE on error so you can check for that.
$result = mysql_query('SELECT * WHERE 1=1');
if (!$result) {
die('Invalid query: ' . mysql_error());
}
Btw: You might want to remove the # operator before mysql_query so you see if something goes wrong there.
Remove error suppression (#) in your code and use inspection methods print_r($var) and var_dump($var) to verify the returned database call values.
I need some help understanding the correct way to mix variables with strings like this. I have tried every configuration I can think of and I keep getting an error.
<?php
include('connect.php');
foreach($_GET['item'] as $key=>$value) {
mysql_query("UPDATE userprojectlist SET category_display_order = '$key' WHERE category_id = '$value' ");
}
?>
Notice: Undefined index: item in updatedb.php on line 3
Warning: Invalid argument supplied for foreach() in pdatedb.php on line 3
Is item an array in the url like item[]? If it's not that's the reason you get that error, you cannot iterate through a non-iterator object!
Also get rid of the single quotes around the values if they are numeric and use string concatenation,
"UPDATE userprojectlist SET category_display_order = " . $key . " WHERE category_id = " . $value . ";"
Notice: Undefined index: item in updatedb.php on line 3
This error is saying that there's no such variable as $_GET['item'] defined. You probably did not pass $_GET['item'] to this page.
Warning: Invalid argument supplied for foreach() in pdatedb.php on line 3
Thus because of the previous error, you get this, as $_GET['item'] is not an array.
The error has nothing to do with the SQL code.
mysql_query('UPDATE userprojectlist SET category_display_order = ' . $key . ' WHERE category_id = ' . $value );
or
mysql_query("UPDATE userprojectlist SET category_display_order = $key WHERE category_id = $value" );
This is assuming both variables are integers.