使用多个php文件更新数据库时出错

时间:2015-06-05 04:23:43

标签: php mysql forms

我正在尝试使用带有上述文件的pubupdate.php文件更新数据库但是它给出了错误提示:未定义的索引:第3行的C:\ xampp \ htdocs \ Publication \ form.php中的用户

注意:未定义的索引:在第4行传递C:\ xampp \ htdocs \ Publication \ form.php。我不知道如何将此页面定向到form.php。但是,form.php已用于创建用户帐户,以便用户可以登录该网站。登录由login.php页面完成,该页面使用已插入create.php中的数据。我不知道如何解决这个问题,以及如何解决pubupdate.php指向form.php以及如何解决这个问题。

我发布了我用过的代码。

pubupdate.php

 <?php

$typereg = $_POST['papertype'];
$ptitlereg = $_POST['ptitle'];
$fauthorreg = $_POST['firstauthor'];
$coauthorreg = $_POST['coauthor'];
$abstractreg = $_POST['abstract'];
$nameconreg = $_POST['namecon'];
$areareg = $_POST['area'];
$datereg = $_POST['date'];
$startpagereg = $_POST['startpage'];
$endpagereg = $_POST['endpage'];
$countryreg = $_POST['country'];


$taken = "false";
$database = "publication";
$password = "";
$username = "root";


$con = mysql_connect('localhost', $username, $password) or die("Unable to connect database");
 @mysql_select_db($database, $con) or die("Unable to connect");

 mysql_query("INSERT INTO `paper` VALUES('$typereg', '$ptitlereg','$fauthorreg','$coauthorreg','$abstractreg' ,'$nameconreg', '$areareg','$datereg', '$startpagereg', '$endpagereg', '$countryreg' )") or die("Strange Error");

echo "Account Created";

 mysql_close($con);

 header('Location: home.php');

 ?>

form.php的

<?php

$userreg = $_POST['user'];
$passreg = $_POST['pass'];



$taken = "false";
$database = "publication";
$password = "";
$username = "root";


if($userreg && $passreg){



 $con = mysql_connect('localhost', $username, $password) or die("Unalbe to  connect database");
 @mysql_select_db($database, $con) or die("Unalbe to connect");

 mysql_query("INSERT INTO `users` VALUES('', '$userreg', '$passreg')") or die("Strange Error");

 echo "Account Created";

 mysql_close($con);

  header("Location : index.html");

 } else {

 echo "You need to have both a username and password";
 }


 ?>

create.php

<?php

 $userreg = $_POST['user'];
$passreg = $_POST['pass'];
$fnamereg = $_POST['fname'];
$lnamereg = $_POST['lname'];
$desigreg = $_POST['designation'];




 $taken = "false";
 $database = "publication";
 $password = "";
 $username = "root";


 if($userreg && $passreg){



 $con = mysql_connect('localhost', $username, $password) or die("Unable to connect database");
 @mysql_select_db($database, $con) or die("Unable to connect");

 mysql_query("INSERT INTO `users` VALUES('', '$userreg','$passreg','$fnamereg','$lnamereg' ,'$desigreg')") or die("Strange Error");

 echo "Account Created";

  mysql_close($con);

  header('Location: index.html');

  } else {

  echo "You need to have both a username and password";
   }
   ?>

1 个答案:

答案 0 :(得分:2)

在您用于获取输入的表单中,即用户名和密码。

你应该给它一个名字

类似

<input type='text' name='user'>
<input type='password' name='pass'>

很明显,您没有在代码中提供name字段。

注意:

此外,您可以根据自己的需要获得课程或ID。

附加说明:

对于调试,我建议您通过检查值是否存在来轻松处理此类错误。

您可以通过以下代码轻松完成

if (isset($_POST['user'])) 
{
echo 'Username value is - '.$_POST['user'];
}