Error while updating the database for the second time with php file

I am trying to update my database named publication with a form as created in data.html. And the file pubupdate.php is used to update the database which is linked through data.html.

While updating for the next time, table project and journal are not being updated at all while other table is getting updated and giving following error.

Notice: Undefined index: projid in C:\xampp\htdocs\Publication\pubupdate.php on line 16

Notice: Undefined index: papertitle in C:\xampp\htdocs\Publication\pubupdate.php on line 20

Notice: Undefined index: jtitle in C:\xampp\htdocs\Publication\pubupdate.php on line 30 Strange Error

I am posting both the codes, please help me out as I have already spent hell lot of time in debugging it. I am new to programming this.



<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>
First Author : <br><input type = "text" name = "firstauthor">
Co-Authors : <br><input type = "text" name = "coauthor">
Title :  <br><input type = "text" name = "ptitle">
Abstract :  <br><textarea name = "abstract" rows = 10 cols = 50></textarea>
Conference / Journal Name :  <br><input type = "text" name = "namecon">
 Conference / Publication Date : <br> <input type = "text" name = "date">
Start Page No:  <br><input type = "text" name = "startpage">
End Page No: <br> <input type = "text" name = "endpage">

 Area: <br> <input type = "text" name = "area">

  Project Name 1 : <br> <input type = "text" name = "projname1">
  Project ID 1 : <br> <input type = "text" name = "projid1">
   Contribution : <br> <select name="projcont1">
   <option value="">Contribution...</option>
   <option value="10">10 </option>
   <option value="20">20</option>

  Project Name 2 : <br> <input type = "text" name = "projname2">
  Project ID 2 : <br> <input type = "text" name = "projid2">
   Contribution :  <br> <select name="projcont2">
   <option value="">Contribution...</option>
     <option value="10">10  </option>

  ISSN : <br> <input type = "text" name = "issn">
   Impact Factor : <br> <input type = "text" name = "imfac">
  ISBN : <br> <input type = "text" name = "isbn">
  SCI/ SSCI/ AHCI :  <br><input type = "text" name = "sci">
  Location : <br><select name="location">
  <option value="">Location...</option>
  <option value="domestic">Domestic</option>
 Issue :  <br><input type = "text" name = "issue">
 Volume :  <br><input type = "text" name = "volume">

  Country : <br><select name="country">
  <option value="">Country...</option>
 <option value="AF">Afghanistan</option>


  <input type ="submit" value ="Update this Publication List">




// 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";

 // 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";


header('Location: home.php');


I don’t see any form elements in your html that have the name set to projid, papertitle or jtitle. But you have included them in the top of your php code.

It doesn’t look like you’ve taken any of the advice given to you in your other topic from 2 days ago

@WebMachine I did that, I created another three field in my .html form and try to insert the value but the error which comes is “Strange Error”.

@Mittineague Which advice are you talking about among the three. Advice 3 were not of any relevance to my problem as there was problem in my html (as suggested in advice 1) form which was redirecting to form.php which was of no use and I removed it later one.
Since I am a new programmer started doing this a week ago, I really don’t have idea about SQL injection.

Your code still shows use of the DEPRECATED mysql_ functions
You are apparently still not doing any Validation or Sanitization
Your code doesn’t show any use of isset()

If you had followed the advice, most, if not all, of the problems you are asking about here would have been solved.

Welcome to the world of web dev :sparkles:

Now is the perfect time for you to learn how to do things the right way so you won’t need to unlearn and relearn later.

I see fields called ‘projid1’ and ‘projid2’ in your form, not one called ‘projid’. Same for papertitle, that seems to be ‘ptitle’ in your form - these have to be exactly the same, or when you try to reference them you will get errors. “Strange Error” tells you one of the three queries failed, but not why - try changing those messages to show which query failed, that will help you figure out what the problem is.

A couple of wikipedia articles that it’ll be worth you reading

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.