PHP - Storing Clicks On A Button - How?
Hello PHPFreaks,
I have emerged yet again with another question. I currently have a fully operational Minecraft Voting for Diamonds script (Don't turn away because you saw Minecraft, this has nothing to do with it), and want to enhance it; though a 'Top Voters' list. Now, basically the script goes like this Login Page > Main Page with links > Rewarding Script > thank you message. On the main page with links, once all links are clicked on, you click a 'Get Rewarded' button. I want to track who clicks this, and how many times a month it is clicked by them. Only 1 click on the button is allowed per day, with the use of cookies. This means the maximum amount of clicks on it per month, per user would be something around 30. I store the players usernane in the cookies, and if they have voted today, but that is all. The Top Voters list would look something like this: Userwhatever - 6 Votes Blarg - 4 votes Someone - 2 votes And so on... I want an ordered list of users which have voted that month. 'Votes', would be the amount of times that 'Get Rewarded' had been clicked. How can I make this? I will also require it to reset all votes of the first of every month, how do I do this? Many thanks! Similar TutorialsHello! I am designing a user registration form which has some radio buttons for people to select. I am confused as to how I should store the value selected by the user into the database. Here is my code, just in case. <li id="li_2" > <label class="description" for="element_2">I am a </label> <span> <input id="element_2_1" name="element_2" class="element radio" type="radio" value="1" /> <label class="choice" for="element_2_1">Student</label> <input id="element_2_2" name="element_2" class="element radio" type="radio" value="2" /> <label class="choice" for="element_2_2">Staff</label> <input id="element_2_3" name="element_2" class="element radio" type="radio" value="3" /> <label class="choice" for="element_2_3">Member</label> <input id="element_2_4" name="element_2" class="element radio" type="radio" value="4" /> <label class="choice" for="element_2_4">Other</label> </span> </li> Hi all, i am creating a custom blog for practise, how do we add no of clicks in database to that topics visitors clicks. I have added 'clicks' field in table 'blog_posts'. Now how to add and increment value by 1 when visitors visits that topic ? Alright more on my affiliate page which you guys helped me build last night. Thanks again I want to count the number of times one of the affiliates is clicked. So each one has to have its own impression number. I have my array set up like so: - i see that impression is now 0 and needs to be changed to a variable etc like $aff_blah1_impressions // affiliates array for affiliates page $affiliates = array( array( "title" => "aff_blah1", "image" => "http://aff_blah1.net/images/aff_blah1.png", "href" => "http://aff_blah1.net/", "start_date" => "1/1/2011", "impressions" => "0" ), array( "title" => "aff_blah2", "image" => "http://aff_blah2.net/images/aff_blah2.png", "href" => "http://aff_blah2.net/", "start_date" => "1/1/2011", "impressions" => "0" ), array( "title" => "aff_blah3", "image" => "http://aff_blah3.net/images/aff_blah3.png", "href" => "http://aff_blah3.net/", "start_date" => "1/1/2011", "impressions" => "0" ), ); // affiliates array end I have seen some examples but they all use a text file. Is there any way to have it stored in the database? I was thinking it would somehow be in the link with like a onClick (which is java) that would run a php function. What i am trying to figure out is the best way to store it and have only one function for impressions made on each affiliate. Any keyword search terms or links would be very helpful! Can also contact through AIM: MadLittleMods@gmail.com This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321849.0 Hey all, THe problem I am having is even when I check the checbox, it still sends a value of 0 to the php array and hence nothing is ever updated: Code: [Select] <input type="checkbox" name="approved[1]" value="1" checked="checked" /> <input type="checkbox" name="approved[3]" value="0" /> <input type="checkbox" name="approved[4]" value="0" /> So the second item is not checked by default. But even when I check it, my post array contains this: Code: [Select] array(2) { [1]=> string(1) "1" [3]=> string(1) "0" } Notice the "0". It should be "1" now since I checked the second option. This is the function: Code: [Select] function update(){ $vanity_url = new VanityUrl(); $checkbox = $this->input->post('approved'); //this is same thing as $_POST if(isset($checkbox)){ foreach($checkbox as $key => $value){ $vanity_url->where('id',$key)->get(); $vanity_url->approved = (int)$value; $vanity_url->save(); $vanity_url->check_last_query(); } } } That check_last_query() function outputs this: Code: [Select] UPDATE `vanity_urls` SET `approved` = 1 WHERE `id` = 1 UPDATE `vanity_urls` SET `approved` = 0 WHERE `id` = 3 So despite checking the second option it still sets it to 0. Thanks for response. How can I make a link or banner to expire after x number of clicks on it? Can you see any problems with the code below? It doesn't work. What I am trying to do is quite straightforward. The links on my site look like this: go.php?id=1&url=usa go.php?id=1&url=uk go.php?id=2&url=usa go.php?id=2&url=uk When a visitor clicks on one of these links, I want to grab the values of the id and url parameters, count the click, and redirect the visitor. Here's the error that I get when I try the code: Quote Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\sites\go.php on line 18 Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\sites\go.php:18) in C:\xampp\htdocs\sites\go.php on line 19 <?php $conn = mysql_connect('localhost','username', 'password') or trigger_error("SQL", E_USER_ERROR); mysql_select_db('database', $conn) or trigger_error("SQL", E_USER_ERROR); $id = intval($_GET['id']); $url = intval($_GET['url']); mysql_query("UPDATE urls SET click_counter = click_counter+1 WHERE id=$id"); if ($url=="usa") $href = "SELECT usa FROM urls WHERE id=$id"; elseif ($url=="uk") $href = "SELECT uk FROM urls WHERE id=$id"; elseif ($url=="aus") $href = "SELECT aus FROM urls WHERE id=$id"; elseif ($url=="can") $href = "SELECT can FROM urls WHERE id=$id"; else $href = "SELECT int FROM urls WHERE id=$id"; $qry = mysql_query($href); list($href)=mysql_fetch_row($qry); header("Location:$href"); mysql_close($conn); ?> So, on my website, i have added a "last active" feature, so if someone is surfing the site, they can view when another users last page visit was. so, every second, +1 is added to the $ts variable what i have now, working and all, shows ONLY "NOW!", or ONLY "1 second", ONLY "___ seconds ago"... and so on I have tred over, and over, and over to fix this to my liking, with more instances available, as an example, my current script will show somebody who is 13 months and 26 days inactive, just as "1 year", i want to see the "1 year, 1 month, and 26 days inactive"... or even simpler, just so it displays days/minutes/seconds/NOW! function howlongtil($ts) { $ts=$ts - time(); if ($ts<1) // <1 second return " NOW"; elseif ($ts==1) // <1 second return $ts." second"; elseif ($ts<60) // <1 minute return $ts." seconds"; elseif ($ts<120) // 1 minute return "1 minute"; elseif ($ts<60*60) // <1 hour return floor($ts/60)." minutes"; elseif ($ts<60*60*2) // <2 hour return "1 hour"; elseif ($ts<60*60*24) // <24 hours = 1 day return floor($ts/(60*60))." hours"; elseif ($ts<60*60*24*2) // <2 days return "1 day"; elseif ($ts<(60*60*24*7)) // <7 days = 1 week return floor($ts/(60*60*24))." days"; elseif ($ts<60*60*24*30.5) // <30.5 days ~ 1 month return floor($ts/(60*60*24*7))." weeks"; elseif ($ts<60*60*24*365) // <365 days = 1 year return floor($ts/(60*60*24*30.5))." months"; else // more than 1 year return floor($ts/(60*60*24*365))." years"; }; anyone know how? Im making a application but many users can access it at the same time, also the data that needs to be stored into the database in 3 parts firstly the user will enter some details the comany will fill out the reamining details and the user will then accept or decline the companies proposal. The issue im havign will it be easier to just store all of this information into session variables and then save them into the database at the end when all of the details are ready ? Thank You Alright, the register/login system is fully working with sql injection, BUUUT now I want to store their IP Address. WHOLE new function that I've never dealt with before. So I need some help. Am I doing something wrong? I have the IPadd in the database as INT(10) and then I went down to another drop down list and hit unsigned. I feel like I'm doing something wrong with the field in the database.. { $_SERVER['REMOTE_ADDR'] = $IPadd; $sql = "INSERT INTO Member (username,createDate,password,firstName,email,IPadd) VALUES ('$username',NOW(),md5('$password'),'$firstName','$email',inet_aton('$IPadd'))"; mysqli_query($cxn,$sql); $_SESSION['auth']="yes"; $_SESSION['username'] = $username; header("Location: testing.php"); } Let's see if I can explain this ok.. Basically I have a site and the page product categories use dynamically created URL's. I want to use these URL's to put on my products so I can list all the categories each product is in. But, as these URL's are not stored anywhere I'm not sure how to go about calling them. Is the best way going to be to modify the site to store the page URL's in MySQL? Or could they be stored within variables in PHP? A little guidance would be great! Thanks in advance Hi, when a user logs out, I want to store the last activity in for the user. I have a db table users: userID userName userPassword lastSession lastActivity ===== ======= ========== ======== ======= 1 bob password 2011-08-09 About.html 2 dre passwords 2011-09-23 Home.php here is logout script: =============== Code: [Select] <?php //run this script only if the logout button has been clicked if(array_key_exists('logout', $_POST)) { require("connect.inc"); $username=$_POST["username"]; $updateLastSessionQuery=mysql_query("UPDATE users SET lastSession=NOW() WHERE userName='$username'"); // end session and redirect //empty the $_SESSION array $_SESSION = array(); session_destroy(); header("Location: xmlShredderLogin.php"); exit; }//END IF for when logout submitted ?> here is Index.php: ============= Code: [Select] <?php session_start(); if(isset($_SESSION["isAuthenticated"])) { require("logout.inc.php"); $username=$_POST["username"]; //print $username."<br />"; print ' <html> <head><title>Home</title></head> <body> <form id="logoutForm" name="logoutForm" method="post" action=""> <input name="logout" type="submit" id="logout" value="Log out" /> <input type="hidden" name="usernameHidden" value='; print$username; print '/> </form>'; mysql_connect("localhost","root"); mysql_select_db("someDB"); $getUserInfoQuery=mysql_query("SELECT lastSession,lastActivity FROM users WHERE userName='$userName'"); $getUserInfo=mysql_fetch_assoc($getUserInfoQuery); print "Last session: ".$getUserInfo["lastSession"]."<br />"; print "Last activity: ".$getUserInfo["lastActivity"]."<br />"; Let's say the last page the user is on is Index.php, so what do I use to track the last page they are on?? I can't user a form b/c if I have to type in the last activity, that's nonsense! So far I have only figured out how to store the current time in last session (but this doesn't work either). I just want to track the last page and then have a switch such as: switch(type) case 1: $lastActivity="About.html"; case 2: $lastActivity="somethingelse.php"; Any help much appreciated! Hi, i would like to know what is the best method to store a picture. Currently what happens, is each user has a different avatar, which when uploaded comes in a folder called Avatar, in my website folder and is also stored as a BLOB in mysql. I would like to know is this ok to store all avatars in one folder or some other step should be used and if so could some one guide me to a good tutorial. As I would also like to make an option, where people could upload their pictures, is it safe to store pictures in the same folder for all users or some how create a different folder for each user. Hello all, I'm having some problems with a script ive written which is designed to allow me to send a message to all the users of my site. the form works fine, the SQL works fine but im having a problem with storing php variables and outputting them in the message. The form has a field named "allmessage" which is where i'll type my message, I'll type something like "Hello $Name" and store the text as $allmessage = $_POST['allmessage']; example script //loops through each member while ($row=mysql_fetch_array($sql)) { //sets variables $ID=$row['ID']; $Name=$row['MemberName']; $Email=$row['Email']; $content_type = 'Content-Type: text/plain; charset="UTF-8"' ; mail($Email, $allsubject, $allmessage, $content_type); } //loop ends send us a copy of the mail mail("me@me.com", $allsubject, $allmessage, $headers ); Now what I want to be outputted in the email is "Hello John" or "Hello Paul" but what I get is "Hello $Name". Any ideas?! Hey guys, What would you recommend to store db values for later? the only thing I can come up with is doing it this way: $result = mysql_query("SELECT * FROM users WHERE name='$user'"); while($row = mysql_fetch_array($result)) { } { and then using the $row['dbvariable'] later is that the best way? Can anyone tell me whats wrong with this: The file uploads fine, the url however does not get posted to the database? I added a 'or die' but it didn't execute...Do I need to move the query higher up the script? <?php include ('base.php'); $id = $_GET['id']; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "imgs/pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } $file = $_FILES["file"]["name"]; $sql = "UPDATE `chillp_security`.`staff` SET `picture` = \'imgs/pictures/$file\' WHERE `staff`.`id` = $id;"; ?> Code: [Select] <?php $going=''; $name='<span id="name"></span>'; echo "$name"; //results : stevengoh --- wanted $going=substr($name, 1, 17); echo "$name"; //results : <span id="going"> ---- don't want ?> Is it possible to store in php the results of variable id="going" javascript instead of <span id="going"></span>?. Hi, I am struggling with a form in php. I am trying to add a form by using the include function. I want to include thsi form on all pages so it would be very useful if I can save the current page name somewhere so that I can use to validate the form. For example, this is the form I am trying to include. <?php if(!empty($errors)) { if(isset($errors['sendError'])) { echo '<p><strong class="error">There was a problem with our system please contact us directly.</strong></p>'; } else { echo '<p><strong class="error">Please check the form below for errors.</strong></p>'; } } ?> <form action="index.php" method="post" id="form1"> <p> <label><?php if(isset($errors['name'])) { echo '<span class="error">'; } ?>Name<font color="red">*</font>: <?php if(isset($errors['name'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['name']; ?>" name="name" size="60" align="right" style="background:#EEF5A4" /> <label><?php if(isset($errors['company'])) { echo '<span class="error">'; } ?>Company: <?php if(isset($errors['company'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['company']; ?>" name="company" size="60" align="right" /> <label><?php if(isset($errors['phone'])) { echo '<span class="error">'; } ?>Phone Number: <?php if(isset($errors['phone'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['phone']; ?>" name="phone" size="60" align="right" /> <label><?php if(isset($errors['email'])) { echo '<span class="error">'; } ?>Email<font color="red">*</font>: <?php if(isset($errors['email'])) { echo '</span>'; } ?></label> <input id="search1" id="complete" type="text" value="<?php echo $form['email']; ?>" name="email" size="60" align="right" style="background:#EEF5A4" /> <label><?php if(isset($errors['enquiry'])) { echo '<span class="error">'; } ?>Enquiry: <?php if(isset($errors['enquiry'])) { echo '</span>'; } ?></label> <textarea id="search1" id="complete" textarea name="enquiry" rows=4 cols=40 value="<?php echo $form['enquiry']; ?>" name="enquiry" size="60" align="right"></textarea> </p> <p> <input type="submit" class="formbutton" value="Submit" /> <input type="reset" class="formbutton" value="Reset" /> </p> <p><font color="red">*</font> Denotes a required field</p> </form> Because I am going to use this form on all pages, I would like it to include whatever the filename is rather than index.php in the first line of the form so that when the user clicks submit, it will stay on the same page but validate the form based on the mandatory fields. I don't know if the question is clear. I would very much appreciate any help at all. Thank you very much. Quote i want to store a value from a database and use it as variable in php code can anyone help me out in this code i want to store value of copies in a php variable and want that it should be more than 0 (zero) for furthur calculations $update_book="update book set copies=copies-1 where bookid='$bookid'"; $result=mysql_query($update_book,$linkID1); if($result) { print "<html><body background=\"header.jpg\"> <p>book successfully subtracted from database</p></body></html>"; } else { print "<html><body background=\"header.jpg\"> <p>problem occured</p></body></html>"; } I don't know why but I'm failing hard at GoogleFu today. I can't find a tutorial on how to store a session id in a cookie and then call it on the server. session_id says it replaces the cookie it makes if you set the id via session_id, even if it's the same id...but I'm not sure if that really matters. Can anyone help point me in the right direction to a good tutorial/give me some insight on this subject? I want to store the session id in a cookie to keep a user logged in for 2 weeks or so (unless they log out of course). I did find some tutorials on how to re-route the session handlers for open/close/read/write session functions which allow me to store the session in a database. Is this what I want? Sorry for the newbie question, Thanks, Justin |