Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-16-2012, 09:21 AM   PM User | #1
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Incrementation not incrementing correctly

Hi guys.

Ill post you the code and then ill talk about it

PHP Code:
$viewcount_update mysql_query("UPDATE dynamic_pages SET view_count=`view_count` +1 WHERE page_name='" $securename "'") OR die(); 
Ok as you can see its a sql query which is basically updating the dynamic_pages by updating the view count by 1.

The problem is its increasing by 2.

How is this possible? Its even stating +1

Can someone point me the the correct path to a solution.

Thanks
devinmaking is offline   Reply With Quote
Old 10-16-2012, 10:20 AM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
This should work:

PHP Code:
$viewcount_update mysql_query("UPDATE dynamic_pages SET view_count=(view_count +1) WHERE page_name='" $securename "'") OR die(); 
Why'd you escape view_count in the second and not in the first instance? You should probably drop the back-tick as it's usually for MySQL reserved words, so it's usually used when escaping variables when used for table names as they may contain any name.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Old 10-16-2012, 10:46 AM   PM User | #3
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by Redcoder View Post
This should work:

PHP Code:
$viewcount_update mysql_query("UPDATE dynamic_pages SET view_count=(view_count +1) WHERE page_name='" $securename "'") OR die(); 
Why'd you escape view_count in the second and not in the first instance? You should probably drop the back-tick as it's usually for MySQL reserved words, so it's usually used when escaping variables when used for table names as they may contain any name.
Thanks for the input, put its exactly the same, its still incrementing +2 instead of +1
devinmaking is offline   Reply With Quote
Old 10-16-2012, 10:56 AM   PM User | #4
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Then my guess is that you are running that query twice by mistake. Try looking into the code that triggers that query to run, i'm sure that it triggers it twice.

Try having a variable $i=1 just outside the loop that runs the query. Set it to increase by one. Then set it to echo at the very bottom of the script. If $i has a value of 3, then the problem is that the query is run twice by mistake.

Or better, post the whole code here.
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk

Last edited by Redcoder; 10-16-2012 at 10:59 AM..
Redcoder is offline   Reply With Quote
Old 10-16-2012, 11:12 AM   PM User | #5
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by Redcoder View Post
Then my guess is that you are running that query twice by mistake. Try looking into the code that triggers that query to run, i'm sure that it triggers it twice.

Try having a variable $i=1 just outside the loop that runs the query. Set it to increase by one. Then set it to echo at the very bottom of the script. If $i has a value of 3, then the problem is that the query is run twice by mistake.

Or better, post the whole code here.
I have double checked the code, its not duplicating anywhere.

Here is the whole page including included pages:

FRONTSIDE:
PHP Code:
<?php 

require_once("applications/configuration/connection.php");
require_once(
"applications/configuration/settings.php");
require_once(
"applications/controllers/Index/homepage.php");

?>
<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width">

<title><?php echo $meta_title ;?></title>

<meta name="description" content="<?php echo $meta_description ?>" />

<meta name="keywords" content="<?php echo $meta_keyword ?>" />
<meta http-equiv="Content-language" content="en" />
<meta name="language" content="english, EN" />
<meta name="rating" content="General" />
<meta name="distribution" content="Global" />
<meta name="robots" content="index, follow" />
<meta name="revisit-after" content="1 Day" />
<meta name="email" content="info(at)tinaadams.co.uk" />
<meta name="copyright" content="UBL Designs" />
<link rel="shortcut icon" href="" />
<link rel="bookmark icon" href="" />
<link href="/css/main.css" rel="stylesheet" type="text/css">

<script src="/js/jquery.min.js"></script>
<script>

$(document).ready(function() {
    
    $("<select />").appendTo(".navigation");
    $("<option />", {"selected": "selected","value"   : "","text" : "Navigation Menu"}).appendTo(".navigation select");
    $(".navigation ul li a").each(function() {var el = $(this);
    $("<option />", {"value"   : el.attr("href"),"text"    : el.text()}).appendTo(".navigation select");});
    $(".navigation select").change(function() {
        window.location = $(this).find("option:selected").val();
    });
});
</script>

<?php require_once("bodies/googleanalytics.php"); ?>

</head>

<body>

<?php require_once("bodies/left-column.php"); ?>

<div class="clear"></div>

<div class="right_column">

    <div class="webwrap">
    
        <div class="middlewrap1">
        
            <div class="middlewrap2">
            
                <div class="innerwebwrap">
                
                    <?php require_once("bodies/slider.php"); ?>
                    
                    <div class="clear"></div>
                
                    <h1><?php echo $page_title ?><span></span></h1>
                
                    <div class="clear"></div>
                
                    <p><?php echo nl2br($page_content) ; ?></p>
                
                    <h2>Events &amp; Services We Offer<span></span></h2>
                
                    <?php echo images_nav() ; ?>
                
                </div>
        
            </div>
        
        </div>
    
    </div>
    
