Problems rendering my form - variable names

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)
{
?>

New Record <?php // if there are any errors, display them if ($error != '') { echo '
'.$error.'
'; } ?>
Company: *
Job Title: *
Felony: *
Age: *
Driver's License: *
GED: *

* required

<?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
$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]

since this form is used multiple times in this file, I have made it a function that is easily reusable

No, no and hell no. Get rid of the function and do an include.

And for gawd sake, stop using the obsolete mysql_* code. It started becoming deprecated over TEN years ago. No excuse to still be using it. Use PDO with prepared statements.

https://phpdelusions.net/pdo

Come back with your updated code if your still having problems.

For now I’m just trying to get a simple form working. Maybe I should have posted in the beginners Forum that this is for my class and we are not using PDO.

Your teacher is not very good if he/her is teaching you to use MySQL instead of the MySQLi which is the standard and has been as Kevin mentioned for years!

Anyway, In line #9, you use 8 arguments. But, in like #84, you use only 3 arguments… Hmmmm, get the hint…?

Thank you so much and yes we are going back and using my sqli later in the course.

I find it unbelievable that these “teachers” are STILL teaching obsolete coding.

Yes! 100% agreement there ! ! ! :o

Sponsor our Newsletter | Privacy Policy | Terms of Service