doufuxi7093 2015-06-05 04:23
浏览 46
已采纳

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

am trying to update the databse with the pubupdate.php file with the mentioned file but it is giving error Notice: Undefined index: user in C:\xampp\htdocs\Publication\form.php on line 3

Notice: Undefined index: pass in C:\xampp\htdocs\Publication\form.php on line 4. I don't know how this page is directed to form.php. However form.php has been used to create the account of the user so that user can login into the website. The login is done by the page login.php which is using the data which has been inserted in create.php. I don't know how to solve this problem and howcome pubupdate.php is directing to form.php and how to solve this problem.

I am posting the codes which I have used.

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条回答 默认 最新

  • douluan8828 2015-06-05 04:30
    关注

    In your form where you use to get the inputs i.e., Username and Password.

    You should give it a name

    Something like

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

    It is clear that you didn't give the name field in your code.

    Note :

    In addition you can have your class or id according to your need.

    Additional Note :

    For Debugging, I would recommend you to deal such errors easily by checking whether the value exists..

    You can do it easily by the below code

    if (isset($_POST['user'])) 
    {
    echo 'Username value is - '.$_POST['user'];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