0

I need to return the 'id' field back to the server, and not the 'name' field. Whatever I try, when I change 'name' field but I can't get 'id' of 'name'. id not changed when I change my 'name' field...

This my code: index

<?php
include "koneksi.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" dir="ltr" lang="en-US" xml:lang="en">
<head>
    <link rel="shortcut icon" href="images/favicon.ico" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>Sms Gateway By Nightwalker Team</title>
    <link rel="stylesheet" href="development-bundle/themes/base/jquery.ui.all.css">
    <script src="development-bundle/jquery-1.6.2.js"></script>
    <script src="development-bundle/ui/jquery.ui.core.js"></script>
    <script src="development-bundle/ui/jquery.ui.widget.js"></script>
    <script src="development-bundle/ui/jquery.ui.button.js"></script>
    <script type="text/javascript" src="js/jquery_notification_v.1.js"></script>
    <script type="text/javascript" src="js/jquery.watermark.min.js"></script>
    <link href="css/jquery_notification.css" type="text/css" rel="stylesheet"/>
    <link href="paging.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="script.js"></script>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    <!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
    <!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->
    <style>
        body { font-size: 62.5%; }
        label, input { display:block; }
        input.text { margin-bottom:12px; width:95%; padding: .4em; font-size:12px; }
        fieldset { padding:0; border:0; margin-top:25px; }
        textarea {margin-bottom:12px; width:90%; padding: .4em; font-size:12px;}
        div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
        div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
        .style1 {font-size: 18px}
    </style>
    <script>
    $(document).ready(function(){

        $( "#tambah" )
            .button()
            .click(function() {
            var Name = $ ("#Name").val();
            var Number = $ ("#Number").val();
            var GroupID = $("#GroupID :selected").val();    
            //kirim ke proses_group.php
            $.ajax({
            type:"POST",
            url:"proses_tambah_group.php",
            //pisahkah dengan tanda & jika mengirim lebih dari 1 data
            data: "Name=" + Name + "&Number=" + Number + "&GroupID=" + GroupID,
            success: function(data){
            $("#groupinfo").html(data);
            }
            });
            });

        });
    </script>
</head>
<body>
<form>
        <fieldset>
        <label for="Name">Nama</label>
        <input type="text" Name="nama" id="Name" class="text ui-widget-content ui-corner-all" />
        <label for="email">Nomor</label>
        <input type="text" Name="nomor" id="Number" class="text ui-widget-content ui-corner-all" />

        <?php
        echo"<select id='GroupID' >";
        include "koneksi.php";
        $sql = mysql_query("select * from pbk_groups");
            while ($data = mysql_fetch_array($sql)){
            echo"<option Value='$data[ID]'>$data[Name]</option>";}
            echo"</select>";
            ?>
        </fieldset>
        </form>
            <br>
        <button id="tambah">Tambah</button>
        <p>&nbsp;</p>
        <div id="groupinfo"></div>
</body>
<html>

this process

<?php
    include "koneksi.php";
    $Name = $_POST['Name'];
    $Number = $_POST['Number'];
    $GroupID = $_POST['GroupID'];
$input = mysql_query("insert into pbk(Name,Number,GroupID)
values ('$Name','$Number','$GroupID')");

//Jika proses berhasil
if ($input){
?>
<script type="text/javascript">
                        showNotification({
                            message: "<?php echo "Pesan Dikirim"; ?>",
                            type: "success",
                            autoClose: true,
                            duration: 2                                       
                        });
</script>
<?php
}
else {
?>
<script type="text/javascript">
                        showNotification({
                            message: "<?php echo "Pesan Gagal" ?>",
                            type: "error",
                            autoClose: true,
                            duration: 2                                    
                        });
</script>
<?php
    }
?>

1 Answers1

0

If I understand correctly, you want the form to find the corresponding ID whenever the user enters a name?

You have two different 'names' in the form: the text input and the select.

Is your select correctly filled by your PHP code? Check your html output.

Do you select the name in the select ? If not, you are missing code to find the ID according to the name: change-the-selected-value-of-a-drop-down-list-with-jquery

Community
  • 1
  • 1
Jay
  • 422
  • 4
  • 15
  • yes, i need get id from name in combobox.. i make a contact phone.. save to groups.. i have groups and group id.. when button clicked contact will save to database and id contact same with id group... i use 2 table,. table group and contact.. on group there ID and contact there "ID" and "GroupID" , GroupID contact i need to take from "ID" on table group.. – Donesa Rucci Jan 02 '12 at 09:24
  • Can you check (or show) your html code? Is the select correctly filled? – Jay Jan 02 '12 at 09:33
  • i'm sorry .. i new member in here , i dont know how to use this.. i cant to display my html code.. how to use this? confused... – Donesa Rucci Jan 02 '12 at 09:51
  • thats my html code.. thanks before.. you my frist friend in here, :) – Donesa Rucci Jan 02 '12 at 11:41
  • By html code, I meant the actual html displayed by your browser, not the php. It's important to check if the output from your php is correct. – Jay Jan 02 '12 at 13:45