The Company, JobPosition, and Felony parts of the form render. The other ones return this error.
( ! ) Warning: Missing argument 4 for renderForm(), called in C:\Users\cenin\Desktop\The Link\new2.php on line 84 and defined in C:\Users\cenin\Desktop\The Link\new2.php on line 9
and
( ! ) Notice: Undefined variable: error in C:\Users\cenin\Desktop\The Link\new2.php on line 20
I have been staring at this code for the past hour trying to figure out how I messed up the naming, but I don’t understand.
[php]<?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($companyfield, $jobtitlefield, $felonyfield, $agefield, $driverslicensefield, $gedfield, $error)
{
?>
Job Title: *
Felony: *
Age: *
Driver's License: *
GED: *
* required
// 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
$company = mysql_real_escape_string(htmlspecialchars($_POST[‘company’]));
$jobtitle = mysql_real_escape_string(htmlspecialchars($_POST[‘jobtitle’]));
$felony = mysql_real_escape_string(htmlspecialchars($_POST[‘felony’]));
$age = mysql_real_escape_string(htmlspecialchars($_POST[‘age’]));
$driverslicense = mysql_real_escape_string(htmlspecialchars($_POST[‘driverslicense’]));
$ged = mysql_real_escape_string(htmlspecialchars($_POST[‘ged’]));
// check to make sure both fields are entered
if ($company == ‘’ || $jobtitle == ‘’ || $felony == ‘’ || $age == ‘’ || $driverslicense == ‘’ || $ged == ‘’)
{
// generate error message
$error = ‘ERROR: Please fill in all required fields!’;
// if either field is blank, display the form again
renderForm($company, $jobtitle, $felony, $age, $driverslicense, $ged, $error);
}
else
{
// save the data to the database
mysql_query(“INSERT players SET company=’$company’, jobtitle=’$jobtitle’, felony=’$felony’, age=’$age’, driverslicense=’$driverslicense’, ged=’$ged’”)
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(’’,’’,’’);
}
?>[/php]