Jump to content

hosseini

New Members
  • Posts

    5
  • Joined

  • Last visited

hosseini's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. hi all , I have a table that shows all rows of a selected table . problem is that I want to delete marked rows from this table but this code is not working for me . updating code works fine but I can't delete selected rows . <? if($_SESSION["count"]!=0){ ?> <!-- begining of setting levels informations --> <form name="form2" method="POST" dir="rtl" action="" style="font-family:'B_yekan';"> <input name="level" type="hidden" value="<? if(isset($_POST['level'])){ echo $_POST['level'];} ?>"/> <div align="center" width = 615> <table class="styled-table" cellspacing="0" width="800" border="1"> <tr> <th width="10" scope="col" ></th> <th width="60" scope="col">level</th> <th width="60" scope="col">time</th> <th width="60" scope="col">date</th> <th width="42" scope="col">status</th> <th width="54" scope="col">price</th> <th width="42" scope="col">off</th> <th width="54" scope="col">off 2</th> <th width="60" scope="col">mark</th> </tr> <?php $id = array(); while($rows=mysql_fetch_array($result)){ $id[]=$rows['id']; ?> <tr> <td align="center"><input class="styled-input" type="hidden" name="id[]" id="id" value= "<? echo $rows['id']; ?>" /></td> <td align="center"><input class="styled-input" type="lev" name="lev" id="lev" value="<? echo $tbl_name; ?>" /></td> <td align="center"><input class="styled-input" type="text" name="time[]" id="time" value= "<? echo $rows['time']; ?>" /></td> <td align="center"><select class="styled-input" type="text" name="date[]" id="date" /> <option selected="selected" value="<? if($rows['date']=="1"){echo "1";}else{echo "0";}?>"> <? if($rows['date']=="1"){echo "even";}else{echo "odd";}?></option> <option value="<? if($rows['date']=="1"){echo "0";}else{echo "1";}?>"> <? if($rows['date']=="1"){echo "odd";}else{echo "even";}?></option> </select></td> <td align="center"><select class="styled-input" type="text" name="act[]" id="act" > <option selected="selected" value="<? if($rows['act']==1){echo "1";}else{echo "0";}?>"> <? if($rows['act']==1){echo "enable";}else{echo "disable";}?></option> <option value="<? if($rows['act']==1){echo "0";}else{echo "1";}?>"> <? if($rows['act']==1){echo "disable";}else{echo "enable";}?></option> </select></td> <td align="center"><input class="styled-input" type="text" name="price[]" id="price" value= "<? echo $rows['price']; ?>" /></td> <td align="center"><input class="styled-input" type="text" name="offprice[]" id="offprice" value= "<? echo $rows['offprice']; ?>" /></td> <td align="center"><input class="styled-input" type="text" name="off2price[]" id="off2price" value= "<? echo $rows['off2price']; ?>" /></td> <td align="center"><input class="styled-input" style="padding: 5px;width:20px" type="checkbox" name="checkbox[]" id="checkbox[]" /></td> </tr> <?php }//end of loop ?> </table> </div> <input class="styled-button-8" type="Submit" value="submit" name="Submit" /> <input class="styled-button-8" type="Submit" value="delete" name="delete" /> <?php }//end of if ?> </form> <?php // Check if button name "Submit" is active, do this if(isset($_POST['Submit']) && $_POST['Submit'] == 'submit') { for($i=0;$i<$_SESSION["count"];$i++) { $sql1="UPDATE `".$tbl_name."` SET `time`='".$_REQUEST['time'][$i]."',`date`='".$_REQUEST['date'][$i]."',`act`='".$_REQUEST['act'][$i]."' , `price`='".$_REQUEST['price'][$i]."' , `offprice`='".$_REQUEST['offprice'][$i]."', `off2price`='".$_REQUEST['off2price'][$i]."' WHERE `id`='".$_REQUEST['id'][$i]."' "; $result1=mysql_query($sql1); } if(isset($result1)){ $_SESSION["count"]=""; ?> <script language="javascript">alert('all of the rows updated successfully');</script> <?php print(redirect('regmanage.php')); } ?> <!-- deleteing records --> <?php // Check if button name "Submit" is active, do this if(isset($_POST['delete']) && $_POST['delete'] == 'delete') { for($i=0;$i<$_SESSION["count"];$i++) { if(isset($_POST['checkbox'][$i])){ $del_id = $_POST['checkbox'][$i]; $sql1 = "DELETE FROM `".$tbl_name."` WHERE `id`='".$_REQUEST['id'][$i]."' "; $result1= mysql_query($sq1) or die(mysql_error()); } } } if(isset($result1)){ ?> <script language="javascript">alert('the selected row deleted successfully.');</script> <?php print(redirect('regmanage.php')); } ?> <!-- end of setting infromations -->
  2. It was php.ini problem with session path and I solved it tnx in advance for your guys help
  3. yes I have error reporting on my codes but this one as i told was working fine on my laptop and on my pc it's not working . I've found what was wrong . the local server on my ubuntu desktop didn't install properly , so I will reinstall it to see if it is gonna work !
  4. tnx for you help but your code is not working too I don't know what is the problem ! everything is ok but the session variable is not getting set ! the funny thing is my other project session variables are working but not this one !
  5. hi all , I have to system running Ubuntu 13.04 . on my laptop everything works fine but on my PC I can not work with session variable , I have installed Apache2 and PHP from terminal ,i'm running a same code on both devices. the code that I used for checking if the variable is set or not on every page is : <?php session_start(); if(!isset($_SESSION["mys"])) { header('location:../index.php'); } ?> as you can see if the variable do not set , user would redirect to the index page . the problem is my session variable is not getting set at all , this is a code that i ran on both devices : <?php session_start(); ?> <!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" xml:lang="en" lang="en"> <link REL="SHORTCUT ICON" HREF="qeshmac.ico"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <?php include 'mytool.php'; if(isset($_POST["myusername"])) { // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $host='localhost'; // Host name $username='root'; // Mysql username $password=''; // Mysql password switch ($_POST['tabs']) { case 'students': $db_name='students'; // Database name $tbl_name='test'; // Table name break; case'teachers': $db_name='managers'; // Database name $tbl_name='teachers'; // Table name break; case'managers': $db_name='managers'; // Database name $tbl_name='employes'; // Table name break; case'admin': $db_name='managers'; // Database name $tbl_name='moderator'; // Table name break; } // Connect to server and select database. mysql_connect($host,$username,$password)or die("cannot connect"); $selected=mysql_select_db($db_name)or die("cannot select DB"); mysql_query("SET CHARACTER SET utf8;"); mysql_query("SET SESSION collation_connection = 'utf8_persian_ci'"); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); if(mysql_fetch_assoc($result)) { switch ($_POST['tabs']) { case 'students': $_SESSION["mys"]=$myusername; print( redirect('student/index.php')); break; case 'teachers': $_SESSION["mys"]=$myusername; print( redirect('teachers/index.php')); break; case 'managers': $_SESSION["mys"]=$myusername; print( redirect('managers/index.php')); break; case 'admin': $_SESSION["mys"]=$myusername; print( redirect('admin/index.php')); break; } } else { //back to login print( redirect('index.php?cmd=error')); } } else { print( redirect('index.php')); } ?> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.