Cant Get posted value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flexsingh
    New Member
    • Mar 2008
    • 17

    #1

    Cant Get posted value

    Hello there, I have constructed a option of choosing a court only available when member no = "0". This works fine and is in the first code: -

    [PHP]<html>
    <head>
    </head>

    <body background="mai n background1.jpg " link="blue" vlink="blue">

    <table width="350" border="1" align="center" cellpadding="0" cellspacing="1" >
    <tr>
    <td><form name="Update Network Gaming form" method="post" action="updateb court_ac.php">
    <table width="100%" border="1" cellspacing="1" cellpadding="3" >
    <tr>
    <td colspan="3" align="center"> <strong><font face="sans-serif, Arial" font color="white">I nsert Data Into mySQL Database </strong></td>
    </tr>
    <tr>
    <td><font face="sans-serif, Arial" font color="white">M ember No</td>
    <td><font color="white">: </td>
    <td><input name="Member_No " type="int" id="Member_No"> </td>
    </tr>
    <tr>
    <td><font face="sans-serif, Arial" font color="white">C ourt No</td>
    <td><font color="white">: </td>
    <td><input name="Court_No" type="varchar" id="Court_No" value="Bcourt"> </td>
    </tr>

    <tr>
    <td><font face="sans-serif, Arial" font color="white">T ime Slot No</td>
    <td><font color="white">: </td>
    <td><select>

    <?php
    $db_name="proje ct"; // Database name
    $tbl_name="bcou rt"; // Table name

    // Connect to server and select database.
    $conn = mysql_connect($ _SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
    mysql_select_db ("$db_name", $conn)or die("cannot select DB");

    $time=urlencode ($_GET['Time_Slot_No']);

    $time = "SELECT Time_Slot_No FROM $tbl_name WHERE Member_No = '0'";
    $query = mysql_query($ti me, $conn); // do the query
    while($queryCol umn=mysql_fetch _assoc($query)) { // fetch each row in the result set
    $val=$queryColu mn['Time_Slot_No']; // make it simpler
    echo "<option value='$val'>$v al</option>"; // construct option statement
    }
    ?>
    </select></td>
    </tr>

    <td colspan="3" align="center"> <input type="submit" name="Submit" value="Continue "></td>
    </tr>
    </table>
    </form>
    </td>
    </tr>
    </table>



    </body>
    </html>[/PHP]

    It then sends the data to be updated into the table replacing the member number "0" to whatever was put in.

    The problem I am getting is it can't update any time slot as it cant retieve the slot I asked for. It only updates member = "0".

    [PHP]<?php
    // this starts the session
    session_start() ;
    ?>

    <?php
    $db_name="proje ct"; // Database name
    $tbl_name="bcou rt"; // Table name

    // Connect to server and select database.
    mysql_connect($ _SESSION['host'], $_SESSION['username'], $_SESSION['password'])or die("cannot connect");
    mysql_select_db ("$db_name") or die("cannot select DB");

    // Get values from form
    $memberno1=$_PO ST['Member_No'];
    $courtno1=$_POS T['Court_No'];
    $TSN1=$_POST['Time_Slot_No'];

    $time=urldecode ($_GET['Time_Slot_No']);

    // Insert data into mysql
    $query = ("UPDATE $tbl_name SET Member_No = '$memberno1' WHERE Time_Slot_No = '".$_GET['Time_Slot_No']."' LIMIT 1");
    $result=mysql_q uery($query) or die(mysql_error ());

    // if successfully insert data into database, displays message "Successful ".
    if($result){
    echo $query;
    }
    else {
    echo "Cannot Update";
    }
    // close connection
    mysql_close();
    ?>[/PHP]

    I had asked for a echo query and it shows : -
    "UPDATE bcourt SET Member_No = '3' WHERE Time_Slot_No = '' LIMIT 1"

    So I know it can't find the time slot, can anyone help me please.

    Thank you in advanced forany help.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Your <form> is posted, [php]<td><form name="Update Network Gaming form" method="post" action="updateb court_ac.php">[/php]then why do you retrieve the passed value from the $_GET array?[php]$query = ("UPDATE $tbl_name SET Member_No = '$memberno1' WHERE Time_Slot_No = '".$_GET['Time_Slot_No']."' LIMIT 1");[/php]Ronald

    Comment

    • flexsingh
      New Member
      • Mar 2008
      • 17

      #3
      Originally posted by ronverdonk
      Your <form> is posted, [php]<td><form name="Update Network Gaming form" method="post" action="updateb court_ac.php">[/php]then why do you retrieve the passed value from the $_GET array?[php]$query = ("UPDATE $tbl_name SET Member_No = '$memberno1' WHERE Time_Slot_No = '".$_GET['Time_Slot_No']."' LIMIT 1");[/php]Ronald

      Id need to retrieve the past value so it knowns which time slot to update the member no for. That is why I'm getting the value (time_Slot_No".

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Guess you don''t know what I am talking about.
        When you POST a value, you cannot retrieve it from the $_GET array, you must retrieve it from the $_POST array!

        Ronald

        Comment

        • flexsingh
          New Member
          • Mar 2008
          • 17

          #5
          Originally posted by ronverdonk
          Guess you don''t know what I am talking about.
          When you POST a value, you cannot retrieve it from the $_GET array, you must retrieve it from the $_POST array!

          Ronald
          I understand now thank you, it works fine. Would you like me to post the working code up for any other users stuck to see?

          Thank you very much for your help!

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Originally posted by flexsingh
            I understand now thank you, it works fine. Would you like me to post the working code up for any other users stuck to see?

            Thank you very much for your help!
            I think Ron's last post sums it up.

            Regards :)

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              Originally posted by flexsingh
              I understand now thank you, it works fine. Would you like me to post the working code up for any other users stuck to see?

              Thank you very much for your help!
              No, I think we get the idea. But I am glad you worked it out. See you around.

              Ronald

              Comment

              Working...