Jump to content

Running a database insert on image click


ukscotth

Recommended Posts

If you want seemless, use an onClick event that will fire an Ajax call to a PHP file that can run the insert for you.

If you want a page refresh, you could use a form/window.location to send the data to be added.

Will the image click do anything else?

Link to comment
Share on other sites

Ok thanks.

 

Its basically for a picture voting facebook app. The user picks which picture is best out of 2 random ones that are displayed.

 

Ideally I would like it so when the user picks one of the pictures it seemlessly inserts there choice details into the database and also changes the 2 images so they can make there next vote, all without the need of refreshing the page but I think this is going to be too hard for me as im a newbie.

 

But I guess the best way would be like you said to use ajax, that way a seperate file could update the database and change the 2 images ready for the next vote, is that right ?

 

Thanks,

 

Scott.

 

 

Link to comment
Share on other sites

Would I start with something like this in the head section of the page ?

 


<script type="text/javascript">
function vote()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.open("GET","vote.php?voter='not sure how to get the data here'",true);
xmlhttp.send();
}
</script>

Link to comment
Share on other sites

or like this ?

 


<script type="text/javascript">
function vote(voter,win,lose)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.open("GET",'vote.php?voter='+voter'&win='+win'&lose='+lose,true);
xmlhttp.send();
}
</script>

Link to comment
Share on other sites

You do not need javascript: infront of the vote function (only really need that in href attributes)

Also if each of those items are individual strings you will need to wrap them in quotes individually.

vote(<?php echo "'test','test2','test3'";?>)

or something like that.

 

Link to comment
Share on other sites

ok thanks, nothing seems to be happening when i try and run it :( any ideas ? heres my simple vote.php code :

 



<?php
include_once "database.php";

mysql_query("INSERT INTO battles (voter, win, lose) VALUES ('".$_GET['voter']."','".$_GET['win']."', '".$_GET['lose']."')");

?>

Link to comment
Share on other sites

Ok thanks, it brings up a few things but none of them seem related :

 


SCRIPT1006: Expected ')' 
home.php, line 31 character 43
SEC7115: :visited and :link styles can only differ by color. Some styles were not applied to :visited. 
home.php
SCRIPT438: Object doesn't support property or method 'tabs' 
home.php, line 57 character 17
SCRIPT438: Object doesn't support property or method 'tabs' 
home.php, line 57 character 17



Link to comment
Share on other sites

ahh the data is being inserted into the database now :)

 

Allthough im getting a lot of https errors which i guess is another issue :

 



SEC7111: HTTPS security is compromised by http://connect.facebook.net/en_US/all.js 
home.php
SEC7111: HTTPS security is compromised by http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js 
home.php
SCRIPT5009: 'FB' is undefined 
home.php, line 24 character 8
SCRIPT5009: '$' is undefined 
home.php, line 34 character 13
SEC7115: :visited and :link styles can only differ by color. Some styles were not applied to :visited. 
home.php
SEC7111: HTTPS security is compromised by http://static.ak.fbcdn.net/rsrc.php/v1/yU/r/74MZs-6P2Dx.js 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/261069_1811448158_6173435_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/273299_825895981_143161359_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369516_100001956697205_1307267885_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/370746_100000063081262_1163655936_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186326_1156985007_724326695_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/275482_522819544_1496773110_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186432_1138683827_161997488_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/274793_100002405641353_902279529_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://static.ak.fbcdn.net/rsrc.php/v1/ys/r/MiVDw0H5WyN.gif 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/261069_1811448158_6173435_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/261069_1811448158_6173435_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/273299_825895981_143161359_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/273299_825895981_143161359_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369516_100001956697205_1307267885_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369516_100001956697205_1307267885_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/370746_100000063081262_1163655936_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/370746_100000063081262_1163655936_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186326_1156985007_724326695_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186326_1156985007_724326695_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/275482_522819544_1496773110_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/275482_522819544_1496773110_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186432_1138683827_161997488_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186432_1138683827_161997488_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/274793_100002405641353_902279529_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/274793_100002405641353_902279529_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://static.ak.fbcdn.net/rsrc.php/v1/ys/r/MiVDw0H5WyN.gif 
home.php
SEC7111: HTTPS security is compromised by http://static.ak.fbcdn.net/rsrc.php/v1/ys/r/MiVDw0H5WyN.gif 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/261069_1811448158_6173435_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369958_809560327_370090192_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/273299_825895981_143161359_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-ash2/369516_100001956697205_1307267885_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/370746_100000063081262_1163655936_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186326_1156985007_724326695_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/275482_522819544_1496773110_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/186432_1138683827_161997488_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://profile.ak.fbcdn.net/hprofile-ak-snc4/274793_100002405641353_902279529_q.jpg 
home.php
SEC7111: HTTPS security is compromised by http://static.ak.fbcdn.net/rsrc.php/v1/ys/r/MiVDw0H5WyN.gif 
home.php
SCRIPT5007: Unable to set value of the property 'innerHTML': object is null or undefined 
all.js, line 6 character 1252
SCRIPT5007: Unable to set value of the property 'innerHTML': object is null or undefined 
all.js, line 6 character 1252


 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.