ballouta Posted December 26, 2010 Share Posted December 26, 2010 Hello I am trying to create a simple update function. but it is giving me syntax error. May you please review my code The function call: function update_article_stats ($article_num) The Function Declaration in the functions.php function update_article_stats ($article_num) { $query = "UPDATE `articles_content` SET `cnt` = cnt+1 WHERE `num` = '$article_num' "; $result = mysql_query($query); } Thank you so much Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 26, 2010 Share Posted December 26, 2010 "but it is giving me syntax error." Most important part: What is the syntax error? in case it helps, you don't call a function with function. update_article_stats($article_num); Quote Link to comment Share on other sites More sharing options...
ballouta Posted December 26, 2010 Author Share Posted December 26, 2010 Thanks the syntax error is gone, in the functions.php I have include ("global.inc.php"); and global.inc.php is the same directory with functions.php The code is giving me a warning message, but I can see in the DB that the update is working (increasing number) why is this warning Warning: include(global.inc.php) [function.include]: failed to open stream: No such file or directory in /home/ahlussu/public_html/www.website.info/inc/functions.php on line 3 Thank you Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 26, 2010 Share Posted December 26, 2010 can't tell without seeing the code. is anything including functions.php? Quote Link to comment Share on other sites More sharing options...
ballouta Posted December 26, 2010 Author Share Posted December 26, 2010 Nothing at all, no html or php code except the above function. Quote Link to comment Share on other sites More sharing options...
ballouta Posted December 26, 2010 Author Share Posted December 26, 2010 in the showarticle.php I have: $article_num = $_GET['cid']; //check if the article number exists, function call check_artnum ($makalah_num); //the function declaration function check_artnum ($article_num) { $query = mysql_query ("Select * FROM `articles_content` where `num` = '$article_num' "); $num_rows = mysql_num_rows($query); if ($num_rows == 0 || $num_rows < 0) { return $article_num = '101';} else {} } is the logic and sytanx correct? I tried ti write a wrong article number in the URL it gave me a blank page. Thank you Quote Link to comment Share on other sites More sharing options...
PHPTOM Posted December 26, 2010 Share Posted December 26, 2010 in the showarticle.php I have: $article_num = $_GET['cid']; //check if the article number exists, function call check_artnum ($makalah_num); //the function declaration function check_artnum ($article_num) { $query = mysql_query ("Select * FROM `articles_content` where `num` = '$article_num' "); $num_rows = mysql_num_rows($query); if ($num_rows == 0 || $num_rows < 0) { return $article_num = '101';} else {} } is the logic and sytanx correct? I tried ti write a wrong article number in the URL it gave me a blank page. Thank you This code doesn't actually output to the page, so hence the blank page. Personally I would do this, though I haven't checked that it works: function check_artnum ($article_num) { $query = mysql_query("Select * FROM `articles_content` where `num` = '".$article_num."'"); $num_rows = mysql_num_rows($query); return ($num_rows == 0) ? '101' : $article_num; } echo check_artnum($_GET['cid']); Quote Link to comment Share on other sites More sharing options...
ballouta Posted December 27, 2010 Author Share Posted December 27, 2010 @ PHPTOM: Thank you so much, i like they way you code, u're prof. Maybe I should have explained this for you before. The variable $article_num is used in the show_article.php page several times, sometimes to get the article index titles, the body, and other attached or related articles. one problem, if i enter 105 for article number in the page URL, the article number (e,.g 105) is wrong and should be fixed by this function and set it to 101 as default value. How do I keep the correct $article_num value available for other queries and functions? Thank you so much Quote Link to comment Share on other sites More sharing options...
ballouta Posted December 27, 2010 Author Share Posted December 27, 2010 I got an idea $article_num = check_artnum ($makalah_num); it is working thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.