Last active
March 13, 2018 17:26
-
-
Save Y0lan/cf0752e980aa894539617ec9d5c80ea9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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