You are viewing our Forum Archives. To view or take place in current topics click here.
Help needed MYSQL (PDO)
Posted:
Help needed MYSQL (PDO)Posted:
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
Status: Offline
Joined: Jan 24, 201311Year Member
Posts: 71
Reputation Power: 2
Okay. I'm trying to insert data to my database from a JSON file everything is being picked up correctly although i keep receiving this message
I have read over my code several times and i still cant figure out what is causing this.
Whole code:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 's the early 90s. Carl's got to go home.', 'Recommended:
I have read over my code several times and i still cant figure out what is causing this.
Whole code:
$data = $jsonResponse[$APPID]["data"];
$game = $data['name'];
$publisher = implode(",", $data["publishers"]);
$image = $data['header_image'];
$info = $data['short_description'];
$requirements = $data["pc_requirements"]['recommended'];
$platform = $_POST['platform'];
$trailer = $_POST['trailer'];
$download = adfly($_POST["download"], $apiKey, $uId);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "games";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO games (game, publisher, image, info, requirements, platform, trailer, dl ) VALUES ('$game', '$publisher', '$image', '$info', '$requirements', '$platform', '$trailer', '$download')";
// use exec() because no results are returned
$conn->exec($sql);
echo '<div class="alert alert-success" role="alert">Successfully entered record.</div>';
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
}
}
#2. Posted:
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200915Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
You are viewing our Forum Archives. To view or take place in current topics click here.