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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据