...

View Full Version : SQL not submiting Value



wee493
04-19-2009, 11:50 PM
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?


$total = $db->query("UPDATE url SET total = total + 1 WHERE url='$show'");

BigRusky
04-20-2009, 02:40 AM
You have to show us the rest of your code regarding this.

-Steven

wee493
04-20-2009, 02:53 AM
You have to show us the rest of your code regarding this.

-Steven

This is what interprets & redirects to the Shortned URL


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


<?
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();

?>

BigRusky
04-20-2009, 03:23 AM
The only thing, I can think of is did you check
"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.

wee493
04-20-2009, 03:40 AM
The only thing, I can think of is did you check
"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/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum