Hi Ben , thanks for your code , it's really useful.
I have a problem with the file edit.php
This is the error:
Parse error: syntax error, unexpected $end in /opt/lampp/htdocs/server/GestionIp/edit.php on line 116
this is the code :
<?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($ID, $IP, $NOMBRE, $DESC, $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="id" value="<?php echo $IP; ?>"/>
<div>
<p><strong>ID:</strong> <?php echo $ID; ?></p>
<p><strong>IP:</strong> <?php echo $IP; ?></p>
<strong>Nombre: </strong> <input type="text" name="NOMBRE" value="<?php echo $NOMBRE; ?>"/><br/>
<strong>DESC: </strong> <input type="text" name="DESC" value="<?php echo $DESC; ?>"/><br/>
<input type="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>
<?php
}
// 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['ID']))
{
// get form data, making sure it is valid
$ID = $_POST['ID'];
$NOMBRE = mysql_real_escape_string(htmlspecialchars($_POST['NOMBRE']));
$DESC = mysql_real_escape_string(htmlspecialchars($_POST['DESC']));
// check that NOMBRE/DESC fields are both filled in
if ($NOMBRE == '' || $DESC == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($IP, $ID, $NOMBRE, $DESC, $error);
}
else
{
// save the data to the database
mysql_query("UPDATE players SET NOMBRE='$NOMBRE', DESC='$DESC' WHERE IP='$ID'")
or die(mysql_error());
// once saved, redirect back to the view page header("Location: enviar.php");
}
}
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['$ID']) && is_numeric($_GET['$ID']) && $_GET['$ID'] > 0)
{
// query db
$ID = $_GET['$ID'];
$result = mysql_query("SELECT * FROM players WHERE $ID=$ID")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'IP' matches up with a row in the databse
if($row)
{
// get data from db
$NOMBRE = $row['NOMBRE'];
$DESC = $row['DESC'];
// show form
renderForm($ID, $IP, $NOMBRE, $DESC, '');
}
else
// if no match, display result
{ echo "No results!";
}
}
else
// if the 'IP' in the URL isn't valid, or if there is no 'IP' value, display an error
{
echo 'Error!';
}
}
?>
I don't know what happen because I copy your code and replaced the specific code for my configuration.
Thanks for all
Bye
PD: One question , What does it do the function renderform()?;