PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
require ("dbhandler.php");
// ill create a dummy var just so the script thinks it's set
$add_article = "Yes";
// first we'll run a query to find out the value of the items in the database
$query = "SELECT Articles, Downloads, Comments FROM stats" or die(mysql_error());
$statvalues = mysql_query($query);
$values = mysql_fetch_array($statvalues, MYSQL_ASSOC) or die(mysql_error());
// now lets make the newly created variables look nicer
$old_articles = $values['Articles'];
$old_downloads = $values['Downloads'];
$old_comments = $values['Comments'];
// now we need to add 1 to the current value and then reinsert it into the database
// lets create a function so i dont have to constantly write out the same script for each
// condition
if (isset($add_article))
{
// this is run only if someone has added an article to the database
$new_article_result = ($old_articles + 1);
// now we have the new value we will run an update statement
$update = "UPDATE stats SET Articles='$new_article_result' WHERE Articles='$old_articles' AND Downloads='$old_downloads' AND Members=$old_members AND Comments=$old_comments'" or die (mysql_error());
$affectedrows = mysql_affected_rows();
print "Added Successfully!\n The New Value of Articles Is --> $new_article_result ";
// this script is not working for some stupid reason, MYSQL
// is not throwing up an error and my conditional print statement is printing
// it even tells me how many rows it has just affected (1)
// however when i check the database its not updated it
// any ideas?
}
else
{
print " var not set";
}
?>
<?php
print "
Old Articles = $old_articles\n
Old Downloads = $old_downloads\n
Old Comments = $old_comments\n
New Articles = $new_article_result\n
The query has affected $affectedrows rows
"
?>
are you sure your checking in the correct place in MySQLFront and PHPmyAdmin? I have done that before, looking for updated data in the wrong DB or table.
May sound stupid but worth double checking cod your code is definatley fine from what i can see, and if it is saying the rows are updated.
Also, are you sure the data been updated, is not the same as the data already in the DB?
ive refreshed it like at least 200+ times and viewed it in both programs/scripts MySQL Front and PHPmyAdmin
i have the default fields set to 0 but that has nothing to do with it
also the feels are 'unsigned' whatever that means however that is default and ive never changed it before (or this time) so i cant see that being the problem
$update = "UPDATE stats SET Articles='$new_article_result' WHERE Articles='$old_articles' AND Downloads='$old_downloads' AND Members=$old_members AND Comments=$old_comments'" or die (mysql_error());
$update = "UPDATE stats SET Articles='$new_article_result' WHERE Articles='$old_articles' AND Downloads='$old_downloads' AND Members=$old_members AND Comments=$old_comments'" or die (mysql_error());
$update = "UPDATE stats SET Articles='$new_article_result' WHERE Articles='$old_articles' AND Downloads='$old_downloads' AND Members=$old_members AND Comments=$old_comments'" or die (mysql_error());