</div>

</body>

</html>
settings.php:

PHP Code:
<?php

$getsettings 
mysql_query("SELECT email,maintainance_mode,facebook,twitter,linkedin FROM settings WHERE id=1") OR die();
$fetchsettings mysql_fetch_assoc($getsettings);

$websites_email stripslashes($fetchsettings["email"]);
$websites_maintainance_mode stripslashes($fetchsettings["maintainance_mode"]);
$websites_facebook stripslashes($fetchsettings["facebook"]);
$websites_twitter stripslashes($fetchsettings["twitter"]);
$websites_linkedin stripslashes($fetchsettings["linkedin"]);

if(
$websites_maintainance_mode == 1){
    
header("Location: /maintainance-mode/");
    die();
}
Homepage.php:

PHP Code:
<?php
require_once("./Libs/sanitise.php");
$viewcount_update mysql_query("UPDATE static_pages SET view_count=(view_count +1) WHERE id=1") OR die();
//page details
$apage "home";
$query mysql_query("SELECT * FROM static_pages WHERE id=1") OR die();
$fetch_page_info     mysql_fetch_assoc($query);

$page_title         stripslashes($fetch_page_info["page_title"]);
$meta_title         stripslashes($fetch_page_info["meta_title"]);
$meta_description     stripslashes($fetch_page_info["meta_description"]);
$meta_keyword         stripslashes($fetch_page_info["meta_keyword"]);
$page_content         stripslashes($fetch_page_info["content"]);

//imaged navigation details
function images_nav(){
    
    
$slug = new sanitiseClass();
    
    
$image_query mysql_query("SELECT page_name,mini_image,page_title FROM dynamic_pages WHERE islive=1 ORDER BY page_name ASC") OR die();
    
$query_num mysql_num_rows($image_query);
    if(
$query_num 0){
    
    
$list '';
        
    
$list .= '<div class="elements">';
    
$list .= '<ul>';
    
    
$list .= '<li>';
    
$list .= '<img src="/Resource/Navigation/weddingflowers.jpg" alt="Wedding Flowers In And Around The Burton &amp; Derby Areas" height="185" width="185">';
    
$list .= '<div class="elopac">';
    
$list .= '<p><a href="/wedding-flowers-in-burton-and-derby/" class="elementtitle">Wedding Flowers</a></p>';
    
$list .= '<a href="/wedding-flowers-in-burton-and-derby/"><img src="/images/view.png" alt="View Info"></a>';
    
$list .= '</div>';
    
$list .= '</li>';
    
    
$list .= '<li>';
    
$list .= '<img src="/Resource/Navigation/736492floristry-classes-small.jpg" alt="Flower Classes, Flower Courses, Flower Arranging In And Around The Burton &amp; Derby Areas" height="185" width="185">';
    
$list .= '<div class="elopac">';
    
$list .= '<p><a href="/flower-arranging-classes-in-burton-and-derby/" class="elementtitle">Flower Classes</a></p>';
    
$list .= '<a href="/flower-arranging-classes-in-burton-and-derby/"><img src="/images/view.png" alt="View Info"></a>';
    
$list .= '</div>';
    
$list .= '</li>';
        
        while(
$fetch_image mysql_fetch_assoc($image_query)){
            
$imagenav_name stripslashes($fetch_image["page_name"]);
            
$mini_image stripslashes($fetch_image["mini_image"]);
            
$imagenav_title stripslashes($fetch_image["page_title"]);
            
$list .= '<li>';
            
$list .= '<img src="/Resource/Navigation/' $mini_image '" alt="' $imagenav_title '" height="185" width="185">';
            
$list .= '<div class="elopac">';
            
$list .= '<p><a href="/' $slug->sluggify($imagenav_name) . '/" class="elementtitle">' $imagenav_name '</a></p>';
            
$list .= '<a href="/' $slug->sluggify($imagenav_name) . '/"><img src="/images/view.png" alt="View Info"></a>';
            
$list .= '</div>';
            
$list .= '</li>';
        }
        
    
$list .= '</div>';
    
$list .= '</ul>';
        
        return 
$list;
        
    } else {
        return 
"No Navigation Has Been Created Yet";
    }
    
}
I have not given connection file because that is database connection file and also the sanitise file, its just stripping slashes, mysql_real_escape etc etc.

As you can see this is not duplicating the code
devinmaking is offline   Reply With Quote
Reply

Bookmarks

Tags
incrementation, mysql, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:53 AM.


Advertisement
Log in to turn off these ads.