Not inserting into database (php)

#untested, so this might give some errors along the way however try it :slight_smile:


<?
$subject ='';
$content ='';
require_once '../mysql_connect.php';
#debug ****s.
echo print_r($_POST)

if ( isset($_POST['Submit']) ){   
   
    if(strlen($_POST['subject'])>0)
	{
	$subject = '1';
	}else{
		$subject = 'You forgot the subject';   
	}

	if(strlen($_POST['content'])>0)
	{
	$content = '1';
	}else{
		$content = 'You forgot the content';   
	}

	if ($subject =='1' && $content=='1')
	{      
    $image = trim($_POST['image']);
    $sql = "INSERT INTO calendar (date, subject, content, image) VALUES('".$_POST['date1']."','".$_POST['subject']."','".$_POST['content']."','".$image."')";
    
    $result = mysql_query($sql);
    $n = mysql_affected_rows();
    if ($n == 1){
        echo 'Event successfully entered!!!';
    }else{
        echo  'System Error, Contact Nathan, Sorry ;)';
    }
    mysql_close();      
 
	}
   exit();
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>calendar update</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#000000" leftmargin="0" topmargin="0">
<div id="Layer2" style="position:absolute; left:14px; top:-8px; width:654px; height:223px; z-index:2">
  <form name="form1" method="post" action="<?$_SERVER['PHP_SELF']?>">
    <p align="center"><br>
      <br>
      <span><strong>Calendar Update Page </strong> </span></p>
    <table width="95%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td >Date : </td>
        <td ><select name="date1" id="date1">
            <option>Jan</option>
            <option>Feb</option>
            <option>Mar</option>
            <option>Apr</option>
            <option>May</option>
            <option>Jun</option>
            <option>Jul</option>
            <option>Aug</option>
            <option>Sep</option>
            <option>Oct</option>
            <option>Nov</option>
            <option>Dec</option>
          </select>
            <select name="date2" id="date2">
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
              <option>6</option>
              <option>7</option>
              <option>8</option>
              <option>9</option>
              <option>10</option>
              <option>11</option>
              <option>12</option>
              <option>13</option>
              <option>14</option>
              <option>15</option>
              <option>16</option>
              <option>17</option>
              <option>18</option>
              <option>19</option>
              <option>20</option>
              <option>21</option>
              <option>22</option>
              <option>23</option>
              <option>24</option>
              <option>25</option>
              <option>26</option>
              <option>27</option>
              <option>28</option>
              <option>29</option>
              <option>30</option>
              <option>31</option>
            </select>
            <select name="date3" id="date3">
              <option>04</option>
              <option>05</option>
              <option>06</option>
              <option>07</option>
              <option>08</option>
          </select></td>
      </tr>
      <tr>
        <td >Subject:</td>
        <td >
		<?
		if ($subject !='1')
		{
		echo '<input name="subject" type="text" id="subject" size="50">'.$subject;
		}else
		{
			echo '<input name="subject" type="text" id="subject" size="50" value="'.$_POST['subject'].'">';
		}
		?>
		</td>
      </tr>
      <tr>
        <td >Content:</td>
        <td >
		<?
		if ($subject !='1')
		{
		echo '<textarea name="content" cols="50" rows="4" id="content"></textarea>'.$subject;
		}else
		{
			echo '<textarea name="content" cols="50" rows="4" id="content">"'.$_POST['content'].'"</textarea>';
		}
		?>
	</td>
      </tr>
      <tr>
        <td >Image Name(include extention):</td>
        <td ><input name="image" type="text" id="image" size="25"></td>
      </tr>
      <tr>
        <td >&nbsp;</td>
        <td ><input type="submit" name="Submit" value="Submit">
        <input type="reset" name="Reset" value="Reset"></td>
      </tr>
    </table>
    <p>Remember the image needs to be uploaded before you will be able to see it. </p>
    <p><br>
    </p>
  </form>
</div>
<table width="780" height="297" border="0" cellpadding="0" cellspacing="0" bgcolor="#00A0DE">
  <tr>
    <td height="102"><div align="center"><span class="style4 style3 style11"><br>
  <br>
      </span></div></td>
  </tr>
</table>
<?php
include ('templates/links.inc');
?>
</body>
</html> 

That suppresses the mysql error message sent to your browser. It’s a good thing to use in a lot of circumstances. One of the big reasons is php doesn’t output errors “defaultly” (word?) very well. Instead it spits out your file name and path, which isn’t the most secure method when you are dealing with dynamic pages. So you can suppress that by using the ‘@’ symbol in front of a php function.

thanks marble,

ol4pro, thanks, i havent tried the script yet but i will soon