Jump to content

Need to modify code for a dynamic voting system!


abhishekdeveloper

Recommended Posts

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.

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.