0
Undefined $conn variable
require 'config.php'; if (isset($_POST["submit"])) { $PLAYERID = NULL; $PLAYERNAME = $_POST ["playerName"]; $stmt = $conn->prepare("INSERT INTO PLAYER (:PLAYERID, :PLAYERNAME) VALUES (?, ?)"); $stmt->execute(["PLAYERID" => $PLAYERID, "PLAYERNAME" => $PLAYERNAME]); echo "Player added!"; echo "<a href='game.html'> Ga naar spel </a>"; } What am I doing wrong? This is a function to insert data by the way how do I define $conn please help me out
9 odpowiedzi
+ 1
I'm trying to submit via a html form but this is an error I get when I put a var dump it shows no errors everything is correct
0
A variable must be assigned with a value. If the variable had a value unassigned, then this will display an error.
0
$conn is undefined here..is it exist inside config.php?
0
Yes it is defined in the config.php that's my db connection
0
is this ur full code?and can u share code for config.php ?
0
Yes of course
$servername = "localhost";
$dbname = "HANGMAN";
$username = "root";
$password = "root";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname",
$username, $password);
$conn->SetAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// echo "Connectie gelukt <br />";
}
catch (PDOException $e)
{
echo "connectie mislukt: " . $e->getMessage();
}
0
seems fine.
0
is ur code that u are asking inside a function?
0
if the code is nested inside a function, then declare
global $conn;
first, then try to use it..