Jump to content

Simple customized function


ballouta

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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']);

Link to comment
Share on other sites

@ 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.