Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-14-2012, 11:05 AM   PM User | #1
Abi89
New to the CF scene

 
Join Date: Feb 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Abi89 is an unknown quantity at this point
Dropdown For the Registration Form not to be refreshed on submit and if error present

I have a form named reg.php and its action is reg.php , i want the selected dropdown value when clicked on submit to remain selected , what i have done so far is given below


PHP Code:

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

$selected_value $_POST['selectID'];
$query mysql_query("SELECT  linecard_name FROM selection WHERE select_id = '$selected_value'");
$rows=mysql_fetch_assoc($query); 
$linecard_name$rows['linecard_name'];
$sql "SELECT select_id, linecard_name FROM selection " "ORDER BY linecard_name";
$rs mysql_query($sql);

while(
$rownw mysql_fetch_array($rs)){
if(  
$rownw['linecard_name'] == $linecard_name)  {
$options "<option  selected =selected  value=".$rownw['select_id']."> " .$rownw['linecard_name']. " </option> ";
}

}
}


require(
"./connect.php");
$sql "SELECT select_id, linecard_name FROM selection ""ORDER BY linecard_name";
$rs mysql_query($sql);

while(
$rownw mysql_fetch_array($rs)){
 
$options .= "<option value = ".$rownw['select_id']." > ".$rownw['linecard_name']. " </option> ";

mysql_close() ;

$form "<form action='./reg.php'  method='post'> 
<table>
<tr>
<td>  </td>
<td>  <font color='red'> $errormsg </font> </td> 
</tr>


<tr>
<td> Select  Linecard </td> 
<td> <Select name='selectID' >  <option value = '0'>  Select  from here </option> $options  </select></td> 

<tr> 
<td  > <input type='submit' name='registerbtn' value='Register' />   </td> 
</tr> 
</table> 

echo $form;

Last edited by Abi89; 06-15-2012 at 05:33 AM..
Abi89 is offline   Reply With Quote
Old 06-14-2012, 12:34 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
I don't get the purposes of all those SELECT queries in your code or the use of the involved tables in them. Anyway, you'd need something like
PHP Code:
$sql "SELECT select_id, linecard_name FROM selection ""ORDER BY linecard_name";
$rs mysql_query($sql); 
----------------------
PHP Code:
echo '<Select name="selectID" >  
<option value ="0">  Select  from here </option>'
;
while(
$row=mysql_fetch_assoc($rs)){

printf("<option value=\"%s\" %s>%s</option"$row['select_id'],
$row['select_id']==$selected_value'selected="selected"':'',
$row['linecard_name']);
}

echo 
'</select>'
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 06-15-2012, 05:42 AM   PM User | #3
Abi89
New to the CF scene

 
Join Date: Feb 2012
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Abi89 is an unknown quantity at this point
The select statements before the register button is clicked is for filling the dropdown from the database with ,
I just want the selected items to remain selected when the particular selection is done by the user and register button is clicked ,
in which case my code fills the dropdown again but now with the user selected item as selected but without clearing the previous items filled in the dropdown i.e before the register button is clicked,
Please help
Abi89 is offline   Reply With Quote
Reply

Bookmarks

Tags
css, html, php, sql

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:09 AM.


Advertisement
Log in to turn off these ads.