我现在尝试修改我的脚本脚本没有错误,但是我将ajax调用到文件http://villageop/saveid.php?user_id=100 它看起来像脚本运行良好,但它没有在数据库上做任何事情它没有修改数据库
<?php
header('Access-Control-Allow-Origin: *');
error_reporting(E_ALL);
ini_set('display_errors',1);
$servername = "localhost";
$username = "publiadd_publix";
$password = "1a3g7893fsh";
try {
$conn = new PDO("mysql:host=$servername;dbname=publiadd_registervillageop", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
if(isset($_GET['user_id'])){
//$user_id = intval($_GET['user_id']);
//Lightly sanitize the GET's to prevent SQL injections and possible XSS attacks
$sql = "INSERT `publiadd_registervillageop`
//(`user_id`)
//VALUES ('publiadd_registervillageop');
//";
//$sql = mysql_query("INSERT INTO `publiadd_registervillageop`.`users` (`user_id`) VALUES ('user_id');");
//$sql = mysql_query("UPDATE `users` SET user_id = SET user_id +'$user_id' WHERE user_id = " . $_SESSION['user']);
if($sql){
//The query returned true - now do whatever you like here.
echo 'Your ID was saved. Congrats!';
}else{
//The query returned false - you might want to put some sort of error reporting here. Even logging the error to a text file is fine.
echo 'There was a problem saving your points. Please try again later.';
}
}else{
echo 'Your id wasnt passed in the request.';
}
// close MySQL connection
$conn = null;
?>
<html>
<head>
</head>
<body>
<body bgcolor="#ffffff">
</body>
</html>