Im trying to create a form with drop down which is populated from database, when i select the value and i press submit i get an error as described below please i need some help.
<?php
require_once ('conn.php');
$sql = mysqli_query(db_connect(), "SELECT Title FROM $table WHERE NOT Status='Links_added' ORDER BY Title ASC");
?>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<h2>Test</h2>
<form method="post" action="pass.php" name="resources">
Name: <select name="title_name">
<?php
echo "<option value=name1>" . "Select Title" . "</option>";
while ($row = $sql->fetch_assoc()){
echo "<option value='" .$row['Title'] ."'>" . $row['Title'] . "</option>";
}
?>
</select>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
you have to check every variable for existence before using it. e.g. with isset, or empty, or the coalesce operator. var_dump it when you are not sure about what it contains.
What environment are you running in? I can’t see anything in your code that would cause the problem, as long as there’s nothing in your included file to unset the array. I did pick up on a problem with PHPStorm causing something similar.
The workaround in your pass.php was something like:
Is that a requirement? I thought that was a good thing, but not actually required unless the parameter value contains a space or some other character that might cause confusion.
What does the full code for pass.php look like? And also what is $table? You have it as "SELECT Title FROM $table WHERE NOT Status='Links_added' ORDER BY Title ASC" So what is $table set as?