Welcome to Dream.In.Code
Getting Help is Easy!

Join 95,475 Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 970 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert

Register to Make This Box Go Away!


input image onclick

 
Reply to this topicStart new topic

input image onclick, onclick modify sql table

darkblood03
post 27 Apr, 2008 - 05:58 PM
Post #1


New D.I.C Head

*
Joined: 27 Apr, 2008
Posts: 1

php

<?php
function incVote()
{
mysql_query("UPDATE quotes SET votes=votes+1 WHERE quote=$quote") or die(mysql_error());
}
function decVote()
{
echo $row['quote'];
mysql_query("UPDATE quotes SET votes=votes-1 WHERE quote=$quote") or die(mysql_error());
}

$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("sqldb") or die(mysql_error());
if (!($db = sqlite_open('sqldb/quotes', '0666'))) {
echo "<h2>".$TEXT['ERROR']."</h2>";
die;
}

$result = mysql_query("SELECT quote FROM quotes ORDER BY votes DESC")
or die(mysql_error());

echo "<table border='1'>";
echo "<tr><th>Position</th><th>Quote</th><th width='2'>Vote</th>";
$i = 0;
while ($row = mysql_fetch_array($result)) {
$i++;
echo "<tr class='style1'><td>";
echo $i;
echo "</td><td>";
$quote = print $row['quote'];
echo $quote;
echo "</td><td>";

mysql_query("UPDATE quotes SET votes=votes+1 WHERE quote=$quote") or die(mysql_error());
?>



HTML
<input name="plus" type="image" src="../images/plus.gif" onclick="alert('Thank You for Voting'); return false" /> &nbsp
<input name="minus" type="image" src="../images/minus.gif" onclick="alert('Thank You for Voting'); return false" />


php

<?php
}
echo "</table>";


?>


//I want the user to be able to click on the image and it would call the function to modify a SQL table,
//which inc/dec the votes.
//do not know which language would be the best, but could not get the input to work in the PHP


EDIT: Code blocks added, please use them in the future => code.gif

This post has been edited by PsychoCoder: 27 Apr, 2008 - 07:14 PM
User is offlineProfile CardPM

Go to the top of the page


joeyadms
post 4 May, 2008 - 11:55 PM
Post #2


D.I.C Head

Group Icon
Joined: 4 May, 2008
Posts: 141



Thanked 6 times

Dream Kudos: 600
My Contributions


What you are going to want to do is use AJAX. Well, if you do not want the browser to refresh whenever they push a button.

Google some php ajax tutorials, and have it send some post data telling php what to increment.

Basically your onClick events will trigger javascript to make an Asnychronous request in the background, the user unaware, to your php page containing some post data, that you will parse and decide what to update.

Security... you don't want someone sending loads of post requests to update it ,so make sure you implement something, either only one vote per IP, or use tokens and sessions to make sure the vote came from one of your scripts and not a form created by an attacker.
User is online!Profile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 7/5/08 03:43AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->