Php checkbox is checked, then mysql update 1, and if not checked mysql update 0 -


echo "<form method='post' action=''><br>"; $query = mysql_query("set names 'utf8'"); $query = mysql_query("   select * pages user_id = '$_session[user_id]' ") or die(mysql_error());  while($pagek = mysql_fetch_array($query)) {   $name = $pagek['page_name'];   $pageid = $pagek['page_id'];   echo '<input type="checkbox" name="page_ids[]" value="'.$pageid.'">'       .$name       ."<br>"; }  echo "<br>       <input type='submit'              value='adatok frissítése'              name ='adat'              class='button small radius center black'       >"; echo "</form>";  foreach($_post['page_ids'] $page){   if ($page){     mysql_query("       update pages       set    page_value = '0'        user_id = '$_session[user_id]'     ");     mysql_query("       update pages       set    page_value = '1'        user_id = '$_session[user_id]'          , page_id = '$page'     ");   } } 

i like, if checkbox checked mysql update 1, , more 0.

this code not good, here in site update on getting rest zero, , can choose site

first!

please, don't use mysql_* functions in new code. no longer maintained and officially deprecated. see red box? learn prepared statements instead, , use pdo or mysqli - this article decide which. if choose pdo, here tutorial.

seriously, code contains serious vulnerability called sql injection. if don't fix it, website can , will compromised easily.


unchecked checkboxes do not submitted @ all. basically, server won't see anything.

to take account, should set 0 default, unconditionally, , then, if checkbox checked, set 1.

yes, require possible 2 queries in request, it's way ensure result need.


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? -