Hola buena gente!
tengo un problema y me estoy volviendo loco!!
Tengo echo un sistema de favoritos mediante Ajax, php y Mysql..
cuando genero una cookie por cada usuario de solo números me lo acepta y lo ingresa a la BD pero el problema que tengo es cuando genero una cookie con números y letras no me lo reconoce y no se guarda en la BD.
Os adjunto código:
AJAX
Código Javascript
:
Ver originalfunction addremove(favid){
// Configure those variables as appropriate
var divid = 'status';
var url = 'favscript/addremove.php';
// The XMLHttpRequest object
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX.");
return false;
}
}
}
// Generate timestamp for preventing IE caching the GET request
fetch_unix_timestamp = function()
{
return parseInt(new Date().getTime().toString().substring(0, 10))
}
var timestamp = fetch_unix_timestamp();
var nocacheurl = url+"?t="+timestamp;
// This code sends the variables through AJAX and gets the response
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState!=4){
document.getElementById(divid).innerHTML='<img src="images/spinner.gif"> Wait...';
}
if(xmlHttp.readyState==4){
document.getElementById(divid).innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open("GET",nocacheurl+"&favid="+favid,true);
xmlHttp.send(null);
// Finally, some code for button toggle
var button = document.getElementById('button');
switch(button.name)
{
case 'button0':
button.src = 'images/1.jpg';
button.name = 'button1';
break;
case 'button1':
button.src = 'images/0.jpg';
button.name = 'button0';
break;
}
}
Código PHP:
<?php
// Include needed files
include 'mysql.php';
// Connect to MySQL
connectMySQL();
//****** SECURITY CHECK *********
session_start();
if(isset($_SESSION['userid'])){
$user = mysql_real_escape_string($_SESSION['userid']);
//*******************************
// Retrieves variables through AJAX
$favid = '3';
// $favid = mysql_real_escape_string($_GET['favid']);
// Firstly, check if article is favourite or not
$query = mysql_query("SELECT * FROM ajaxfavourites WHERE user=$user AND favid=$favid");
$matches = mysql_num_rows($query);
// If it is not favourited, add as favourite
if($matches == '0'){
mysql_query("INSERT INTO ajaxfavourites (user, favid) VALUES ('$user', '$favid')");
echo "<div class=\"green\">This is a favourite</div>";
}
// Instead, if it is favourited, then remove from favourites
if($matches != '0'){
mysql_query("DELETE FROM ajaxfavourites WHERE user=$user AND favid=$favid");
echo "<div class=\"red\">This is NOT a favourite</div>";
}
} else {
// Someone tries to directly access the file!
echo "Invalid session!";
}
?>
gracias de antemano!!!