Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts

    change select option value before inserting to mysql database

    I have problem in this code the select option value (alwa_no) & textbox value (pre_salary) insert to mysql database with the same value(959). I want to change the select option value (alwa_no) from 959 to A1 before inserting to mysql database.
    Thanks in advance

    Code:
    <script src="jquery-1.11.1.min.js"></script>
    <script src="jquery.chained.min.js"></script>
    <script>
      $(document).ready(function () {
    $("#alwa_no").chained("#dgree_now"); /* or $("#series").chainedTo("#mark"); */
    document.getElementById('alwa_no').addEventListener('change', function(){
       document.getElementById('pre_salary').value = this.value;
    });
    
    });
    </script>
    <?php
    include"conn.php";include("header2.php");
    echo"<center>";
    echo"<font face='Terminal' color='green'><h1>تعديل / حذف البدلات العامـــة </h1>";
    $gid=intval($_GET['id']);
    $id=$_POST['id'];
    $a=$_POST['dgree_now'];
    $b=$_POST['alwa_no'];
    $c=$_POST['pre_salary'];
    $d=$_POST['alwa_year'];
    $e=$_POST['alsakn'];
    $f=$_POST['kla_mesha'];
    $g=$_POST['menha'];
    $h=$_POST['tamseal'];
    $i=$_POST['badl_trhil'];
    $j=$_POST['badel_nakdy'];
    $k=$_POST['natural_job'];
    $l=$_POST['badl_adwa'];
    $m=$_POST['alwa_perosn'];
    if(isset($_POST['edit'])and$_POST['edit']=='news'){
    $xy=mysql_query("update basic1 set dgree_now='$a',alwa_no='$b',
    pre_salary='$c',alwa_year='$d',alsakn='$e',
    kla_mesha='$f',menha='$g',tamseal='$h',badl_trhil='$i',badel_nakdy='$j',
    natural_job='$k',badl_adwa='$l',alwa_perosn='$m' where id='$gid'")or die ("عذرا لم يتم تعديل البدلات العامـــة,,, الرجاء المحاولة 
    
    مرة ثانيــة");
    if(isset($xy)){
    echo"<h1>  تم تعديل بيانات البدلات العامـــة بنجاح </h1>";
    }
    }
    if ($_REQUEST['delete']=='news'){
    $del==mysql_query("delete from basic1 where id='".$gid."'");
    if(isset($del)){
    echo"<h2>تم حذف الببانات بنجاح</h2>";
    }}
    $query=mysql_query("select * from basic1 where id='".$gid."'") or die("لم يتم حذف البيانات ");
    $re=mysql_fetch_assoc($query);
    echo"<form action='".$server['PHP_SELF']."' method='post'>
    <table bgcolor='#7ACB83'  border='1'>
     <tr> <td>الدرجة الوظيفية:</td><td><select id='dgree_now' name='dgree_now'>
            <option  value='1'>الاُولى</option>
            <option value='2'>الثانية</option>
            <option value='3'>الثالثة</option>
            <option value='4'>الرابعة</option>
            <option value='5'>الخامسة</option>
            <option value='6'>السادسة</option>
            <option value='7'>السابعة</option>
    <option value='8'> الثامنة</option>
    <option value='9'> التاسعة</option>
    <option value='10'>العاشرة </option>
    <option value='11'>الحادية عشر </option>
    <option value='12'>الثانية عشر </option>
    <option value='13'>الثالثة عشر </option>
    <option value='14'>الرابعة عشر </option>
    <option value='15'>الخامسة عشر </option>
    <option value='16'>السادسة عشر </option>
    <option value='17'> السابعة عشر</option>
    <option value='18'> اُولي خاصــة</option>
          </select></td>
    
    <td>رقــم العلاوة:</td><td><select id='alwa_no' name='alwa_no'>
      <option value=''>--</option>
      <option value='959' class='1'>A1</option>
      <option value='998' class='1'>A2</option>
      <option value='1038' class='1'>A3</option>
    <option value='1079' class='1'>A4</option>
      <option value='887' class='2'>B1</option>
      <option value='923' class='2'>B2</option>
      <option value='959' class='2'>B3</option>
      <option value='998' class='2'>B4</option>
      <option value='C1' class='3'>C1</option>
      <option value='C2' class='3'>C2</option>
      <option value='C3' class='3'>C3</option>
      <option value='C4' class='3'>C4</option>
      <option value='D1' class='4'>D1</option>
      <option value='D2' class='4'>D2</option>
      <option value='D3' class='4'>D3</option>
      <option value='D4' class='4'>D4</option>
      <option value='E1' class='5'>E1</option>
      <option value='E2' class='5'>E2</option>
      <option value='E3' class='5'>E3</option>
      <option value='E4' class='5'>E4</option>
    <option value='E5' class='5'>E5</option>
    <option value='F1' class='6'>F1</option>
      <option value='F2' class='6'>F2</option>
      <option value='F3' class='6'>F3</option>
      <option value='F4' class='6'>F4</option>
    <option value='F5' class='6'>F5</option>
    <option value='G1' class='7'>G1</option>
      <option value='G2' class='7'>G2</option>
      <option value='G3' class='7'>G3</option>
      <option value='G4' class='7'>G4</option>
    <option value='G5' class='7'>G5</option>
    <option value='G6' class='7'>G6</option>
    <option value='H1' class='8'>H1</option>
      <option value='H2' class='8'>H2</option>
      <option value='H3' class='8'>H3</option>
      <option value='H4' class='8'>H4</option>
    <option value='H5' class='8'>H5</option>
    <option value='H6' class='8'>H6</option>
    <option value='I1' class='9'>I1</option>
      <option value='I2' class='9'>I2</option>
      <option value='I3' class='9'>I3</option>
      <option value='I4' class='9'>I4</option>
    <option value='I5' class='9'>I5</option>
    <option value='I6' class='9'>I6</option>
      <option value='I7' class='9'>I7</option>
    <option value='I8' class='9'>I8</option>
    <option value='I9' class='9'>I9</option>
    <option value='J1' class='10'>J1</option>
      <option value='J2' class='10'>J2</option>
      <option value='J3' class='10'>J3</option>
      <option value='J4' class='10'>J4</option>
    <option value='J5' class='10'>J5</option>
    <option value='J6' class='10'>J6</option>
    <option value='K1' class='11'>K1</option>
      <option value='K2' class='11'>K2</option>
      <option value='K3' class='11'>K3</option>
      <option value='K4' class='11'>K4</option>
    <option value='K5' class='11'>K5</option>
    <option value='K6' class='11'>K6</option>
    <option value='L1' class='12'>L1</option>
      <option value='L2' class='12'>L2</option>
      <option value='L3' class='12'>L3</option>
      <option value='L4' class='12'>L4</option>
    <option value='L5' class='12'>L5</option>
    <option value='L6' class='12'>L6</option>
    <option value='M1' class='13'>M1</option>
      <option value='M2' class='13'>M2</option>
      <option value='M3' class='13'>M3</option>
      <option value='M4' class='13'>M4</option>
    <option value='M5' class='13'>M5</option>
    <option value='M6' class='13'>M6</option>
    <option value='N1' class='14'>N1</option>
      <option value='N2' class='14'>N2</option>
      <option value='N3' class='14'>N3</option>
      <option value='N4' class='14'>N4</option>
    <option value='N5' class='14'>N5</option>
    <option value='N6' class='14'>N6</option>
    <option value='O1' class='15'>O1</option>
      <option value='O2' class='15'>O2</option>
      <option value='O3' class='15'>O3</option>
      <option value='O4' class='15'>O4</option>
    <option value='O5' class='15'>O5</option>
    <option value='O6' class='15'>O6</option>
    <option value='P1' class='16'>P1</option>
      <option value='P2' class='16'>P2</option>
      <option value='P3' class='16'>P3</option>
      <option value='P4' class='16'>P4</option>
    <option value='P5' class='16'>P5</option>
    <option value='P6' class='16'>P6</option>
    <option value='Q1' class='17'>Q1</option>
      <option value='Q2' class='17'>Q2</option>
      <option value='Q3' class='17'>Q3</option>
      <option value='Q4' class='17'>Q4</option>
    <option value='Q5' class='17'>Q5</option>
    <option value='لا يوجد علاوة' class='18' disabled>لا يوجد علاوة</option>
    </select></td>
    </table><br>
    <table bgcolor='#7ACB83' width='98%' border='1'>
    
    <td>المرتب الأساسي:</td><td><input type='text' id='pre_salary' name='pre_salary'  value='".$re['pre_salary']."'></td>
    <td>العلاوة السنوية:</td><td><input type='text' name='alwa_year'  value='".$re['alwa_year']."'></td>
    <td>بدل السكن:</td><td><input type='text' name='alsakn' value='".$re['alsakn']."'></td>
    
     <tr><td>غلاء المعيشة:</td><td><input type='text' name='kla_mesha' value='".$re['kla_mesha']."'></td>
    <td>المنحــة:</td><td><input type='text' name='menha' value='".$re['menha']."'></td>
    <td>بدل تمثيـــل:</td><td><input type='text' name='tamseal' value='".$re['tamseal']."'></td>
    <tr><td>بدل ترحيـــل:</td><td><input type='text' name='badl_trhil' value='".$re['badl_trhil']."'></td>
    <td>البديل النقدي:</td><td><input type='text' name='badel_nakdy' value='".$re['badel_nakdy']."'></td>
    
     <td>طبيعة عمـل:</td><td><input type='text' name='natural_job' value='".$re['natural_job']."'></td>
    <tr><td>بدل عـــدوي:</td><td><input type='text' name='badl_adwa' value='".$re['badl_adwa']."'></td>
    
    <td>علاوة شخصيــة:</td><td><input type='text' name='alwa_perosn' value='".$re['alwa_perosn']."'></td>
    
    
    </table>
    <table bgcolor='#7ACB83' width='5%' border='1'>
    <input type='submit' name='submit' value='حفظ بيانات البدلات العامـــة  '/>
    <input type='hidden' name='id' value='".$gid."'/>
    <input type='hidden' name='edit' value='news'/>";
    echo"</table>
    </form>
    ";
    $data=mysql_query("select * from basic1 order by id ");
    echo"<table bgcolor='abd9f9'width='99%'border='4'bordercolor='#7ACB83'>
    
    
    <td bgcolor='#7ACB83'>الرقم</td>
    <td bgcolor='#7ACB83'>الدرجة الوطيفية</td>
    <td bgcolor='#7ACB83'>رقم العلاوة:</td>
    <td bgcolor='#7ACB83'>المرتب الأساسي:</td>
    <td bgcolor='#7ACB83'>العلاوة السنوية:</td> 
    <td bgcolor='#7ACB83'>بدل السكن:</td>
    <td bgcolor='#7ACB83'>غلاء المعيشة:</td>
    <td bgcolor='#7ACB83'>المنحة</td>
    <td bgcolor='#7ACB83'>بدل تمثيل</td>
    <td bgcolor='#7ACB83'>بدل ترحيل</td>
    <td bgcolor='#7ACB83'>البديل النقدي</td>
    <td bgcolor='#7ACB83'>طبيعة عمل</td>
    <td bgcolor='#7ACB83'>بدل عدوي</td>
    <td bgcolor='#7ACB83'>علاوة شحصية</td>
    <td bgcolor='#7ACB83'>تعديل البيانات</td>
    <td bgcolor='#7ACB83'>حذف البيانات</td>
    ";
    while($row=mysql_fetch_assoc($data)){
    echo"<tr>
    <td bgcolor='abd9f9'>".$row['id']."</td>
    <td bgcolor='abd9f9'>".$row['dgree_now']."</td>
    <td bgcolor='abd9f9'>".$row['alwa_no']."</td>
    <td bgcolor='abd9f9'>".$row['pre_salary']."</td>
    <td bgcolor='abd9f9'>".$row['alwa_year']."</td>
    <td bgcolor='abd9f9'>".$row['alsakn']."</td>
    <td bgcolor='abd9f9'>".$row['kla_mesha']."</td>
    <td bgcolor='abd9f9'>".$row['menha']."</td>
    <td bgcolor='abd9f9'>".$row['tamseal']."</td>
    <td bgcolor='abd9f9'>".$row['badl_trhil']."</td>
    <td bgcolor='abd9f9'>".$row['badel_nakdy']."</td>
    <td bgcolor='abd9f9'>".$row['natural_job']."</td>
    <td bgcolor='abd9f9'>".$row['badl_adwa']."</td>
    <td bgcolor='abd9f9'>".$row['alwa_perosn']."</td>
    <td bgcolor='abd9f9'><a href='replace__edit.php?id=".$row['id']."'><img src='2.gif'></a>
    <td bgcolor='abd9f9'><a href='replace__edit.php?delete=news&id=".$row['id']."'><img src='1.png'></a>";
    }
    echo"</table>
    <a href='main.php'><font size='3' color='green'> الانتقال الى الصفحة الرئيسية للنظام</a><br>
    <a href='login.php'><font size='3' color='green'> الخروج من النظام</a>";
    
    ?>

  2. #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    15,047
    Thanks
    165
    Thanked 2,248 Times in 2,235 Posts
    Can't you just change
    Code:
    <option value='959' class='1'>A1</option>
    to
    Code:
    <option value='A1' class='1'>A1</option>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  3. #3
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Code:
    <option value='959' class='1'>A1</option>
    I need this value (959) because the pre_salary depends on it if you select A1 then the pre_salary textbox value becomes (959)
    Quote Originally Posted by abduraooft View Post
    Code:
    <option value='A1' class='1'>A1</option>
    but I need after the select & before insert to mysql the value becomes A1.
    Or you can find to me another solution to pre_salary (it depends on alwa_no select) & the values fills 959 if you select A1.
    Thanks in Advance

  4. #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    15,047
    Thanks
    165
    Thanked 2,248 Times in 2,235 Posts
    Just change
    PHP Code:
    $b=$_POST['alwa_no']; 
    into
    PHP Code:
    $b=($_POST['alwa_no']=='959':'A1':$_POST['alwa_no']); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  5. #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Add the pre_salary value as a custom attribute of the alwa_no select options.
    Code:
    <select id='alwa_no' name='alwa_no'>
        <option value='A1' data-value='959' class='1'>A1</option>
        <option value='A2' data-value='998' class='1'>A2</option>
        ...
    </select>
    Then in the onchange handler:
    Code:
    document.getElementById('alwa_no').addEventListener('change', function(){
       document.getElementById('pre_salary').value = this.options[this.selectedIndex].getAttribute('data-value') || '';
    });

  6. Users who have thanked glenngv for this post:

    hassanab (06-23-2014)

  7. #6
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    $b=($_POST['alwa_no']=='959':'A1':$_POST['alwa_no']);
    I try it but gives me error (Parse error: syntax error, unexpected ':' in C:\wamp\www\last\replace__edit.php on line 19)
    also I need to check if the value of alwa_no is 959 Then $b value becomes A1 if the value 998 then $b becomes A2. The if clause here check only for one number 959.
    <select id='alwa_no' name='alwa_no'>
    <option value='A1' data-value='959' class='1'>A1</option>
    <option value='A2' data-value='998' class='1'>A2</option>
    ...
    </select>
    document.getElementById('alwa_no').addEventListener('change', function(){
    document.getElementById('pre_salary').value = this.options[this.selectedIndex].getAttribute('data-value') || '';
    });
    I try it but the value of alwa_no enter to database is 0. I don't know where is the error
    Thanks in Advance

  8. #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Location
    Here
    Posts
    3,572
    Thanks
    58
    Thanked 648 Times in 643 Posts
    glenngv's code works fine. You must have an error elsewhere

  9. #8
    New Coder
    Join Date
    Sep 2009
    Posts
    40
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by xelawho View Post
    glenngv's code works fine. You must have an error elsewhere
    Yes, it works fine I found the error in mysql database the alwa_no is float and default value is 0 so I change it to varchar and works fine.
    Thank you very much

  10. #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    15,047
    Thanks
    165
    Thanked 2,248 Times in 2,235 Posts
    Oops, that should be
    Code:
    $b=($_POST['alwa_no']=='959'?'A1':$_POST['alwa_no']);
    Anyway, I my vote is for glenngv's solution
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •