Good morning/afternoon,
Can someone please explain to me why i keep getting a;
Warning: Missing argument 4 for renderForm(), called in /home/***/public_html/new.php
Here is the HTML/PHP code i am using;
<?php
/*
NEW.PHP
Allows user to create a new entry in the database
*/
// creates the new record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($date, $home, $time, $away, $city, $error)
{
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>New 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">
<div>
<label>Date:</label>
<input class="input" name="id" type="text" value="<?php echo $date; ?>">
<br/>
<label>Home Team:</label>
<input class="input" name="id" type="text" value="<?php echo $home; ?>">
<br/>
<label>Time:</label>
<input class="input" name="id" type="text" value="<?php echo $time; ?>">
<br/>
<label>Away Team:</label>
<input class="input" name="id" type="text" value="<?php echo $away; ?>">
<br/>
<label>Location:</label>
<input class="input" name="id" type="text" value="<?php echo $city; ?>">
<br/>
<p>* required</p>
<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, start to process the form and save it to the database
if (isset($_POST['submit']))
{
// get form data, making sure it is valid
$date = mysql_real_escape_string(htmlspecialchars($_POST['date']));
$home = mysql_real_escape_string(htmlspecialchars($_POST['home']));
$time = mysql_real_escape_string(htmlspecialchars($_POST['time']));
$away = mysql_real_escape_string(htmlspecialchars($_POST['away']));
$city = mysql_real_escape_string(htmlspecialchars($_POST['city']));
// check to make sure both fields are entered
if ($date == '' || $home == '' || $time == '' || $away == '' || $city == '')
{
// generate error message
$error = 'ERROR: Please fill in all required fields!';
// if either field is blank, display the form again
renderForm($date, $home, $time, $away, $city, $error);
}
else
{
// save the data to the database
mysql_query("INSERT data SET date='$date', home='$home', time='$time', away='$away', city='$city'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: view.php");
}
}
else
// if the form hasn't been submitted, display the form
{
renderForm('','','');
}
?>
I have tried to search here and google with no fix. Can anyone please help me please? This should be a form to add new events. But with these errors i am unable to make it work. Thank you in advance for any assistance you might be able to provide.
The original part is done. Thank you for all the answers. But now i after i submit it gives me this error, not sure if it has anything to do with the edit i made to:
renderForm(null,null,null,null,null,null);
Thank you once again.