Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question SQL not submiting Value

    I have this script to increase the value of a table by +1 every time it a specific page is loaded. I have the code, but somewhere there is a problem and it does not post to the databse. If I just run the core of the command in PHP my admin it works, but not form the site. Can someone please help me out?
    Code:
    $total = $db->query("UPDATE url SET total = total + 1 WHERE url='$show'");
    Last edited by wee493; 04-20-2009 at 12:40 AM.

  • #2
    New Coder
    Join Date
    Aug 2008
    Posts
    90
    Thanks
    5
    Thanked 3 Times in 3 Posts
    You have to show us the rest of your code regarding this.

    -Steven

  • #3
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BigRusky View Post
    You have to show us the rest of your code regarding this.

    -Steven
    This is what interprets & redirects to the Shortned URL
    Code:
    if(is_dir($show)){
    		header("location: $SITE_URL/$show");
    	} else {
    		// check up against DB for URL
    		// if adding .gif or .jpg, then still process redirect, but ignore .gif or .jpg
    		$ext=substr($show,-4,4);
    		if($ext=='.gif') $show=str_replace('.gif','',$show);
    		if($ext=='.jpg') $show=str_replace('.jpg','',$show);
    		if($db->query("SELECT destination FROM url WHERE url='$show'")){
    			// url exist
    			//$total2 = $db->query("SELECT total FROM url WHERE url='$show'");
    			$db->query("UPDATE url SET total = total + 1 WHERE url='$show'");
    			
    			header('location: '.$db->row["destination"]);
    		} else {
    			// invalid short URL, dispaly homepage
    		}
    	}
    Here is the entire Code
    Code:
    <?
    include_once 'master_config.inc.php';
    include_once 'db.class.inc.php';
    include_once 'HtmlTemplate.class.php';
    
    $page=new HtmlTemplate("templates/index.htm");
    
    /* $rnd_url=chr(rand(97,122)).rand(0,9).chr(rand(65,90)).chr(rand(97,122)).rand(0,9);
    $newurl = $_POST['newurl'];
    if (empty($newurl)) {
        $newurl = $rnd_url;
    } */
    
    $db=new db($DB_LOCALHOST,$DB_DATABASE,$DB_USERNAME,$DB_PASSWORD);
    $db1=new db($DB_LOCALHOST,$DB_DATABASE,$DB_USERNAME,$DB_PASSWORD);
    
    // take care of register global
    foreach($_POST AS $key => $value) { ${$key} = $value; }
    foreach($_GET AS $key => $value) { ${$key} = $value; }
    
    $number3 = $db->query("SELECT id FROM url ORDER BY `id` DESC");
    $number2 = mysql_fetch_array($number3);
    $number = $number2 + 720;
    
    $recent_url = $db->query("SELECT url FROM url ORDER BY `id` DESC");
    $recent = mysql_fetch_array($recent_url);
    //$recent = $db->row["url"];
    
    $page->Set("SITE_URL",$SITE_URL);
    $page->Set("SITE_NAME",$SITE_NAME);
    $page->Set("NUMBER",$number);
    $page->Set("RECENT",$recent);
    
    
    // set title,description,keywords meta tags to default title
    $page->Set("page_title","$META_TITLE");
    $page->Set("page_description","$META_DESCRIPTION");
    $page->Set("page_keyword","$META_KEYWORDS");
    
    
    /* ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// */
    
    if($_POST["shorten_submitted"] && $_POST["destination"]!=''){
    	$page->Set("destination",$_POST["destination"]);
    	// check up again DB for destination URL
    	if($db->query("SELECT * FROM url WHERE destination='".$_POST["destination"]."'")){
    		// url exist
    		$db->fetch();
    		$mini_url=$db->row["url"];
    		$page->Set("mini_url","$SITE_URL/$mini_url");
    		$page->Set("message","This URL has been shortened before, here it is again:");
    	} else {
    		// url does not exist, create new mini url			
    		// generate random mini url and check against url database for existence
    		do {
    			
    		$rnd_url=chr(rand(97,122)).rand(0,9).chr(rand(65,90)).chr(rand(97,122)).rand(0,9);
    			
    		} while ($db->query("SELECT id FROM url WHERE url='$newurl'"));
    		if(!mysql_query("INSERT INTO url (url, destination) VALUES ('$rnd_url','".$_POST["destination"]."')")){
    			// insert failed
    			$page->Set("message","Database INSERT Failed.  Please contact Webmaster.");
    		} else {
    			$page->Set("mini_url","$SITE_URL/$rnd_url");
    			$page->Set("message","The WiURL URL is:");
    		}
    	}
    	$page->Set("result",$page->CreatePage("templates/result.htm"));
    	
    } else {
    	// redirect
    	if(is_dir($show)){
    		header("location: $SITE_URL/$show");
    	} else {
    		// check up against DB for URL
    		// if adding .gif or .jpg, then still process redirect, but ignore .gif or .jpg
    		$ext=substr($show,-4,4);
    		if($ext=='.gif') $show=str_replace('.gif','',$show);
    		if($ext=='.jpg') $show=str_replace('.jpg','',$show);
    		if($db->query("SELECT destination FROM url WHERE url='$show'")){
    			// url exist
    			//$total2 = $db->query("SELECT total FROM url WHERE url='$show'");
    			$db->query("UPDATE url SET total = total + 1 WHERE url='$show'");
    			
    			header('location: '.$db->row["destination"]);
    		} else {
    			// invalid short URL, dispaly homepage
    		}
    	}
    }
    echo $page->CreatePage();
    
    ?>

  • #4
    New Coder
    Join Date
    Aug 2008
    Posts
    90
    Thanks
    5
    Thanked 3 Times in 3 Posts
    The only thing, I can think of is did you check
    Code:
    "SELECT destination FROM url WHERE url='$show'"
    in phpmyadmin?

    And also, check if you can update anything in your database from that page. Maybe you just didn't connect to the database on that page.

  • #5
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BigRusky View Post
    The only thing, I can think of is did you check
    Code:
    "SELECT destination FROM url WHERE url='$show'"
    in phpmyadmin?

    And also, check if you can update anything in your database from that page. Maybe you just didn't connect to the database on that page.
    Ya I ran that code in phpmyadmin and it works just fine. Also that page is connected to the database just fine. Could it be that my databse version is 4.1 and not 5.0? I'm going to upgrade it right now anyways, so I'll report back if I have any luck.

    If u want to check it out the site is http://wiurl.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •