I would like to make it so that when you click an image it saves that images url to a field in a database... I know how to do the SQL UPDATE part but i don't know how to get the the image url?
I am sorry but i have no code because i don't know where to start!
Thanks in advance!
You can get the url of the image with jQuery like this:
$(document).ready(function(){
$('img').click(function(){
var img = $(this.src)
});
});
Then execute your Ajax request using your var img to send the information in your php file.
Edit: Remember to escape the URL that is going to be returned as someone could easily try and SQL injection or some kind of breach in your database.
You could use javascript to make an ajax request. In this example i use jQuery:
//javascript
$('img').click(function(){
$.post('process.php', {url: $(this).attr('src')});
}
//process.php
$url = $_POST['url'];
//save to db
You can do as @Jonan suggested and pass the url you want to save in anchor.
According to @Jonan:
<a href="insertPictureURL.php?url=theLinkYouwantToSave"></a>
Then all you need to do is get the value and store it in a php variable in "insertPictureURL.php" with:
$theLinkIWantToSave = $_GET['url'];
Then just put that in your query.