Page 1 of 1

php submit and updat mysql in multi input form

Posted: Tue Jan 06, 2009 11:23 am
by aneeshtan
Hi

I wana write a php menu system for my portal and i need to submit all the input box by just clicking only on one button

this is my code !?

Code: Select all

 
    echo "<form action=\"\" method=\"POST\">
    <table border=\"0\" align=\"center\" width=\"100%\">
    <tr>
    <td bgcolor=\"#F0F0F0\" width=\"15%\">&nbsp;<b>name</b></td>
    <td bgcolor=\"#F0F0F0\" width=\"15%\">&nbsp;<b>url</b></td>
    <td bgcolor=\"#F0F0F0\" >&nbsp;<b>category</b></td>
    <td bgcolor=\"#F0F0F0\" align=\"center\">&nbsp;<b>place number</b>&nbsp;</td>
    </tr>"; 
/*  $num = $db->sql_numrows($db->sql_query("SELECT mid FROM fgh_menu"));if ($num = 0) {}
            $sql =$db->sql_query("SELECT *  FROM  fgh_menu_items where active=0");
            while ($row = $db->sql_fetchrow($sql)) {
            $tid = intval($row['tid']);
            $title = $row['title'];
            $url = $row['url'];*/
 
    $act =$db->sql_query("SELECT * FROM  menu_items where active=1");   
 
        while ($row = $db->sql_fetchrow($act)) {
        $title = $row['title'];
        $url = $row['url'];
        $etid = intval($row['tid']);
 
        
    $act2 =$db->sql_query("SELECT * FROM  menu where tid='$etid'");     
        while ($row4 = $db->sql_fetchrow($act2)) {
        $cid = intval($row4['cid']);
        $mid = intval($row4['mid']);
        
        }
echo "<form method=\"post\"  action=\"admin.php?op=fghMenu\" ><tr onMouseOver=\"this.style.backgroundColor='#FFFFB9';\"  onMouseOut=\"this.style.backgroundColor='#ECFAFF';\" 
onclick=\"this.style.backgroundColor='#FFFF0D';\">
<td ><input type='text' dir='rtl' name='title' id='title' size='20' maxlength='20' value='$title'></td>
<td ><input type='text' dir='rtl' name='url' id='url' size='20' maxlength='20' value='$url'></td>
<td ><input type='text' dir='rtl' name='etid' id='etid' size='5' maxlength='5' value='$etid'></td>
<td >";
SelectCategory();
echo "</td >";
echo "<td >
<input name='em' id='em'  type=\"submit\" value='update'></td>";
}       
        
 
echo "</tr></table>";   
 
if( isset($_POST['em'])){
    while($counter<=($_POST['etid']-1)){
    
    $title = mysql_real_escape_string($_POST['title']);
    $url = mysql_real_escape_string($_POST['url']);
    $etid =  $_POST['etid'];
    $cat_id = $_POST['cat_id'];
    $result2 = $db->sql_query("UPDATE fgh_menu SET cid='$cat_id' where tid='$etid'");
$counter++;}
    
    }
 
 
// cid is the category id

but when i click the button it just update one row

help me with the code

thank you

Re: php submit and updat mysql in multi input form

Posted: Thu Jan 08, 2009 9:12 am
by cptnwinky
Could you put that in php tags rather than code tags please? I think your problem might be one of syntax and it would be a lot easier to tell with syntax highlighting.

Re: php submit and updat mysql in multi input form

Posted: Thu Jan 08, 2009 9:22 am
by aneeshtan
here u r

thanx 4 reply

Re: php submit and updat mysql in multi input form

Posted: Thu Jan 08, 2009 9:43 am
by cptnwinky
If I understand the code correctly your creating several seperate forms. What you want to do is only create one form and loop over the elements instead. You also have to change the name of the form elements (input tags) on each itteration or each field will have the same value, for instance $_POST['etid'] will be overwritten by each form element with the same name unless you add some kind of distinctive value to it; something like $_POST['etid-1'], $_POST['etid-2'], etc.

Does that make sense?

Re: php submit and updat mysql in multi input form

Posted: Thu Jan 08, 2009 10:07 am
by aneeshtan
this is a script for building java menu and this part of the code that i included is administration section .

so i need a while {} to show available titles , urls , place numbers and category

therefore i will have some inputs that i wana be able to update them by clicking just on submit button

my main problem is about the last part of the code , when i need to update them in mysql database .

question is " how to update all the inputs "

if u can plz help me in code way so i can understand better . or correct my attached codes

thanx mate

Re: php submit and updat mysql in multi input form

Posted: Thu Jan 08, 2009 11:58 am
by 水车老大
form不能嵌套吧!
也没有找到form的结束!