abhishekdeveloper Posted February 20, 2012 Share Posted February 20, 2012 Hi Guys, I am designing this website that takes votes on images. I need to store the votes for each image against the image name and a username. For this purpose, I need to modify the current code which retrieves votes from the voting system but doesn't have a system to enter the image name dynamically. Below is the code for the same: <?php ob_start(); $host="localhost"; $username="computat_abhi"; $password="[..]"; $databasename="computat_button"; $tbl_name="record"; $db=mysql_connect ("localhost", "computat_abhi", "[..]")or die(mysql_error()); mysql_select_db($databasename, $db) or die(mysql_error()); if( isset($_POST['Like']) ) { $sql = 'INSERT INTO record(ImageNumber,LikeCounter) VALUES (\'b1\', 1)'; mysql_query($sql, $db) or die(mysql_error()); echo 'Like vote is registered'; } elseif(isset($_POST['Dislike'])) { $sql = 'INSERT INTO record(ImageNumber,DislikeCounter) VALUES (\'b1\', 1)'; mysql_query($sql, $db) or die(mysql_error()); echo 'Dislike vote is registered'; } ob_end_flush(); ?> <html> <head> <title> Do you Like/Dislike this image? </title> </head> <body> <h1> Do you Like/Dislike this image? </h1> <form name="form1" method ="post"> <input type="submit" name="Like" value="Like"> <input type="submit" name="Dislike" value="dislike"> </form> </body> </html> Another issue is to register a new user on the website www.computationalphotography.in and link it with the voting system above. Looking forward to your help and suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/257404-need-to-modify-code-for-a-dynamic-voting-system/ Share on other sites More sharing options...
WatsonN Posted February 20, 2012 Share Posted February 20, 2012 I would seriously consider changing your username and password for your SQL server. Also, did you mean retrieve the votes, because it looks as if the submit code is there already? Quote Link to comment https://forums.phpfreaks.com/topic/257404-need-to-modify-code-for-a-dynamic-voting-system/#findComment-1319347 Share on other sites More sharing options...
xyph Posted February 20, 2012 Share Posted February 20, 2012 It'd be a good idea to ask specific questions as well. Or a question at all for that matter. Quote Link to comment https://forums.phpfreaks.com/topic/257404-need-to-modify-code-for-a-dynamic-voting-system/#findComment-1319349 Share on other sites More sharing options...
AyKay47 Posted February 21, 2012 Share Posted February 21, 2012 I hope that isn't your actual db credentials. What exactly do you need help with? Quote Link to comment https://forums.phpfreaks.com/topic/257404-need-to-modify-code-for-a-dynamic-voting-system/#findComment-1319424 Share on other sites More sharing options...
abhishekdeveloper Posted February 21, 2012 Author Share Posted February 21, 2012 My exact question is that $sql stores values b1,1 in the column ImageNumber and LikeCounter.Here b1 is the image name which is statically entered into the db. I want this to be dynamically entered for each image name. The code is the part of rating system that I have developed which is referenced again and again when the user votes in a Like/Dislike voting system. if( isset($_POST['Like']) ) { $sql = 'INSERT INTO record(ImageNumber,LikeCounter) VALUES (\'b1\', 1)'; mysql_query($sql, $db) or die(mysql_error()); echo 'Like vote is registered'; } elseif(isset($_POST['Dislike'])) { $sql = 'INSERT INTO record(ImageNumber,DislikeCounter) VALUES (\'b1\', 1)'; mysql_query($sql, $db) or die(mysql_error()); echo 'Dislike vote is registered'; } [\code] Thank you for your help. [quote author=AyKay47 link=topic=354171.msg1672827#msg1672827 date=1329795892] I hope that isn't your actual db credentials. What exactly do you need help with? [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/257404-need-to-modify-code-for-a-dynamic-voting-system/#findComment-1319440 Share on other sites More sharing options...
WatsonN Posted February 21, 2012 Share Posted February 21, 2012 I'm not sure how your page is set up but if your pulling the image by page id you could use GET or POST for the image name. Quote Link to comment https://forums.phpfreaks.com/topic/257404-need-to-modify-code-for-a-dynamic-voting-system/#findComment-1319450 Share on other sites More sharing options...
abhishekdeveloper Posted February 21, 2012 Author Share Posted February 21, 2012 @Watson - Solves my problem. Quote Link to comment https://forums.phpfreaks.com/topic/257404-need-to-modify-code-for-a-dynamic-voting-system/#findComment-1319539 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.