I have this piece of code:
if (isset($_POST['username']) && isset($_POST['email'])) {
$query = $pdo->prepare('INSERT INTO users (name, email, joined) VALUES (?, ?, ?)') or die ('Error.');
$query->bindValue(1, $_POST['username']);
$query->bindValue(2, $_POST['email']);
$query->bindValue(3, time());
$query->execute();
$sql = mysql_query('SELECT * FROM users;');
while ($row = mysql_fetch_array($sql)) {
echo ('<div style="font-weight: bold;">' .$row['name']. '</div>');
echo ($row['email']);
echo ('<br>');
echo ('Posted: ');
echo date('F j, Y, g:i a', strtotime($row['joined']));
}
}
which it accuses this error:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\WebServer\htdocs\newsSite\register.php on line 21
and on another file (below), it works fine, but i don't see the difference between them:
<body>
<?php
$query = mysql_query('SELECT * FROM posts;');
while ($row = mysql_fetch_array($query)) {
echo ('<div style="font-weight: bold;">' .$row['title']. '</div>');
echo ($row['post']);
echo ('<br>');
echo ('Posted: ');
echo date('F j, Y, g:i a', strtotime($row['date']));
}
?>
</body>
mysql_*and PDO ?PDOconnection and amysql_connectconnection?NOW()which is a MySQL function and will automatically fill the field with the current time. Example:INSERT INTO users (name, email, joined) VALUES (?, ?, NOW())