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.

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


 // 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');



?>

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

http://en.wikipedia.org/wiki/Secure_input_and_output_handling

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