我正在尝试使用 data.html 中创建的表单更新名为发布的数据库。文件 pubupdate.php 用于更新通过 data.html 链接的数据库。
第一次更新时,它正在更新数据库,但 projcont1 = NULL,projcont2 = NULL,volume = NULL,startpage with endpage 和 endpage = NULL 。休息一切都很好。 已解决的问题
在下次更新时,表项目和日志根本没有更新,而其他表正在更新并发出以下错误。
注意:未定义的索引:第16行的C:\ xampp \ htdocs \ Publication \ pubupdate.php中的projid
注意:未定义的索引:第20行的C:\ xampp \ htdocs \ Publication \ pubupdate.php中的papertitle
注意:未定义的索引:第30行的C:\ xampp \ htdocs \ Publication \ pubupdate.php中的jtitle 奇怪的错误
我发布了这两个代码,请帮助我,因为我已经花了很多时间来调试它。我是编程的新手。
data.html
<html>
<title> Publication v.0.0.1 </title>
<div align = "center">
<form action = "pubupdate.php" method = "post">
<p>Paper Type :<br> <select name="papertype"></p>
<option value="">Paper Type...</option>
<option value="journaltype">Journal</option>
<option value="conferencetype">Conference</option>
</select>
<br></br>
First Author : <br><input type = "text" name = "firstauthor">
<br></br>
Co-Authors : <br><input type = "text" name = "coauthor">
<br></br>
Title : <br><input type = "text" name = "ptitle">
<br></br>
Abstract : <br><textarea name = "abstract" rows = 10 cols = 50></textarea>
<br></br>
Conference / Journal Name : <br><input type = "text" name = "namecon">
<br></br>
Conference / Publication Date : <br> <input type = "text" name = "date">
<br></br>
Start Page No: <br><input type = "text" name = "startpage">
<br></br>
End Page No: <br> <input type = "text" name = "endpage">
<br></br>
Area: <br> <input type = "text" name = "area">
<br></br>
Project Name 1 : <br> <input type = "text" name = "projname1">
<br></br>
Project ID 1 : <br> <input type = "text" name = "projid1">
<br></br>
Contribution : <br> <select name="projcont1">
<option value="">Contribution...</option>
<option value="10">10 </option>
<option value="20">20</option>
</select>
<br></br>
Project Name 2 : <br> <input type = "text" name = "projname2">
<br></br>
Project ID 2 : <br> <input type = "text" name = "projid2">
<br></br>
Contribution : <br> <select name="projcont2">
<option value="">Contribution...</option>
<option value="10">10 </option>
</select>
<br></br>
ISSN : <br> <input type = "text" name = "issn">
<br></br>
Impact Factor : <br> <input type = "text" name = "imfac">
<br></br>
ISBN : <br> <input type = "text" name = "isbn">
<br></br>
SCI/ SSCI/ AHCI : <br><input type = "text" name = "sci">
<br></br>
Location : <br><select name="location">
<option value="">Location...</option>
<option value="domestic">Domestic</option>
</select>
<br></br>
Issue : <br><input type = "text" name = "issue">
<br></br>
Volume : <br><input type = "text" name = "volume">
<br></br>
Country : <br><select name="country">
<option value="">Country...</option>
<option value="AF">Afghanistan</option>
</select>
<br></br>
<input type ="submit" value ="Update this Publication List">
</form>
</div>
</html>
pubupdate.php
<?php
// Updating the values of Table "Paper"
$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'];
$projidreg = $_POST['projid'];
$countryreg = $_POST['country'];
// Updating the values of Table "Project"
$papertitlereg = $_POST['papertitle'];
$projname1reg = $_POST['projname1'];
$projid1reg = $_POST['projid1'];
$projcont1reg = $_POST['projcont1'];
$projname2reg = $_POST['projname2'];
$projid2reg = $_POST['projid2'];
$projcont2reg = $_POST['projcont2'];
// Updating the values of Table "Journal"
$issnreg = $_POST['issn'];
$jtitlereg = $_POST['jtitle'];
$imfacreg = $_POST['imfac'];
$isbnreg = $_POST['isbn'];
$scireg = $_POST['sci'];
$locationreg = $_POST['location'];
$issuereg = $_POST['issue'];
$volumereg = $_POST['volume'];
// Create Local variable
$taken = "false";
$database = "publication";
$password = "";
$username = "root";
// Main if statement
//if($userreg && $passreg){
// Connect to database
$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");
mysql_query("INSERT INTO `journal` VALUES('$issnreg', '','$imfacreg','$isbnreg','$scireg' ,'$locationreg', '$issuereg','$volumereg')") or die("Strange Error");
mysql_query("INSERT INTO `project` VALUES( '','$projname1reg','$projid1reg','$projcont1reg' ,'$projname2reg', '$projid2reg','$projcont2reg')") or die("Strange Error");
echo "Account Created";
mysql_close($con);
header('Location: home.php');
?>
答案 0 :(得分:0)
请尝试以下代码。我已经添加了检查是否存在值,如果某个值不存在则会添加“NA”,您可以根据需要更改此字符串。下面的代码将帮助您进行更多调试。
<?php
//$userreg = isset() ? htmlspecialchars($_POST['user']);
//$passreg = isset() ? htmlspecialchars($_POST['pass']);
// Updating the values of Table "Paper"
$typereg = isset($_POST['papertype']) ? htmlspecialchars($_POST['papertype']):"NA";
$ptitlereg = isset($_POST['ptitle']) ? htmlspecialchars($_POST['ptitle']):"NA";
$fauthorreg = isset($_POST['firstauthor']) ? htmlspecialchars($_POST['firstauthor']):"NA";
$coauthorreg = isset($_POST['coauthor']) ? htmlspecialchars($_POST['coauthor']):"NA";
$abstractreg = isset($_POST['abstract']) ? htmlspecialchars($_POST['abstract']):"NA";
$nameconreg = isset($_POST['namecon']) ? htmlspecialchars($_POST['namecon']):"NA";
$areareg = isset($_POST['area']) ? htmlspecialchars($_POST['area']):"NA";
$datereg = isset($_POST['date']) ? htmlspecialchars($_POST['date']):"NA";
$startpagereg = isset($_POST['startpage']) ? htmlspecialchars($_POST['startpage']):"NA";
$endpagereg = isset($_POST['endpage']) ? htmlspecialchars($_POST['endpage']):"NA";
$countryreg = isset($_POST['country']) ? htmlspecialchars($_POST['country']):"NA";
// Updating the values of Table "Project"
$papertitlereg = isset($_POST['papertitle']) ? htmlspecialchars($_POST['papertitle']):"NA";
$projname1reg = isset($_POST['projname1']) ? htmlspecialchars($_POST['projname1']):"NA";
$projid1reg = isset($_POST['projid1']) ? htmlspecialchars($_POST['projid1']):"NA";
$projcont1reg = isset($_POST['projcont1']) ? htmlspecialchars($_POST['projcont1']):"NA";
$projname2reg = isset($_POST['projname2']) ? htmlspecialchars($_POST['projname2']):"NA";
$projid2reg = isset($_POST['projid2']) ? htmlspecialchars($_POST['projid2']):"NA";
$projcont2reg = isset($_POST['projcont2']) ? htmlspecialchars($_POST['projcont2']):"NA";
// Updating the values of Table "Journal"
$issnreg = isset($_POST['issn']) ? htmlspecialchars($_POST['issn']):"NA";
$jtitlereg = isset($_POST['jtitle']) ? htmlspecialchars($_POST['jtitle']):"NA";
$imfacreg = isset($_POST['imfac']) ? htmlspecialchars($_POST['imfac']):"NA";
$isbnreg = isset($_POST['isbn']) ? htmlspecialchars($_POST['isbn']):"NA";
$scireg = isset($_POST['sci']) ? htmlspecialchars($_POST['sci']):"NA";
$locationreg = isset($_POST['location']) ? htmlspecialchars($_POST['location']):"NA";
$issuereg = isset($_POST['issue']) ? htmlspecialchars($_POST['issue']):"NA";
$volumereg = isset($_POST['volume']) ? htmlspecialchars($_POST['volume']):"NA";
// Create Local variable
$taken = "false";
$database = "publication";
$password = "";
$username = "root";
// Main if statement
//if($userreg && $passreg){
// Connect to database
$con = mysqli_connect('localhost', $username, $password,$database);
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
mysqli_query($con,"INSERT INTO `paper` VALUES('$typereg', '$ptitlereg','$fauthorreg','$coauthorreg','$abstractreg' ,'$nameconreg', '$areareg','$datereg', '$startpagereg', '$endpagereg','$projid1reg','$countryreg' )") or die("Strange Error");
mysqli_query($con,"INSERT INTO `journal` VALUES('$issnreg', '$ptitlereg','$imfacreg','$isbnreg','$scireg' ,'$locationreg', '$issuereg','$volumereg')") or die("Strange Error");
mysqli_query($con,"INSERT INTO `project` VALUES( '$ptitlereg','$projname1reg','$projid1reg','$projcont1reg' ,'$projname2reg', '$projid2reg','$projcont2reg')") or die("Strange Error");
echo "Account Created";
mysqli_close($con);
header('Location: home.php');
//} else {
//echo "You need to have both a username and password";
//}
?>