PHP - Creating A Like System
I am in the process of creating a like system for a personal website that I am working on. I am trying to pull information from one database and use that to place info into another database. When I do I get resource error #15.
This is my code that I have so far Code: [Select] function like_add() { $last = $_GET['l']; $first = $_GET['f']; $ip = $_SERVER['REMOTE_ADDR']; $like_sql = "Select * from `counter` where first = ' $first ' and last = '$last '"; $like_result = mysql_query($like_sql); $likes = '<p class="like_button"> Likes '; while ($like_row = mysql_fetch_assoc($like_result)) { $like = $like_row['likes']; $likes .= " $like"; } $likes .= '</p>'; echo "$likes"; echo '<form name="like_add_form" action="" method="POST" class="like_add"> <input type="submit" name="like_add" class="like_add_button" value="Like Me" /> </form>'; if (isset($_POST['like_add'])) { $page_id = "SELECT `page_id` FROM `counter` WHERE first = '$first' AND last = '$last'"; $page_id_result = mysql_query($page_id); echo $page_id_result; <----- Here I am trying to pull information from a field in my database to use as a variable and to place in the second database $voted = mysql_query("Select * FROM `liked_ip` where ip ='$ip' AND page_id='$page_id_result'"); <----- Here I want to use the information from the first table to place in the second one if (mysql_num_rows($voted) != 0) { echo "You have all ready liked this post"; } else { mysql_query("INSERT into `liked_ip`(id,page_id,ip) VALUES ('$page_id_result','$ip')"); } if (mysql_num_rows($voted) == 0) { mysql_query("UPDATE counter SET `likes` = `likes` + 1 where first = '$first' AND last = '$last'"); } } } I know that I have to be doing something so simple that I am just not seeing it this late at night. I may even be completely wrong in all of this. If someone could please help me out I would appreciate it very much. Similar TutorialsHi guys, As a uni student i have to reference alot and my uni has its own prefered system. I would like to make referencing as easy as possible. http://library.scotch.vic.edu.au/research/biblios/ScotchBib/index.htm has a neat system that makes referencing quite easy. My question is how would i start the coding. When the form is sent all it does is string together the inputed text and numbers. What would this code look like and how could i display it in a 'Select All' Box? im tying to design and make a routing system for my mvc framework but im wondering the best way to do this if anyone could help on how the design pattern would be. im thinking i would have a route config file which would contain all the routes for each file routes.config <?php $routes = array('news' => 'news/index'); ?> then the routing class which would get the correct route depeding on the request class and get the dispatch class to load the controller and action? if anyone could help on the best way to do this that would be great...thanks Hi, I have a database of products but I am finding it diffult to understand how to categorise each product and build a site for it. Can I do something like this: $category = ( $gamesconsoles = ( playstation, xbox, wii ) $personalhygiene = ( electric toothbrush, electric razor, electric shaver) ) So I have PHP code which identifies a 'Playstation' as a $gamesconsoles. It then enters a 'gamesconsoles' tag into the database in a category field. I then I have link on my site which looks something like this on the homepage: productrange.php?category="gamesconsoles" class="menulink">Games Consoles</a> I then link to a productrange.php page which has in it: $category = category; if (isset($_GET['category'])) { $id = $_GET['category']; } I then echo all the producys from the database which come under the category of 'gamesconsoles'. Or am I completely mad and it should be done differently. If so please advise. hello dear PHP-Fans - greetings to you - and a happy new year!! i set up a WAMP-System on my openSuse 11.4 system. In order to learn as much as i can bout PHP i want to do some tests and write some scripts. Well the WAMP is allready up and running. Now i try to give the writing access to the folder mkdir /srv/www/ where the php-scripts should go in... i want to give write permission to all to all files in /srv/www As root I generally: mkdir /srv/www/ chown <webmaster usrername> /srv/www/ /srv/www/ should be readable and traversable by all, but only writeable by it's owner (the user designated as the webmaster.) can i do this like mentioned above,... Love to hear from you greetings db1 Hi all I have been looking though loads of tutorials regarding log in method for websites (not APIs), and cant help find that they are outdated. So I am asking what is the correct way to create a log in system using php? Modern websites use JavaScript for asynchronous web requests so this requirement should also be catered for. APIs and mobile apps use access tokens which is very secure if implemented correctly. Can we use the token principle for websites? As the way I see it that most php log in systems use php sessions and they create a session and save some data in this session when the user successfully authenticates, however the session id is held in a cookie so if the cookie is stolen then they have access to your account. API access tokens are expired and refreshed periodically so is there such a implementation method for web sites too?
Hi this is my login script i do have the html if you need to see it please ask & i was wondering if anyone would be kind enough to tell me how i can get my ban system to work Thanks
<?php require 'connect.php'; if(isset($_POST['submit'])) { $username = $_POST['username']; $password = $_POST['password']; //Prevent hackers from using SQL Injection $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql = "SELECT * FROM $tbl_name WHERE username='$username' AND password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); $user_level = $_GET['user_level']; $_SESSION['user_level'] = $user_level; if($count == 1) { $_SESSION['username']; $_SESSION['password']; header("Location: index.php"); } else { echo "Please check the username and password you entered is correct."; } if($_SESSION['user_level'] == 0) { $_SESSION['username']; $_SESSION['password']; header("Location: index.php"); } else if($_SESSION['user_level'] == -1) { die(); header("Location: banned.php"); } else if($_SESSION['user_level'] < -1) { die(); echo "An error has occurred please contact your administrator."; } else if($_SESSION['user_level'] == 1) { $_SESSION['username']; $_SESSION['password']; header("Location: admin.php"); } } ?> Edited by Tom8001, 23 November 2014 - 12:18 PM. i am trying to add a like system to my forum similar to facebook where it shows how many people like a post. this is my code so far: $like_list = ""; $likes = explode("|", $post_info['post_likes']); $amount_likes = count($likes); $ac_likes = ($amount_likes / 2); $slice = array_slice($likes, 0, 4, true); $remain = array_slice($likes, 4, $ac_likes, true); $remain_num = count($remain); if ($ac_likes >= 4) { for($i=0; $i<$ac_likes; $i+=2) { $like_list .= $likes[$i].", "; } $like_list .= " and $remain_num others like this"; } elseif ($amount_likes == 1 ) { $like_list .= "0 people like this"; } elseif ($ac_likes == 1) { $like_list = implode(", ", $likes); $like_list .= " likes this"; } else { $like_list = implode(", ", $likes); $like_list .= " like this"; } $post_info['post_likes'] contains data like: Code: [Select] user1|123456789|user2|123456789 where the number is the timestamp. unfortunatly $like_list prints the username and the timestamp when i would like it to only display the username. This means printing every 2nd element in the array starting from 0. I have seen this done with for loops but i am not using one therefore i am stuck. Any ideas? and is this the best database setup for likes? the post_likes column is added on to the end of the post table. Hi there, I am a student from the UK and I am taking PHP and mySql programming for the first time. I have done a bit of python and html before. I do have some experience with PHP though.
I need to create a project for my coursework. My system will be an MVP system (Cricket) where scores will be input and then MVP scores obtained. I wanted to know if anyone has any experience with this and thus could helpfully guide me in the right direction with resources and anything that could be deemed relevant.
I am more than happy to explain further and send my prototype over. Many thanks. I've created a template system. I've got a function to assign a page (the templates are in /template/skin). It all works fine in the main root, but if I had a directory it won't work. $dir = "template/skin"; That is found in template/ I need to be able to assign the template even in directories. I need help coming up with a better combat system for my PHP RGP-MMO. Is anyone interested? Right now it is basically offense vs. defense. Whichever is greater wins, but is honestly getting dull. Total Offense = User Total Units + User Unit Upgrades + User Unit Bonuses. Total Defense = Enemy Total Units + Enemy Unit Upgrades + Enemy Unit Bonuses. I'm busy with a small storage system for my site, but i encounter some problems with it. I have successfully managed to get all products from the order, and traced on what spots those product are in the warehouse. It looks like this atm http://img37.imageshack.us/img37/7302/tableordereng.jpg this is the code i have atm (sorry i program in dutch, i hope its abit understandable) Code: [Select] <?php $query = "select * from `orderregel` WHERE `ordernr`='".$ordernr."'"; $row = mysql_fetch_array( $query ); echo "<table border=1 width=680 bgcolor=#FFFFFF> <tr> <th width= 100>artikelnummer</th> <th width= 100>productnaam</th> <th width= 40>Plaats</th> <th width= 40>aantal in magazijn</th> <th width= 40>aantal nodig</th> </tr> </table>"; foreach ( self::find_by_sql($query) as $user) { $query2 = "select * from magazijn WHERE artikelnr = ".$user->artikelnr.""; $row = mysql_fetch_array( $query ); foreach ( self::find_by_sql($query2) as $magazijn) { echo "<table class= order_overzicht border= 0 width= 680>"; echo "<tr> <td width= 100>".$magazijn->artikelnr."</td> <td width= 100>".$magazijn->productnaam."</td> <td width= 40>".$magazijn->magazijn_plaats."</td> <td width= 40>".$magazijn->aantal."</td> <td width= 40>".$user->aantal."</td> </tr> </table>"; } } ?> The problem i have now is, that i want it to do the following. for example someone orders 430 packages of Haribo Kers Cola (see imageshack upload). I first want it to empty spot 16 in the wherehouse. Only when spot 16 is empty, i want it to go to the next spot (19) wich contains the same product. the end result would be something like this: http://img690.imageshack.us/img690/6246/tableorderneweng.jpg i hope you guys can help me out on this one, becouse i have no clue how i can resolve this problem thanks in advance (Sorry btw for my bad english ) im working on a point system for my forum where points are awarded based on actions taken. $scores = array( 'login' => 1, 'editor' => 10 ); so if a user logs in then they will be awarded 1 point, if they edit their post then they get 10 points etc. So in my login process page i process the login then award the points that it is worth with $score['login']. Everything works fine. My problem is that this is a forum package like phpbb and mybb where people download the package and can install their own forum. So i want them to be able to add to the points list. For example the admin chooses to award 10 points for every post that is made. how would i go about implementing this? the points categories would be in the database but what happens in the post processing page when i add the post to the database? how would i know that the admin wants some points awarded? the database would look like so: id title points 1 post 10 but the title can change based on the admins choosing of words. I hope i explained this ok. Hello, Basically i am following this tutorial -: http://tutorialzine.com/2010/06/simple-ajax-commenting-system/ for a website I am creating. But in that tutorial when you write a comment you add a name, I was wondering is it possible instead for my website to use the users username as I have a login system that I created from folowing a tutorial on the same site. I am new to PHP and web creation so please keep the comments simple. The current system I am using has worked so far but it has its problems. Basically I have 2 files to display forum topics. view_topics.php and topic_list_tpl.php view_topics.php defines some variables like so $template->topic_name = $row[$key]['topic_name'] then it renders the page like so $template->render('topic_list_tpl.php'); then in topic_list_tpl.php i use this to print the name of the topic <?php echo $this->topic_name; ?> which works fine. But as you know a topic list needs a header. But the render function is within a foreach loop so it displays all of the topics from the query. This poses the problem of the header being looped, which it shouldnt be. So in view_topics.php i use: $template->topic_id = $row[$key]['topic_id']; $template->first_topic_id = $row[0]['topic_id']; then in topic_list_tpl.php i can use: <?php if($this->topic_id == $this->first_topic_id) { echo the header } else { echo the topics } but the problem comes when adding a footer bar at the bottom(for the new reply link and other topic options). i can use something like $amount_of_topics = count($row); $template->last_topic_id = $row[$amount_of_topics-1]['topic_id'] and then check it like that but that wont work when using pagination as the last topic displayed isnt always going to be the last topic in the query. So another option i have is to have the header and footer bars in seperate files and call them outside of the loop. But these files would only be 2 or 3 lines each. So is this the best option? or is there an easier way of doing things? Hi All I am wanting to create an online booking system. Has anyone got any suggestions on this? Adi Hi could you help me get this login page working?
I made a form which posts to login.php the "user" and "pass".
Then this is my code for login.php: <?php include("mysql_connect.inc.php"); ?> <?php $user = $_POST['user']; $pass = $_POST['pass']; session_start(); $query = mysqli_query("SELECT * FROM users WHERE username='$user'"); $results = mysqli_query($con, $query) or die(mysqli_error($con)); $resultsarray = mysql_fetch_array($userresults); if (isset($_POST['user']) && $_POST['user'] == $query && isset($_POST['pass']) && $_POST['pass'] == $query) { $_SESSION['username'] = $_POST['user']; echo "<p>Login success. You are logged in as: " . $_SESSION['username'] . "</p>Return to mainpage, click <a href='index.php'>here</a>!"; } else { echo "<p>Wrong username or password.</p>"; } mysqli_close($con); ?> I have database table EMAIL[e_id,receiver_email,sender_email,email_Subject,date_time,Text_body] i have displayed sender_email,Email_subject,Date_time in html table by using select sender_email,Email_subject,Date_time from email where receiver_email=$current _user i need to open email_body by clicking the sender_email problem is that how can i get value of first cell of table in the same row by clicking any other column or if you have alternative as yahoo displayes all emails received in inbox by clicking any sender it opens that specific email First of all hello as I am new to this forum. Ok so, I am have been trying for the past few days to create a login system in PHP for a website I am creating, and I am having serious problems. I have tryed so many tutorials and they all are not working, my conclusion is they are outdated or not fully understandable. So what I want to create - Registration Forgot password Login page Email activation Member page My hosting has the latest php and mysql as far as I know so could someone please give me an up to date simple tutorial on creating this. Lastly the program I am using is Dreamweaver CS5 Thankyou. So I am having some difficulties with a category system. I want my code to search the database an unlimited amount of times to the very last directory and then display it in tree view on my screen. I'm having some trouble because I am having to specify how many depths the code will search. How can I get it to do this on it's own? Currently my code does this... <?php // Establish SQL Connection. $mysqli = mysqli_connect( $sql['host'], $sql['user'], $sql['pass'], $sql['db'] ) or die( "DARN"); $query = $mysqli->query( "SELECT * FROM folders ORDER BY name ASC" ); $num_rows = $query->num_rows; echo "Found <b>" . $num_rows . "</b> row(s) in the database!<br>"; while ( $row = mysqli_fetch_array( $query ) ) { // DO NOT REMOVE $id = $row['id']; $name = $row['name']; $parent = $row['parent']; /***************************************************************************************************/ if ( $parent == 0 ) { echo $id . " " . $name . " " . $parent . "<br>"; $query2 = $mysqli->query( "SELECT * FROM folders WHERE parent = " . $id . " ORDER BY name ASC" ); while ( $row2 = mysqli_fetch_array( $query2 ) ) { echo " " . $row2['name'] . "<br>"; } } } ?>I know it's messy, doing the best I can. DB looks a little like this... +----+---------+--------+ Hi, im getting alot of errors like so Deprecated: Function session_is_registered() is deprecated time to update some files, can you guys pls help im rubbish with PHP guess thats why I waited so long to update. here is the code I need to change checklogin.php // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:index.php"); } index.php <? session_start(); /*if(!session_is_registered(myusername)){ header("location:main_login.php"); }*/ ?> index.php (display username stuff) <?php if(session_is_registered(myusername)){ ?> Welcome: <?= $_SESSION['myusername'] ?><?php } ?> index.php (edit content stuff) <?php $file = file_get_contents('content/menu_header_a.txt', 'r'); if(session_is_registered(myusername)){ ?><a href="javascript:open4()"><?php echo $file ?></a><?php } else { echo $file; }?> Many thanks for any and all your help with this one. if you could keep it simple please like ( replace this with this ) . thanks |