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 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同