Why can't I save the data from the LIST/MENU ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yuukiizawa
    New Member
    • Sep 2012
    • 10

    Why can't I save the data from the LIST/MENU ???

    Here's the code::

    [alternatif.php]
    Code:
    <?php
    $namakoneksi = mysql_connect("localhost","root","") or die ("Failed Connect");
    mysql_select_db("tanamanobat",$namakoneksi);
    
    if (isset($_GET['pesan']))
    {
    echo $_GET['pesan'];
    }
    ?> <center> <?php
    $sqlTampil ="SELECT * FROM penyakit ORDER BY kd_penyakit";
    $qryTampil = mysql_query($sqlTampil) or die ("query failed".mysql_error());while ($dataTampil=mysql_fetch_array($qryTampil))
    ?> <form action="http://bytes.com/?menu=alternatif" method="post"> <select name="nm_penyakit"> <option value="" selected="selected">Choose Disease Name</option> <?php
    $sqlTampil ="SELECT * FROM penyakit ORDER BY kd_penyakit";
    $qryTampil = mysql_query($sqlTampil) or die ("gagal query".mysql_error());
    while ($dataTampil=mysql_fetch_array($qryTampil)) {
    ?> <option value="<?php echo $dataTampil['kd_penyakit']; ?>"> <?php echo $dataTampil['nm_penyakit']; ?> </option> <?php } ?> </select> <input type="submit" value="search" name="mysearch"/> </form> <?php
    if(isset($_POST['mysearch']))
    {
    $nm_penyakit=$_POST['nm_penyakit'];
    $sqlTampil2 ="SELECT * FROM penyakit WHERE kd_penyakit='".$nm_penyakit."'";
    $qryTampil2 = mysql_query($sqlTampil2) or die ("query failed".mysql_error());
    ?> <form action="http://bytes.com/alternatif_aksi.php?menu=alternatif&act=in put" method="post"> <table border="0" cellpadding="10" cellspacing="15" align="center"> <?php
    while ($dataTampil2=mysql_fetch_array($qryTampil2)) {
    ?> <tr><td colspan="40" bgcolor="#333333" align="center"><font color="#FFFFFF" face="Tahoma, Geneva, sans-serif" size="-1">Alternative of Herbal Plants</font></td> </tr> <tr> <td><input type="checkbox" name="cebo1" value="<?php echo $dataTampil2['to1']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to1']; ?></font></td> </tr> <tr> <td><input type="checkbox" name="cebo2" value="<?php echo $dataTampil2['to2']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to2']; ?></font></td> </tr> <tr> <td><input type="checkbox" name="cebo3" value="<?php echo $dataTampil2['to3']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to3']; ?></font></td> </tr> <tr> <td><input type="checkbox" name="cebo4" value="<?php echo $dataTampil2['to4']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to4']; ?></font></td> </tr> <tr> <td><input type="checkbox" name="cebo5" value="<?php echo $dataTampil2['to5']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to5']; ?></font></td> </tr> <td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td> </tr> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"></font></td> </tr> <?php } } ?> </table> <table> <tr> <td><input type="submit" value="save" /></td> <td><input type="reset" value="refresh" /></td> <td><input type="button" value="  Batal  " onclick=self.history.back() class='back_inline'></td> </tr> </table> </form> </center>

    [alternatif_aksi .php]
    Code:
    <?php
    $namakoneksi = mysql_connect("localhost","root","") or die ("Failed Connection");
    mysql_select_db("tanamanobat",$namakoneksi);
    
    ?> <?php
    $menu=$_GET['menu'];
    $act=$_GET['act'];
    
    // Input Alternatif
    if ($menu=='alternatif' AND $act=='input')
    {
    if (isset($_POST['cebo1']))
    {
    $kd_altrntf = $_POST['kodealter'];
    $nm_penyakit = $_POST['nm_penyakit'];
    $cbo1 = $_POST['cebo1'];
    $cbo2 = $_POST['cebo2'];
    $cbo3 = $_POST['cebo3'];
    
    echo "kd_penyakit : ".$kd_altrntf."<br />";
    echo "nm_penyakit : ".$nm_penyakit."<br />";
    echo "alt1 : ".$cbo1."<br />";
    echo "alt2 : ".$cbo2."<br />";
    echo "alt3 : ".$cbo3."<br />";
    
    $tambah=mysql_query("INSERT INTO alternatif VALUES('$kd_altrntf','$nm_penyakit','$cbo1','$cbo2 ','$cbo3')"); }
    if ($tambah)
    //{ header ('location:index.php?menu=alternatif&pesan=Choosing is done');
    exit();
    // }
    else
    // { header ('location:index.php?menu=alternatif&pesan=Choosing Failed');
    exit();
    }
    //}
    ?>

    And also, I still don't get the way to saving data from checkboxes randomly checked...

    Can somebody help to solve these? Thankyou :)
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's probably because the form that submits to the page alternatif_aksi .php doesn't have nm_penyakit or kodealter in its post data.

    You can save checkbox data anyway you want. Some people use y/n to indicate checked or not. Some spell it out as yes/no. Some use 0/1. There are many variations, you just have to pick one that you like.

    Comment

    • yuukiizawa
      New Member
      • Sep 2012
      • 10

      #3
      which one do you mean with "doesn't have nm_penyakit or kodealter in its post data." ?
      Code:
       // Input Alternatif
      if ($menu=='alternatif' AND $act=='input')
      {
      if (isset($_POST['cebo1']))
      {
      $kd_altrntf = $_POST['kodealter'];
      $nm_penyakit = $_POST['nm_penyakit'];
      $cbo1 = $_POST['cebo1'];
      $cbo2 = $_POST['cebo2'];
      $cbo3 = $_POST['cebo3'];
      That ones?

      but the CHECKBOX's contain is from different FIELD in database.. so that I can't use array calling in there.

      Code:
      <td><input type="checkbox" name="cebo1" value="<?php echo $dataTampil2['to1']; ?>"/></td>
      <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to1']; ?></font></td></tr>
      <tr><td><input type="checkbox" name="cebo2" value="<?php echo $dataTampil2['to2']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to2']; ?></font></td></tr>
      <tr><td><input type="checkbox" name="cebo3" value="<?php echo $dataTampil2['to3']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to3']; ?></font></td></tr>
      <tr><td><input type="checkbox" name="cebo4" value="<?php echo $dataTampil2['to4']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to4']; ?></font></td></tr>
      <tr><td><input type="checkbox" name="cebo5" value="<?php echo $dataTampil2['to5']; ?>"/></td> <td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"><?php echo $dataTampil2['to5']; ?></font></td></tr>
      <tr><td><font color="#009900" face="Tahoma, Geneva, sans-serif" size="-1"></font></td> </tr> <?php } } ?> </table> <table> <tr> <td><input type="submit" value="save" /></td> <td><input type="reset" value="refresh" /></td> <td><input type="button" value="  Batal  " onclick=self.history.back() class='back_inline'></td> </tr> </table> </form> </center>
      cebo1 to cebo5 will placed different Field in database..

      Comment

      • yuukiizawa
        New Member
        • Sep 2012
        • 10

        #4


        That's link to the problems
        The image named GNASHING of TEETH... would you mind to see it?

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Yes, that's the form that is missing the data I mentioned.

          I have no idea what you're trying to say about the combo boxes, that has no bearing on the missing data.

          Comment

          • yuukiizawa
            New Member
            • Sep 2012
            • 10

            #6
            About checkbox:

            In Disease FORM, I have 5 values which I saved it in disease table named to1, to2, to3, to4 and to5. example: Apples -->to1, Carrot -->to2, until to5...

            And then,
            I call them (apple&friends) in Alternatif FORM using checkbox like in the image.
            I made 3 fields in alternatif table named cbo1, cbo2 and cbo3 for saving the chosen one (I limited it just for 3 plants).

            How can I save the data from checkbox randomly?
            Example:
            • Apple
            • Carrot
            • Cherry
            • Spinach
            • Cabbage

            then I want to chose only Carrot and Cabbage...

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              That picture is too small for me to read the text on there.

              I'm not sure what you mean by save it randomly. You should want to avoid random as much as possible. But if you're talking about how to map the 5 checkboxes to 3 fields in your table, the answer is you shouldn't. Your data is not normalized and that's why it's making it so difficult for you to query and update your data. You should really have another table for their checkbox choices. It would have two fields, a foreign key to the main table and their choice. If they make 3 choices, then there would be 3 rows in the choice table.

              Comment

              • yuukiizawa
                New Member
                • Sep 2012
                • 10

                #8
                about the picture, you can click to make it zoomed

                Yes, I want to map the 5 checkboxes to 3 fields...
                Well, then you were so helpful. Thankyou so much for the solution :)

                Comment

                • Rabbit
                  Recognized Expert MVP
                  • Jan 2007
                  • 12517

                  #9
                  My monitor at work is small so I still couldn't read it when I zoomed in. Either way, glad you got it working.

                  Comment

                  • jdstankosky
                    New Member
                    • Sep 2012
                    • 30

                    #10
                    They only give you one tiny monitor? That sucks. Everyone should just know that devs, coders, and programmers should have at least two large wide-screens.

                    Comment

                    Working...