I have made a edit.php file .It seems to work but it only displays error from the echo line (end of the line). I can't seem to find where i have mistyped or have not typed in the coding.
What should I do to fix this?
<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="songid" value="<?php echo $songid; ?>"/>
<table style="margin-left:auto; margin-right:auto; width:400px;">
<tbody>
<tr style="text-align:center">
<td colspan="2"><h2 style="color:#00008b;">Edit song into Music Database</h2><label style="color:#FF0000;"></label></td>
</tr>
<tr>
<td>Title<label style="color:#FF0000;"></label></td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>Artist<label style="color:#FF0000;"></label></td>
<td><input type="text" name="artist"></td>
</tr>
<tr>
<td>Genre<label style="color:#FF0000;"></label></td>
<td><input type="text" name="genre"></td>
</tr>
<tr>
<td>Language<label style="#FF0000;"></label></td>
<td><input type="text" name="language"></td>
</tr>
<tr>
<td>Lyrics: <label style="#FF0000;"></label></td>
<td><textarea name="lyrics" rows="5" cols="50"></textarea></td>
</tr>
<tr style="text-align:center">
<td colspan="2"><input type="submit" name="submit" value="Submit"></td>
</tr>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
} // continue end of function of renderform
// connect to the database
include('connect-db.php');
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['songid']))
{
// get form data, making sure it is valid
$songid = (isset($_POST['songid']) ? $_POST['songid'] : null);
$title = (isset($_POST['title']) ? $_POST['title'] : null);
$artist = (isset($_POST['artist']) ? $_POST['artist'] : null);
$genre = (isset($_POST['genre']) ? $_POST['genre'] : null);
$lyrics = (isset($_POST['lyrics']) ? $_POST['lyrics'] : null);
$language = (isset($_POST['language']) ? $_POST['language'] : null);
// check that firstname/lastname fields are both filled in
if ($title == '' || $artist == '' || $genre == '' || $lyrics == '' || $language == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error);
}
else
{
// save the data to the database
mysql_query("UPDATE players SET title='$title', artist='$artist', genre='$genre', lyrics='$lyrics', language='$language' WHERE songid='$songid'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: view.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{
// get the 'songid' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['songid']) && is_numeric($_GET['songid']) && $_GET['songid'] > 0)
{
// query db
$songid = $_GET['songid'];
$result = mysql_query("SELECT * FROM songs WHERE songid=$songid")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$title = $row['title'];
$artist = $row['artist'];
$genre = $row['genre'];
$lyrics = $row['lyrics'];
$language= $row['language'];
// show form
renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error);
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'songid' in the URL isn't valid, or if there is no 'songid' value, display an error
{
echo 'Error!';
}
}
?>
According to your first screenshot, you use id in the URL instead of songid.
Try changing id to songid, like localhost/songdb/edit.php?songid=14
Propably you defined function but not executed. Please check it:
<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
renderForm();
function renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error)
{...}
your code has some syntax errors but I fixed it also something to note is I tidied up your code and move some stuff around also noticed you were using MySQL when it is deprecated so I made it MySQLI and I gave you the way to connect to your database also when changing header location it is suggested that you put exit(); afterwards to stop the rest of the PHP code from running
<?php
include('connect-db.php');
function renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error){
}
if (isset($_POST['submit'])){
if (is_numeric($_POST['songid'])){
$songid = (isset($_POST['songid']) ? $_POST['songid'] : null);
$title = (isset($_POST['title']) ? $_POST['title'] : null);
$artist = (isset($_POST['artist']) ? $_POST['artist'] : null);
$genre = (isset($_POST['genre']) ? $_POST['genre'] : null);
$lyrics = (isset($_POST['lyrics']) ? $_POST['lyrics'] : null);
$language = (isset($_POST['language']) ? $_POST['language'] : null);
if ($title == null || $artist == null || $genre == null || $lyrics == null || $language == null){
$error = 'ERROR: Please fill in all required fields!';
} else {
$conn = new mysqli('host', 'username', 'password', 'DB');// This will be located in your connect.php but the refrence variable("$conn") is important if you are going to use this php
$conn->query("UPDATE players SET '$title', artist='$artist', genre='$genre', lyrics='$lyrics', language='$language' WHERE songid='$songid''");
header("Location: view.php");
exit();
}
} else {
$error = "Song Id is not valid";
}
}
if (isset($_GET['songid']) && is_numeric($_GET['songid']) && $_GET['songid'] > 0){
$songid = $_GET['songid'];
"SELECT * FROM songs WHERE songid=$songid"
$result = $conn->query("UPDATE players SET '$title', artist='$artist', genre='$genre', lyrics='$lyrics', language='$language' WHERE songid='$songid''");
$row = $result->fetch_assoc();
if(mysqli_num_rows($result) > 0){
$title = $row['title'];
$artist = $row['artist'];
$genre = $row['genre'];
$lyrics = $row['lyrics'];
$language= $row['language'];
renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error); // Still not quite sure what you are doing with this function because there is no function made on this current php script
} else {
$error = "No results!";
}
} else {
$error = "Song id in URL is not valid";
}
?>
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<?php
if ($error){
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="songid" value="<?php echo $songid; ?>"/>
<table style="margin-left:auto; margin-right:auto; width:400px;">
<tbody>
<tr style="text-align:center">
<td colspan="2"><h2 style="color:#00008b;">Edit song into Music Database</h2><label style="color:#FF0000;"></label></td>
</tr>
<tr>
<td>Title<label style="color:#FF0000;"></label></td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td>Artist<label style="color:#FF0000;"></label></td>
<td><input type="text" name="artist"></td>
</tr>
<tr>
<td>Genre<label style="color:#FF0000;"></label></td>
<td><input type="text" name="genre"></td>
</tr>
<tr>
<td>Language<label style="#FF0000;"></label></td>
<td><input type="text" name="language"></td>
</tr>
<tr>
<td>Lyrics: <label style="#FF0000;"></label></td>
<td><textarea name="lyrics" rows="5" cols="50"></textarea></td>
</tr>
<tr style="text-align:center">
<td colspan="2"><input type="submit" name="submit" value="Submit"></td>
</tr>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Related
So I am trying to get the title from the URL by using $_GET['title'] in the first PHP file, but I can't get the file on the 2nd file.
URL:
https://easy2book.000webhostapp.com/neworder.php?bookid=101&title=SENIOR%20secondary%20geography%20fieldwork%20and%20assessment%20practice%202021.%20For%20HKDSE%202021%20/%20Ip%20Kim%20Wai%20...%20[et%20al.].
1st File:
<?php
include_once 'header.php';
$id2 = mysqli_real_escape_string($conn, $_GET['bookid']);
$title2 = mysqli_real_escape_string($conn, $_GET['title']);
?>
<section class="neworder-form">
<h2>Order</h2>
<div class="neworder-form-form">
<form action="neworder.inc.php" method="post">
<table>
<tr>
<td>Book ID:</td>
<td>
<input type="text" disabled="disabled" name="bookid2" value="<?= $id2 ?>">
</td>
</tr>
<tr>
<td>Book Title: </td>
<td>
<input type="text" disabled="disabled" name="title2" value="<?= $title2 ?>">
</td>
</tr>
<tr>
<td>Username: </td>
<td>
<input type="text" name="uid2" placeholder="Username...">
</td>
</tr>
<tr>
<td>Comfirmed Book ID: </td>
<td>
<input type="text" name="id2" placeholder="Please enter the Book ID....">
</td>
</tr>
</table>
<button type="submit" name="submit2">Order</button>
</form>
</div>
<?php
// Error messages
if (isset($_GET["error"])) {
if ($_GET["error"] == "emptyinput2") {
echo "<p>Fill in all fields!</p>";
}
else if ($_GET["error"] == "usernametaken2") {
echo "<p>Username already taken!</p>";
}
}
?>
</section>
2nd File:
<?php
if (isset($_POST["submit2"])) {
// First we get the form data from the URL
$uid2 = $_POST["uid2"];
$id2 = $_POST["id2"];
$title2 = $_POST["title2"];
// Then we run a bunch of error handlers to catch any user mistakes we can (you can add more than I did)
// These functions can be found in functions.inc.php
require_once "dbh.inc.php";
require_once 'functions2.inc.php';
// Left inputs empty
// We set the functions "!== false" since "=== true" has a risk of giving us the wrong outcome
if (emptyInputOrder2($uid2,$id2) !== false) {
header("location: ../neworder.php?error=emptyinput&bookid=$id2&title=$title2");
exit();
}
// Is the username exists
if (uidExists2($conn, $uid2) !== true) {
header("location: ../neworder.php?error=undefineuser");
exit();
}
// If we get to here, it means there are no user errors
// Now we insert the user into the database
createUser($conn, $uid2, $id2);
} else {
header("location: ../neworder.php");
exit();
}
The input fields are disbled, disabled inputs are not posted.
Replace $title2 = $_POST[""]; with $title2 = $_POST["title2"];
I can fetch the data but the submit button is not working.
I am confused with the update query and storing data in array.
Here is the code for fetching and showing data in table.
`<?php
while ($rows=mysqli_fetch_assoc($result)){ ?>
<tr>
<td align="center">
<?php $id[]=$rows['id']; ?><?php echo $rows['id']; ?>
</td>
<td align="center">
<input name="name[]" type="text" id="name" value="<?=$rows['name']; ?>">
</td>
<td align="center">
<input name="lastname[]" type="text" id="lastname" value="<? =$rows['lastname']; ?>">
</td>
<td align="center">
<input name="email[]" type="text" id="email" value="<?=$rows['email']; ?>">
</td>
</tr>
`
Here is the code for submit button
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["Submit"] != ""){
$count = mysqli_num_rows($result);
for($i=0;$i<$count;$i++){
$sql2="UPDATE test_mysql SET name='".$_POST["name"][$i]."',lastname='".$_POST["lastname"][$i]."', email='".$_POST["email"][$i]."' WHERE id='$id[$i]'";
$result1=mysqli_query($con, $sql2);
}
header("Location: update-multiple-2.php");
}
If you handle POST after outputting form (to set variable $id) and variable $test_mysql is set to existing table in your database and all columns exists and you are only one who can add or remove row (because it will change the $id variable) then it should work.
Maybe this could help:
if(!$result1=mysqli_query($con, $sql2)){
echo 'Error: '.mysqli_error();
}
You need to debug it somehow:
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_POST["Submit"] != ""){
$count = mysqli_num_rows($result);
$error = '';
for($i=0;$i<$count;$i++){
$sql2="UPDATE $test_mysql SET name='".$_POST["name"][$i]."',lastname='".$_POST["lastname"][$i]."', email='".$_POST["email"][$i]."' WHERE id='$id[$i]'";
if(mysqli_query($con, $sql2) === FALSE){
$error .= 'SQL query failed, SQL: '.$sql2.', Error: '.mysqli_error() . "\n";
}
}
if(!$error){
header("Location: update-multiple-2.php");
}else{
echo $error;
exit();
}
}
Below is the code I have, which checks for if text box is empty then give warning beside text box once clicked on Submit.
<?php
if(isset($_POST["submit"])) {
$fqdn = $_POST["fqdn"];
$ip = $_POST["ip"];
$fileText = $fqdn."\n".$ip;
$file = fopen("inputFile.txt","w");
fwrite($file, $fileText);
fclose($file);
}
?>
<form action = "<?php $_PHP_SELF ?>" method = "post">
<table style= "width:400px">
<tr class="spaceUnder">
<td><b>FQDN:</b></td>
<td><input type="text" name="fqdn" placeholder="server.domain.com"/></td>
<td> <?php if(isset($_POST['fqdn']) && $_POST['fqdn'] == ''){ echo "<font color='red'>FQDN cannot be empty</font>";} ?> </td>
</tr>
<tr class="spaceUnder">
<td><b>IP:</b></td>
<td><input type="text" name="ip" placeholder="***.***.***.***"/></td>
<td> <?php if(isset($_POST['ip']) && $_POST['ip'] == ''){ echo "<font color='red'>IP cannot be empty</font>"; } ?> </td>
</tr>
<tr>
<td align="center" colspan="2">
<input type = "submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
After clicking on submit, the php is still going and writing to the file. If i give exit() or return false; at the below step:
<td> <?php if(isset($_POST['fqdn']) && $_POST['fqdn'] == ''){ echo "<font color='red'>FQDN cannot be empty</font>"; exit();} ?> </td>
the form becomes incomplete, means, the IP textbox and submit button will not exist. Any way to make it right?
So what we have here. We are making 2 variables that will dispay our errors. The variable in first place are emty because we dont know what we have post. After we post the data we can see if the post is emty or not. If the post is emty we assign an error message to the variable and dispay it to our table.
$error_FQDN = "";
$error_ip = "";
if(isset($_POST["submit"])) {
if($_POST["fqdn"] == "" || $_POST["ip"] == ""){
if($_POST["fqdn"] == ""){
$error_FQDN = "FQDN cannot be empty!";
}
if($_POST["ip"] == ""){
$error_ip = "IP cannot be empty!";
}
} else {
$fqdn = $_POST["fqdn"];
$ip = $_POST["ip"];
$fileText = $fqdn."\n".$ip;
$file = fopen("inputFile.txt","w");
fwrite($file, $fileText);
fclose($file);
}
}
<form action = "<?php $_PHP_SELF ?>" method = "post">
<table style= "width:400px">
<tr class="spaceUnder">
<td><b>FQDN:</b></td>
<td><input type="text" name="fqdn" placeholder="server.domain.com"/></td>
<td><?php echo $error_FQDN ?></td>
</tr>
<tr class="spaceUnder">
<td><b>IP:</b></td>
<td><input type="text" name="ip" placeholder="***.***.***.***"/></td>
<td><?php echo $error_ip ?></td>
</tr>
<tr>
<td align="center" colspan="2">
<input type = "submit" name="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
Try this,
// Check for form submit and if fields aren't empty
if(isset($_POST["submit"]) && $_POST['fqdn'] != "" && $_POST['ip'] != "") {
$fqdn = $_POST["fqdn"];
$ip = $_POST["ip"];
$fileText = $fqdn."\n".$ip;
$file = fopen("inputFile.txt","w");
fwrite($file, $fileText);
fclose($file);
}
By validating fqdn and ip, if values aren't empty, if case will be executed. Else it simply won't run.
I have been trying the whole week to get this too work but haven't had any luck thus far. I am building an employee system, being my first project I could really use your help.
I have a database with a table called ref_employees with x amount of fields.
I managed to get my hands on some source to edit the record and thought that my problem was solved. Although the source helped me to edit the records, the client needs more functionality by means of upload and storing functionality. I have edited the code accordingly but have 2 issues now.
1) I had to add the upload form separate to the editing form because when the edits' update is clicked it clears the upload fields within the db even after adding echoing out the current values within the upload fields in the db.
2) The uploads shows that it is uploading but is doesn't get saved in the specified directory. The permissions are set to 777, and the file names are not captured in the database in the relevant fields. I think it is because the upload function is in a separate page and not on the same page as the upload form.
I need it to upload the file, store it in a directory and finally place the file name in the db where the warning fields are, but it needs to be captured under the record (employee) being edited.
I am new to this and all help is appreciated.
The edit page:
<?php
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
error_reporting(1);
?>
<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($idnumber, $firstname, $lastname, $department, $manager, $startdate, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<div class="article">
<h1>Employee Details</h1>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="idnumber" value="<?php echo $idnumber; ?>"/>
<div>
<p>* Required</p>
<p><strong>ID:</strong> <?php echo $idnumber; ?></p>
<table cellpadding="5" cellspacing="5">
<tr>
<td><strong>First Name: *</strong></td>
<td><input type="text" name="firstname" value="<?php echo $firstname; ?>"/></td>
</tr>
<tr>
<td><strong>Last Name: *</strong></td>
<td> <input type="text" name="lastname" value="<?php echo $lastname; ?>"/></td>
</tr>
<tr>
<td><strong>Department: *</strong> </td>
<td> <input type="text" name="department" value="<?php echo $department; ?>"/></td>
</tr>
<tr>
<td><strong>Manager/Superviser: *</strong></td>
<td><input type="text" name="manager" value="<?php echo $manager; ?>"/></td>
</tr>
<tr>
<td><strong>Start Date: *</strong></td>
<td><input type="text" name="startdate" value="<?php echo $startdate; ?>"/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit" class="btn"></td>
</tr>
</table>
</form>
<tr>
<td>
<table cellpadding="5" cellspacing="0">
<form action="includes/add.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="idnumber" value="<?php echo $idnumber; ?>"/>
<th>Ad Warnings Documents</th>
<tr>
<td>Warning File 1</td>
<td><input type="file" name="warning1" value="<?php echo $warning1;?>" /></td>
</tr>
<tr>
<td>Warning File 2</td>
<td><input type="file" name="warning2" value="<?php echo $warning2;?>" /></td>
</tr>
<tr>
<td>Warning File 3</td>
<td><input type="file" name="warning3" value="<?php echo $warning3;?>" /></td>
</tr>
<tr><td><input type="submit" name="submit" value="upload"></td></tr>
</table>
</td>
<td></td>
</tr>
</table>
</div>
</body>
</html>
<?php
}
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit']))
{
// confirm that the 'id' value is a valid integer before getting the form data
if (is_numeric($_POST['idnumber']))
{
// get form data, making sure it is valid
$idnumber = $_POST['idnumber'];
$firstname = mysql_real_escape_string(htmlspecialchars($_POST['firstname']));
$lastname = mysql_real_escape_string(htmlspecialchars($_POST['lastname']));
$department = mysql_real_escape_string(htmlspecialchars($_POST['department']));
$manager = mysql_real_escape_string(htmlspecialchars($_POST['manager']));
$startdate = mysql_real_escape_string(htmlspecialchars($_POST['startdate']));
// check that firstname/lastname fields are both filled in
if ($firstname == '' || $lastname == '')
{
// generate error message
$error = 'ERROR: Please fill in all fields!';
//error, display form
renderForm($idnumber, $firstname, $lastname, $department, $manager, $startdate, $error);
}
else
{
// save the data to the database
mysql_query("UPDATE ref_employees SET firstname='$firstname', lastname='$lastname', department='$department', manager='$manager', startdate='$startdate' WHERE idnumber='$idnumber'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: employeelist.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error!';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['idnumber']) && is_numeric($_GET['idnumber']) && $_GET['idnumber'] > 0)
{
// query db
$idnumber = $_GET['idnumber'];
$result = mysql_query("SELECT * FROM ref_employees WHERE idnumber=$idnumber")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$department = $row['department'];
$manager = $row['manager'];
$startdate = $row['startdate'];
$warning1 = $row['warning1'];
$warning2 = $row['warning2'];
$warning3 = $row['warning3'];
// show form
renderForm($idnumber, $firstname, $lastname, $department, $manager, $startdate, '');
}
else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error!';
}
}
?>
<h1>Additional options</h1>
</div>
The file upload source file add.php
<?php
include 'core/init.php';
protect_page();
include 'includes/overall/header.php';
error_reporting(1);
?>
<?php
//This is the directory where images will be saved
$target = "files/empdocs";
$target1 = $target . basename( $_FILES['warning1']['name']);
$target2 = $target . basename( $_FILES['warning2']['name']);
$target3 = $target . basename( $_FILES['warning3']['name']);
//This gets all the other information from the form
$warning1=($_FILES['warning1']['name']);
$warning2=($_FILES['warning2']['name']);
$warning3=($_FILES['warning3']['name']);
//Writes the information to the database
mysql_query("INSERT INTO ref_employees VALUES ('$warning1', '$warning2', '$warning3')") ;
//Writes the file to the server
if (move_uploaded_file($_FILES['warning1']['tmp_name'], $target1)
&& move_uploaded_file($_FILES['warning2']['tmp_name'], $target2)
&& move_uploaded_file($_FILES['warning3']['tmp_name'], $target3)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
I'm working on a registration form for my website.
One of the fields on my registration form is a drop down box that is populated by a table on my MySQL database.
I originally wrote the registration script a different way but I needed to change how the form worked to accommodate the new drop down box and the way it gathered its data.
Before the changes the form was successfully submitted, but now it just gives me a white screen.
I have checked the mysqli_connect.php with an if-else statement. It showed that it was working but no registrations were being sent to the MySQL server when the submit button was pressed. Also, the drop down box was not showing any of the content from the MySQL table that it was linked to.
Below is a copy of the script that I am using:
<?php
#ini_set('display_errors', 'on');
echo "<h1>Register</h1>";
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$errors = array();
if (empty($_POST['firstname'])){
$errors[] = 'Your forgot to enter your first name.';
}else{
$firstname = trim($_POST['firstname']);
}
if (empty($_POST['lastname'])){
$errors[] = 'Your forgot to enter your last name.';
}else{
$lastname = trim($_POST['lastname']);
}
if (empty($_POST['username'])){
$errors[] = 'Your forgot to enter your username.';
}else{
$username = trim($_POST['username']);
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST ['password2']) {
$errors[] = 'Your password did not match the confirmed password!';
}else{
$password = trim($_POST['password1']);
}
} else {
$errors[] = 'You forgot to enter your password!';
}
if (empty($_POST['birthdate'])){
$errors[] = 'Your forgot to enter your birthdate.';
}else{
$birthdate = trim($_POST['birthdate']);
}
if (empty($_POST['gamespyid'])){
$errors[] = 'Your forgot to enter your gamespy id.';
}else{
$gamespyid = trim($_POST['gamespyid']);
}
if (empty($errors)) {
require ('mysqli_connect.php');
$q="INSERT INTO Users (firstname, lastname, username, password1, birthdate, gamespyid, base) VALUES ('$firstname', '$lastname', '$username', SHA1('$password1'), '$birthdate', '$gamespyid', '$base')";
$r = #mysql_query($dbc, $q);
if ($r){
echo'<p>You are now registered</p>';
}else{
echo'<p>You have not been registered</p>';
}
} else {
echo 'Error<br> <p>The following errors have occured:<br/>';
foreach ($error as $msg) {
echo " - $msg<br/>\n";
}
echo '</p><p>Please try again.</p><p><br/></p>';
} //if no errors
} //submit
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title></title>
</head>
<body>
<form action="../pages/register.inc.php" method='POST'>
<table summary="REgform">
<tr>
<td>First Name:</td>
<td><input type='text' name='firstname' value='<?php echo $firstname; ?>'></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type='text' name='lastname'value='<?php echo $lastname; ?>'></td>
</tr>
<tr>
<td>Username:</td>
<td><input type='text' name='username'value='<?php echo $username; ?>'></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password1'></td>
</tr>
<tr>
<td>Repeat Password:</td>
<td><input type='password' name='password2'></td>
</tr>
<tr>
<td>Birthdate:</td>
<td><input type='text ' name='birthdate'value='<?php echo $birthdate; ?>'></td>
</tr>
<tr>
<td>Gamespy Id:</td>
<td><input type='text' name='gamespyid'value='<?php echo $gamespyid; ?>'></td>
</tr>
<tr>
<td>Base:</td>
<td><select name="base" size="1">
<option>
Select One
</option>
<?php require('http://www.virtual-aviation.org/gatewayaviation/admin/mysqli_connect.php');
$q = "SELECT id, CONCAT_WS(' ', airport_name, airport_code) FROM airports ORDER BY airport_code ASC";
$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r) > 0) {
while ($row = mysql_fetch_array ($r, MYSQL_NUM)) {
echo "<option value=\"$row[0]\"";
if (isset($_POST['existing']) && ($_POST['existing'] == $row[0]) ) echo 'selected="selected"'; echo ">$row[1]</option>\n";
}
} else {
echo '<option>Please a new airport first.</optioon>';
}
mysqli_close($dbc);
?>
</select></td>
</tr>
</table>
<p><input type='submit' name='submit' value='Register'></p>
</form>
</body>
</html>
Errors found in the dropdown box area
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home5/virtua15/public_html/gatewayaviation/pages/register.inc.php on line 178
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /home5/virtua15/public_html/gatewayaviation/pages/register.inc.php on line 180
Please a new airport first.
You can't require from 'http'. You need to change
require('http://www.virtual-aviation.org/gatewayaviation/admin/mysqli_connect.php');
to some local path like
require('mysqli_connect.php');
IMHO First check your mysql query by echoing it and then run the query through editor.
Second, although you have set display_errors but still you might not able to view the errors.