警告:缺少renderForm()的参数4

时间:2018-01-03 17:39:51

标签: php html mysql

早上好/下午好,

有人可以向我解释为什么我一直得到一个;

Warning: Missing argument 4 for renderForm(), called in /home/***/public_html/new.php

这是我正在使用的HTML / 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($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('','','');

}

?>
&#13;
&#13;
&#13;

我试图在这里搜索并没有修复谷歌。有人可以帮我吗?这应该是添加新事件的表单。但是由于这些错误,我无法使其发挥作用。提前感谢您提供的任何帮助。

原始部分已完成。谢谢你的所有答案。但现在我提交后它给了我这个错误,不确定它是否与我编辑的内容有关:

&#13;
&#13;
renderForm(null,null,null,null,null,null);
&#13;
&#13;
&#13;

再次感谢你。

2 个答案:

答案 0 :(得分:0)

renderForm('','','');代码底部缺少第四个参数。

答案 1 :(得分:0)

您的功能如下:

function renderForm($date, $home, $time, $away, $city, $error){}

你需要将六个总参数传递给函数,

  • $日期
  • $ HOME
  • $时间
  • $远
  • $城市
  • $误差

因此,您必须为每个

填充函数调用
renderForm(null,null,null,null,null,null);

或者您可以使用''示例中显示的空字符串。但是必须为每个论点传递一些东西。