Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Making a Like/Dislike AJAX script - Not working
- <div id="voting">
- <form>
- <input name="vote" type='button' onclick="getVote(<?php echo $image['filename'];?>)" value='Like' />
- </form>
- </div>
- <script type="text/javascript">
- function getVote(filename)
- {
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("voting").innerHTML=xmlhttp.responseText;
- }
- }
- xmlhttp.open("GET","voting.php"+filename,true);
- xmlhttp.send();
- }
- </script>
- <?php
- //Database Information
- $dbhost = "";
- $dbname = "";
- $dbuser = "";
- $dbpass = "";
- //Connect to database
- mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
- mysql_select_db($dbname) or die(mysql_error());
- $filename = $_GET['filename'];
- $query = "UPDATE images SET rating = rating+1 WHERE filename = '$filename'";
- mysql_query($query) or die(mysql_error());
- mysql_close();
- ?>
- xmlhttp.open("GET","voting.php?filename="+filename,true);
- $filename = isset($_GET['filename']) ? mysql_real_escape_string($_GET['filename']) : null ;
- if (is_null($filename)) {
- exit;
- }
Add Comment
Please, Sign In to add comment