adding in a database problem

Page 1 of 1

0 Replies - 210 Views - Last Post: 06 October 2013 - 05:57 AM Rate Topic: -----

#1 christina_pia  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 06-October 13

adding in a database problem

Posted 06 October 2013 - 05:57 AM

Hello guys, sorry if my english is kind of bad but I'll do my best for you to understand me clearly. I'm trying to make a class scheduling system. and I'm currently working with the add button, as of now when I click the add button the user should input the data that she wants to add, if the user click the submit button without data's on the field the message that come's out is "SOME TEXT MISSING" which is correct but it still adds into the database even if there's no informations on the fields. Here are my codes:

this is my add.php
<form action="In.php" method="get">

<?php

$time=$_GET['time'];
$subject=$_GET['subject'];
$course=$_GET['course'];
$section=$_GET['section'];
$day=$_GET['day'];
$room=$_GET['room'];

?>

<table>
<tr>
<td>Time:</td><td> <input type="text" name="time" value="<?php echo $time; ?>" />
<?php
if($time=="")
{
	?>
    <font color="#FF0000">*</font>
    <?php	
} 
?>
</td>

<tr></tr>
<td>Subject:</td><td><input type="text" name="subject" value="<?php echo $subject; ?>" />
<?php
if($subject=="")
{
	?>
    <font color="#FF0000">*</font>
    <?php	
} ?>
</td>
<tr></tr>
<td>Course:</td><td> <input type="text" name="course" value="<?php echo $course; ?>" />
<?php
if($course=="")
{
	?>
    <font color="#FF0000">*</font>
    <?php	
} ?>
</td>
<tr></tr>
<td>Section:</td><td> <input type="text" name="section" <?php echo $section; ?> />
<?php
if($section=="")
{
	?>
    <font color="#FF0000">*</font>
    <?php	
} ?>
</td>
<tr></tr>
<td>Day:</td><td> <input type="text" name="day" value="<?php echo $day; ?>" />
<?php
if($day=="")
{
	?>
    <font color="#FF0000">*</font>
    <?php	
} ?>
</td>
<tr></tr>
<td>Room:</td><td><input type="text" name="room" value="<?php echo $room; ?>" />
<?php
if($room=="")
{
	?>
    <font color="#FF0000">*</font>
    <?php	
} ?>
</td>
<tr></tr>

<td><input type="submit" value = "SUBMIT" name="submit"/></td><td><a href="index.php" style="text-decoration:none;"><input type="button" value="CANCEL" /></a></td>
</table>
</form>


and this is In.php
<form action="add.php" method="get">
<?php
$time=$_GET['time'];
$subject=$_GET['subject'];
$course=$_GET['course'];
$section=$_GET['section'];
$day=$_GET['day'];
$room=$_GET['room'];
$vtest1=0;
?>



<?php
$con = mysql_connect("localhost","pma");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("class_schedule", $con);




$sql="INSERT INTO schedule (time, subject, course, section, day, room)
VALUES
('$_POST[time]','$_POST[subject]','$_POST[course]','$_POST[section]','$_POST[day]', '$_POST[room]')";
?>

<input type="hidden" name="time" value="<?php echo $time; ?>"/>
<input type="hidden" name="subject" value="<?php echo $subject; ?>"/>
<input type="hidden" name="course" value="<?php echo $course; ?>"/>
<input type="hidden" name="section" value="<?php echo $section; ?>"/>
<input type="hidden" name="day" value="<?php echo $day; ?>"/>
<input type="hidden" name="room" value="<?php echo $room; ?>"/>

<?php

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

if($time=="")
{
	$vtest=1;	
}
if($subject=="")
{
	$vtest=1;	
}
if($course=="")
{
	$vtest=1;	
}
if($section=="")
{
	$vtest=1;	
}
if($day=="")
{
	$vtest=1;	
}
if($room=="")
{
	$vtest=1;	
}
if($vtest==1)
{
	?>  <center>
	<?php echo "SOME DATA ARE MISSING";	?> <br /><br />
	<input type="submit" value="BACK"  /></center>
    <?php
}
  else
  {
  echo "<center>1 record added!</center>";
  echo "<center><input type='button' name='Ok' onclick='window.location.href='index.php'></center>";
  }

mysql_close($con)
?> 
</form>


What am I doing wrong? :( Hoping that somebody would help me. :'(

Is This A Good Question/Topic? 0
  • +

Page 1 of 1