Skip to content

Instantly share code, notes, and snippets.

@Y0lan
Last active March 13, 2018 17:26
Show Gist options
  • Save Y0lan/cf0752e980aa894539617ec9d5c80ea9 to your computer and use it in GitHub Desktop.
Save Y0lan/cf0752e980aa894539617ec9d5c80ea9 to your computer and use it in GitHub Desktop.
<?php
include('../config.php');
$query = "
SELECT
id,
pseudo
FROM users
";
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
// Finally, we can retrieve all of the found rows into an array using fetchAll
$info = $stmt->fetchAll();
$id = $array[0]['id'];
print_r($info);
switch ($_REQUEST['action']) {
case 'sendMessage':
$query = $db->prepare("INSERT INTO messages SET id_user = ?, content=?");
$query->execute([$id,$_REQUEST['message']]);
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment