My website is sitethijsvries.epizy.com and the relevant pages are sitethijsvries.epizy.com/form.html and /verwerk.php. I’m 100% sure I used the right host, password and database name. Can someone please help me or tell me why this doesn’t work. The code is as following:
if($correct){
$db = new PDO('mysql:host=(got this right in my code but only allowed to put 2 links in this post)
;dbname=epiz_24665691_reacties', 'epiz_24665691', 'HIDDEN BY MOD');
$query = "SELECT id FROM personen WHERE naam = ? AND email = ?";
$stmt = $db->prepare($query);
$stmt->execute(array( $naam, $email));
if ($stmt->rowCount() > 0){
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$persoon_id = $row['id'];
} else {
$query = "INSERT INTO personen(naam, email) VALUES (?, ?)";
$stmt = $db->prepare($query);
$stmt->execute(array( $naam, $email));
//vraagt de id van de nieuwe persoon op
$persoon_id = $db->lastInsertId();
}
$query = "INSERT INTO reacties(persoon_id, reactie, datum) VALUES (?, ?, ?)";
$stmt = $db->prepare($query);
$stmt->execute(array( $persoon_id, $reactie, date('Y-m-d H:i:s')));
echo "<br /><br />Bovenstaande informatie is opgeslagen!<br />\n";
echo 'Zie hier de <a href="reacties.php">reacties</a>.<br />';
} else {
echo "<br /><br />Er is een foute waarde ingevoerd, <a href=\"javascript:history.back();\">ga terug</a>.<br />\n";
Uh oh! Don’t share passwords (especially your hosting account password) on a public place, like this forum! Change it to something else now, because that one is now compromised.
Also, seen that the codes above work with MySQLi Object-Oriented, try to connect to the database with this code:
$servername = "your server name"; // replace with your server host
$username = "your username"; // replace with your hosting account username
$password = "your password"; // replace with your hosting account password; also note, don't share your password on a public place!
$dbname = "your database name"; // replace with your database name
$db = new mysqli($servername, $username, $password, $dbname);
if(mysqli_connect_error()) {
echo "Error connecting to the database: ".mysqli_connect_error();
exit;
}
@goat123, maybe change rowCount() with num_rows. Also, before that, use $stmt->store_result to store the results from the prepared statement on the memory before calling that function.
@anon19508339, also, I don’t think $result->num_rows will work, as it will only work with an element that is at least a mysqli_stmt.
Fatal error : Uncaught Error: Call to a member function fetch_assoc() on bool in /home/vol15_8/epizy.com/epiz_24665691/htdocs/verwerk.php:106 Stack trace: #0 {main} thrown in /home/vol15_8/epizy.com/epiz_24665691/htdocs/verwerk.php on line 106
Line 106 is this now:
$row = $result->fetch_assoc();