gpt4 book ai didi

php - 使用php文件第二次更新数据库时出错

转载 作者:行者123 更新时间:2023-11-29 22:21:22 24 4
gpt4 key购买 nike

我正在尝试使用 data.html 中创建的表单更新名为 publication 的数据库。文件pubupdate.php用于更新通过data.html链接的数据库。

第一次更新时,它会更新数据库,但projcont1 = NULL,projcont2= NULL,volume= NULL,startpage with endpageendpage= 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');



?>

最佳答案

请尝试以下代码。我添加了检查值是否存在的功能,如果值不存在,则会添加“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";
//}


?>

关于php - 使用php文件第二次更新数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30680823/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com