提交返回空白页面

A blank page is returned when I try to add a new note. My code is in php and the DB is mysql

This is the php code:

if (isset($_POST['Submit'])) {

$candidate_id = $_POST['candidate_id'];
$Notes=$_POST['notes'];
if ($Notes != "") {

$sql3="INSERT INTO notes (notes_id, candidate_id, notes)
VALUES(DEFAULT,'$candidate_id','$Notes')";

$result3=mysql_query($sql3);

if (!$result3)
{
die('Error: ' . mysql_error());
 }
 echo "</br>1 note added"

  }
  }
 mysql_close();

The code for the form

<div id ="tab3">
    <h2> Notes </h2>
    <dl><dt>Notes</dt><dd><textarea id="notes" style="width: 80%; height: 150px;" name="notes"></textarea></dd></dl>
          <?php   echo "<a href =newCandidate.php?id=$contact_id><input style =\"right:2em; bottom:1em;\" type =\"button\" name =\"update\" value =\"Submit\"></a>";
       ?>   </div>

try

if($_SERVER['REQUEST_METHOD']=="POST"){

or

if(isset($_POST['update'])){

instead of

 if (isset($_POST['Submit'])) {

the name of the submit button is update not Submit on your form

also stop using mysql_* functions. If you have to use them for now, at least escape the inputs properly before inserting them to database.

To sum this up:

use error reporting in the beginning of your script

error_reporting(E_ALL);

Echo out the SQL query (after you created it) to see what weird, unescaped stuff you want to send to the server:

echo $sql3;
exit; // to prevent execution

Try the echoed SQL with phpmyadmin to see if the problem is your query or the missing database connection.

There are a lot more bad things in your script, but for first error-tracing those tips might be okay... In general, i recommend you to completely rewrite this after you read into SQL injection, modern database query methods, proper php coding etc. ! To finish your project, you should consider using a micro framework to get quick and secure results.

in your submit button you have no form

try this

      <div id ="tab3">
  <h2> Notes </h2>
 <dl><dt>Notes</dt><dd><form action="" method="post" name="myform"><textarea id="notes" style="width: 80%; height: 150px;" name="notes"></textarea></dd></dl>
      <?php   echo "<a href =newCandidate.php?id=$contact_id><input style =\"right:2em; bottom:1em;\" type =\"button\" name =\"update\" value =\"Submit\"></a></form>";
    ?>   </div>
  • and please avoid using inner css , please use classes in other css file.

Try This

<?php
if(isset($_POST['submit'])){                

    // Code 

<?php
 }
else
{ 
echo "form not submited properly";
}
?> 

<?php
include 'header.php';
include 'nav.php';
include 'config.php';
?>

Except

<?php
include 'header.php';
include 'nav.php';
include 'config.php';
?>

<?php
if(isset($_POST['submit'])){                

    // Code 

<?php
 }
else
{ 
echo "form not submited properly";
}
?>