So what do you get if you do:
Code: Select all
while ($row = mysql_fetch_assoc($maklumat)) {
echo '<pre>';
print_r($row);
echo '</pre>';
}Moderator: General Moderators
Code: Select all
while ($row = mysql_fetch_assoc($maklumat)) {
echo '<pre>';
print_r($row);
echo '</pre>';
}Code: Select all
<?php
die('num rows is: ' . mysql_num_rows($maklamut) . '<br />'); #DEB
?>Code: Select all
<?php
function mysqlQuery2($mysql, $line, $file)
{
$query = mysql_query($mysql) or die('sql error: ' . mysql_errno() . ' - ' . mysql_error() . '<br/>' . $line . ' | ' . $file . '<br />' . $mysql . '<br />');
return $query;
}
?>Code: Select all
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in g:\programming\phpdev\www\mmis\system\semakaduan1.php on line 35
num rows is:Code: Select all
<?php
// replaces your query() function
function mysqlQuery2($mysql, $line, $file)
{
$query = mysql_query($mysql)
or die( 'sql error: ' . mysql_errno() . ' - ' . mysql_error() . '<br/>'
. $line . ' | ' . $file . '<br />'
. $mysql . '<br />'
);
return $query;
}
function theUpdate($id)
{
$mysql = "UPDATE aduankerosakan SET status='Diproses' WHERE idAduan = '" . $id . "'";
mysqlQuery2($mysql, __LINE__, __FILE__);
echo 'UPDATE: affected rows = ' . mysql_affected_rows() . '<br />'; #DEB
}
function theSelect($id)
{
$maklumat_query = "SELECT [..name the cols..] FROM aduankerosakan
INNER JOIN tpartminor USING(idMajor)
WHERE aduankerosakan.idAduan ='" . $id . "'";
$result = mysqlQuery2($maklumat_query, __LINE__, __FILE__);
echo '$maklamut num rows is: ' . mysql_num_rows($result) . '<br />'; #DEB
return $result;
}
// set a valid value - check the table first
$id = ??;
// now see if it works..
theUpdate($id);
theSelect($id);
?>I'm sorry but I have to point this out...Try concatenation to fix the problem with $_POST, eg:
PHP:
<?php
"UPDATE aduankerosakan SET status = '" . $status . "' WHERE idAduan = '" . $_POST['id'] . "' "
?>
To get the error, you need to test for $result == false in your custom query function, ie:
PHP:
<?php
if ($result == false && ini_get('display_errors') == 1)
?>
I wouldn't recommend that method for a couple of reasons,// replaces your query() function
function mysqlQuery2($mysql, $line, $file)
{
$query = mysql_query($mysql)
or die( 'sql error: ' . mysql_errno() . ' - ' . mysql_error() . '<br/>'
. $line . ' | ' . $file . '<br />'
. $mysql . '<br />'
);
return $query;
}
Code: Select all
<?php
define("USE_DB", "mysql");
query($sql, $line = null, $file = null, $link = null)
{
// Attempt to import the resource handler from $GLOBALS['link'];
if (is_null($link))
$link = $GLOBALS['link'];
switch (USE_DB)
{
case 'mysql':
$result = mysql_query($sql, $link);
if (empty($result))
db_error($link, $line, $file);
break;
case 'pgsql':
$result = pg_query($link, $sql);
if (empty($result))
db_error($link, $line, $file);
break;
}
}
function db_error($link, $line = null, $file = null)
{
switch (USE_DB)
{
case 'mysql':
echo mysql_errno($link).': ';
echo mysql_error($link)."<br />\n";
break;
case 'pgsql':
echo pg_last_error($link)."<br />\n";
break;
}
if (!is_null($line))
echo "@ line: $line ";
if (!is_null($file))
echo "in file: $file<br />\n";
}
?>Sorry - I edited my original post. What I meant to say was make sure you set a test value which does actually exist in the table.apek wrote:what do u mean??// set a valid value according to the col type
$id = ??;
Code: Select all
affected rows = 1
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in g:\programming\phpdev\www\mmis\system\semakaduan1.php on line 55
num rows is:Code: Select all
<% Response.Buffer=True %>Hey man, nothing personal. I'm just pointing out the information. Don't take it personally. Apek requested my assistance specifically.quesadilla5 you're getting a little bit OT. If you want to discuss the code I posted could you start a new topic? I'm not sure all your comments are valid but this isn't the place to deal with them.