php - Form is failing to update mysql table -


so i'm working form admin can select multiple users database via tickbox system, change welcome message or general message client when log in:

<?php     session_start();     include_once("isadmin.php"); ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>update client message</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <?php     if( isset($_session['errmsg_arr']) && is_array($_session['errmsg_arr']) && count($_session['errmsg_arr']) >0 ) {         echo '<ul class="err">';         foreach($_session['errmsg_arr'] $msg) {             echo '<li>',$msg,'</li>';          }         echo '</ul>';         unset($_session['errmsg_arr']);     } ?> <form id="updateform" name="updateform" method="post" action="updateexec.php">   <table width="500" border="0" align="center" cellpadding="2" cellspacing="0">     <tr>       <th width="200">select user</th>       <td> <?php require_once('config.php');      //connect mysql server     $link = mysql_connect(db_host, db_user, db_password);     if(!$link) {         die('failed connect server: ' . mysql_error());     }      //select database     $db = mysql_select_db(db_database);     if(!$db) {         die("unable select database");          }   $useruploadids = mysql_query("select member_id, firstname, lastname members"); while ($row = mysql_fetch_assoc($useruploadids)) {     $userid = $row['member_id'];      $firstname = $row['firstname'];     $lastname = $row['lastname']; ?> <input type="checkbox" name="userid_<?php echo $userid ?>" value="y" /><?php echo     $firstname ?><?php echo $lastname ?><br /> <?php } ?> </td>     </tr>      <tr>       <th>message client </th>       <td>       <textarea input name="otherdeets" type="textarea" class="textfield" id="otherdeets" style="width: 356px; height: 176px">           </textarea>       </td>     </tr>       <tr>       <td>&nbsp;</td>           <td><input type="submit" name="submit" value="update" /></td>     </tr>   </table> </form> </body> </html> 

so form, , works fine, calls users database , displays them in tickbox fasion.

i can assume issue in exec script:

<?php    echo( "<pre>" );  print_r( $_post );  echo( "</pre>" );  include ("config.php");  $tbl_name="members";     //connect mysql server     $link = mysql_connect(db_host, db_user, db_password);     if(!$link) {         die('failed connect server: ' . mysql_error());     }      //select database     $db = mysql_select_db(db_database);     if(!$db) {         die("unable select database");          }   //this gets other information form   $update = $_post['otherdeets'];   $id = $_post['userid'];   // cycle through each member , check needs added db $useruploadids = mysql_query( "select member_id members" ); while ($row = mysql_fetch_assoc($useruploadids)) {     // check member sent last form     if( isset( $_post['userid_'.$row['member_id']] ) &&     $_post['userid_'.$row['member_id']] == "y" )     {   // update data in mysql database $sql="update $tbl_name set otherdeets='$update' id='$id'"; $result=mysql_query($sql);       }  }   if($result){ echo "successful"; echo "<br>"; echo "<a href='admin-welcome.php'>admin home</a>"; }  else { echo "error"; }  ?>  

when run script says:

array (     [userid_1] => y     [otherdeets] => blah blah     [submit] => update )  error  

any idea wrong? knowing luck probabaly spelling mistake

thank you

hey query wrong there should condition appropriate column name i.e. "member_id"

and 1 more thing fetching $id = $_post['userid']; error there no value exist key rather in if condition before doing update query, i.e. $id = $post['userid'.$row['member_id']];


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -