HI guys i have a little problem while i post the data that is class_id and subject_id to my db with it extra field is generated having zero in class_id and subject_id e.g below
Edit Delete 0 0
Edit Delete 315 1

beside the original ids.here is my code below i cant figure it out that why is this happening can someone help me



$con = mysql_connect("localhost","root","");
if ($con)
/*  die('connected: ' );*/
	  die ("not connected");

$db_selected = mysql_select_db("project", $con);

  $subject = $_POST['subject_name'];
  $id = $_POST['id2'];

	///insertion code
$sql = mysql_query("INSERT INTO `connection` (subject_id,class_id) VALUES ('$subject','$id') ");




<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/div_validation.js"></script>

<link rel="stylesheet" type="text/css" href="css/connection.css" />



                  <div id="form2">
                    <center id="Center">
                    Enter Subject
                    <hr id="new">
                    <center class="Center">
<form id="class" class="class" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"  style="width:600px">
                   <div class="test">
                    <select class="form-dropdown" style=" 
    width: 150px;" >
                    <option>  </option>
                    <option value="Option 1"> Option 1 </option>
                    <option value="Option 2"> Option 2 </option>
                    <option value="Option 3"> Option 3 </option>
                    <label class="label1"> Go to
                    <p class="name1"> 
                    <select  id="id2" name="id2">
                    <option value="" selected="true"></option>
                    <option value="315">315</option>
                    <option value="316">316</option>
                    <option value="317">317</option> 
                    <label for="name"><i>Class id</i></label> 
                    <p class="name">  
                    <select id="subject_name" name="subject_name">
                    <option value="" selected="true"></option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>  
                     <label for="name"><i>Subject id</i></label> 
                    <p class="submit">  
                    <input type="submit"  id="submit"value="Submit"  />  

                    <div id="msg"></div>
                    <color> <horizontal offset> <vertical offset> <blur> 


Edited by extemer: n/a

5 Years
Discussion Span
Last Post by cgull

Could you clarify the problem more than this?
What do you mean by:

Edit Delete 0 0
Edit Delete 315 1

If the problem is in inserting the data into MySQL, then replace the line #25 with:

$sql = mysql_query("INSERT INTO connection (subject_id,class_id) VALUES ('$subject','$id')") or die(mysql_error());

Edited by Pro2000: n/a


I think it might be because of these lines:

<option value="" selected="true"></option>

It sees the option as selected and inserts value 0 into the table.


i have done it but the problem is when the page refresh after selecting value it insert extra row of class_id zero and sub_id zero


i figure out the problem its was in insert query as the class_id was first field of the table and subject_id was second and put it second one field in first place and first one in second.Here is query below.

$sql = mysql_query("INSERT INTO `connection` (subject_id,class_id) VALUES ('$id','$subject') ")or die(mysql_error());

Correct one

$sql = mysql_query("INSERT INTO `connection` (class_id,subject_id) VALUES ('$id','$subject') ")or die(mysql_error());

Thanks for the concern

Edited by extemer: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.