Parabolundertow Posted March 2, 2007 Share Posted March 2, 2007 Hi there, I am trying to run a counter so when a person clicks on a banner, it updates the db with a new number. I have called the banner link: ad_counter.php?id=1 I have a field in my table called ad_counter Then im setting a recordset to GET the data. I am using: $last = $row_Recordset1['ad_counter']; $add = 1; $ad_counter = $last + $add; What I want to do is auto form fill and update the database, and proceed to their website without this process even being seen. Is this possible without having to push the form submit button. A basic statistics gatherer for businesses who wish to advertise. Thankyou Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/ Share on other sites More sharing options...
skali Posted March 2, 2007 Share Posted March 2, 2007 I have called the banner link: ad_counter.php?id=1 Modify this link to modify banner link to: ad_counter.php?id=1&do=update On your ad_counter.php page if($_GET['do']=='update && !empty($_GET['id']){ //update your database counter. } Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-197669 Share on other sites More sharing options...
Parabolundertow Posted March 2, 2007 Author Share Posted March 2, 2007 hi skali Thanks for the quick reply. if($_GET['do']=='update && !empty($_GET['id']){ //update your database counter. } How does this know which field in the table to update? I want to update the field (ad_counter) Should this work? Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-197673 Share on other sites More sharing options...
skali Posted March 2, 2007 Share Posted March 2, 2007 if($_GET['do']=='update && !empty($_GET['id']){ mysql_query('update your_table set ad_counter = ad_conter +1 where ad_id = {$_GET['id']}'); } Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-197677 Share on other sites More sharing options...
Parabolundertow Posted March 2, 2007 Author Share Posted March 2, 2007 that looks great - but am i missing something - it wont let me close the ?> text all red from there (Dreamweaver) Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-197683 Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 you are missing a ' here if($_GET['do']=='update use if($_GET['do']=='update' Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-197689 Share on other sites More sharing options...
Parabolundertow Posted March 2, 2007 Author Share Posted March 2, 2007 awesome thankyou !!! Sometimes the more you stare at something the more you can't see it. Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-197726 Share on other sites More sharing options...
Parabolundertow Posted March 4, 2007 Author Share Posted March 4, 2007 Hi guys, Im still trying to make this work ... Im hoping to call the ad_counter from the table using $_GET, add 1 and update, then go to a url. here is my script: <?php require_once('Connections/Farout.php'); ?> <?php if (isset($_GET['id'])) { $colname_rsBusinessclick = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']); } mysql_select_db($database_Farout, $Farout); $query_rsBusinessclick = sprintf("SELECT * FROM hub_directory WHERE id = '%s'", $colname_rsBusinessclick); $rsBusinessclick = mysql_query($query_rsBusinessclick, $Farout) or die(mysql_error()); $row_rsBusinessclick = mysql_fetch_assoc($rsBusinessclick); $totalRows_rsBusinessclick = mysql_num_rows($rsBusinessclick); $ad_counter = $row_rsBusinessclick['ad_counter']; if($_GET['do']=='update' && !empty($_GET['id']){ mysql_query('update hub_directory set ad_counter = ad_counter +1 where id = {$_GET['id']}'); $updateGoTo = "http://www.mywebaddress.com.au"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?> Where am I going wrong ... ?? Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-198969 Share on other sites More sharing options...
roopurt18 Posted March 4, 2007 Share Posted March 4, 2007 You can only include variables inside of double quoted, not single quoted, strings. Change the single quotes around: 'update hub_directory set ad_counter = ad_counter +1 where id = {$_GET['id']}' to double quotes. Link to comment https://forums.phpfreaks.com/topic/40827-how-do-i-auto-insert-to-db-without-a-form/#findComment-199011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.