I HAVE ONE FORM IN THIS I AM INSERTING AND UPDATIONG BOTH, I WANT TO RETAIN the value of combox box when php validations occurs

<td>Page Id</td>
      <td><select name='pageID' class="select">
          <option  value='0' >select any page</option>

$sql10 = "SELECT ID,Title FROM page";
$rs = mysql_query($sql10) or die(mysql_error());
while($row = mysql_fetch_array($rs)){
$selected = ($val == $row['ID'] ? 'selected="selected"' : '');
echo '<option value ="' . $row['ID'] . '" '. $selected .'>' . $row['Title'] . '</option>';

want that if php validation ouccur the value of the combox still not changed

You can use the code below. Replace the respective values with the ones that apply to your code.

<select name="pageId">
                    // I used the $_GET method. You could be using $_POST
                    $subject_id = $_GET['subject_id'];

                    // display a drop down of all categories with the chosen category preselected
                    $query = mysql_query("SELECT * FROM subjects WHERE subject_id = '$subject_id'");
                    while ($row = mysql_fetch_assoc($query)) 
                        $sub_id = $row['subject_id'];
                        $subject_name = $row['subject'];

                        if ($sub_id == $subject_id) 
                            $selected = "selected='selected'";
                            $selected = "selected = 'none'";

                        echo "<option value='$subject_name' $selected>$subject_name</option>\n";

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.