Database Issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathanwb
    New Member
    • Mar 2008
    • 39

    Database Issue

    I have this code and I when the submit button is pressed it will create a new record in the database but wont place any of the data from the form into the new record.? Im kind stumped.

    This is what the http link looks like when I pull the page up.

    [html]
    /mailsend.php?ii d=1
    [/html]

    This tells the following code which person I am sending a message to.

    [php]
    <?
    include('db.php ');
    if ($myID == 0) header("locatio n:login.php");
    if ($admin == 0) header("locatio n:login.php");

    include("navtop .php");
    include("nav.ph p");
    include("func.p hp");
    connect1();



    // this is where I take the data and insert it into the database
    _v('mode;i:id') ;
    if ($mode=='save') {
    pg('msg_from,ms g_to,msg_body,m sg_date,msg_tim e,msg_subject,m sg_subject,msg_ isread,msg_sid, msg_tid');
    $qupd = mysql_query("IN SERT INTO `email` VALUES ('0','$name', '$to', '$msg', '$now', '$t', '$subject','0', '$myId','$iid') ") or die(mysql_error ());
    goto('mail.php' );
    }

    $now = date('m/d/Y');
    $t = date('h:i A');


    // this is the query that gets the current loged in user and data about him or her

    $query = mysql_query("SE LECT * FROM `instructors` WHERE id='$myID'") or die(mysql_error ());
    $row = mysql_fetch_arr ay($query);
    extract($row);
    $name = $row['first_name'] . " " . $row['last_name'];


    echo "<td width=100% valign=top>
    <table border=0 width=100% class=leftMenut op1><td>

    </form>
    <form method='post' name='frmado' action='mailsen d.php'>
    <table border=0 width=99% cellpadding=0 cellspacing=0>
    <Td wdith=100%>";

    // this is the query that pulls the selected person from the list out of the database
    // this data displays just fine on the page

    $qi = mysql_query("SE LECT * FROM `instructors` WHERE id='$iid'");
    $Row2 = mysql_fetch_arr ay($qi);
    extract($row);
    $to = $row2['first_name'] . " " . $row2['last_name'];
    echo "

    <p><br><p><sp an class='text'>Fr om: <b>$name</b></p>

    <p><span class='text'>To : <b>$first_nam e $last_name</b></p>


    <p><span class='text'>Su bject<br>
    <input type='text' size='50' name='subject' value='' id='subject' />
    </p>

    <p><span class='text'>En ter Message<br>
    <textarea name='msg' id='msg' cols=50 rows=15 value=''></textarea>

    <input type='hidden' name='mode' value='save'>
    <p><input type=submit name='submit' value='Send Message' class='input' ></p>


    </td>
    </table>";

    include('navbot .php');

    ?>
    [/php]
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    When a variable is posted to a PHP page, it not posted as $name, but as $_POST['name']

    Change all your variables to the form of $_POST['variable_name']

    Also, use the closing form tab at right position.

    Harpreet

    Comment

    • nathanwb
      New Member
      • Mar 2008
      • 39

      #3
      Originally posted by hsriat
      When a variable is posted to a PHP page, it not posted as $name, but as $_POST['name']

      Change all your variables to the form of $_POST['variable_name']

      Also, use the closing form tab at right position.

      Harpreet

      Even though is posting to the same file?

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Actually, It doesn't matter which file it is posting to.

        Each time you call the same file, it has no link to the previously called one.
        Also when you click on the submit button, it calls the same script again and doesn't start from where it left last time.

        So you would need to make that change.


        Regards,
        Harpreet

        Comment

        • nathanwb
          New Member
          • Mar 2008
          • 39

          #5
          Originally posted by hsriat
          Actually, It doesn't matter which file it is posting to.

          Each time you call the same file, it has no link to the previously called one.
          Also when you click on the submit button, it calls the same script again and doesn't start from where it left last time.

          So you would need to make that change.


          Regards,
          Harpreet
          Ok, just so I understand.. were would I place those quotes?

          Comment

          • hsriat
            Recognized Expert Top Contributor
            • Jan 2008
            • 1653

            #6
            Originally posted by nathanwb
            Ok, just so I understand.. were would I place those quotes?
            Which quotes?........

            Comment

            • nathanwb
              New Member
              • Mar 2008
              • 39

              #7
              Originally posted by hsriat
              Which quotes?........

              $_POST['variable_name']


              were in the code..?

              Comment

              • hsriat
                Recognized Expert Top Contributor
                • Jan 2008
                • 1653

                #8
                I mean to say, replace all your variables which are posted by the form with $_POST['variable_name'].
                Where variable_name is the name of the variable.

                eg:
                change:
                $subject to $_POST['subject']
                $msg to $_POST['msg']
                $mode to $_POST['mode']

                Comment

                • dlite922
                  Recognized Expert Top Contributor
                  • Dec 2007
                  • 1586

                  #9
                  Originally posted by nathanwb
                  $_POST['variable_name']


                  were in the code..?
                  Welcome to PHP $_POST 101, please have a seat, turn of your cell phones, and turn to page 1 in your booklet.

                  We have the following code that posts a field's text, if run in a browser, to another (or same) php file

                  [PHP]

                  <html>
                  <body>
                  <form name="myForm" action="testing .php" method="post">
                  <input type="text" name="something " value="" />
                  <input type="submit" value="submit" />
                  </form>
                  </body>
                  </html>

                  [/PHP]

                  Once the user types in a value in the text box and clicks submit.

                  the file in the action, testing.php can read the value in that text box like so

                  [PHP]
                  <?php

                  echo $_POST['something'];

                  ?>
                  [/PHP]

                  any questions?

                  Comment

                  • hsriat
                    Recognized Expert Top Contributor
                    • Jan 2008
                    • 1653

                    #10
                    Good work, professor DM!

                    :)


                    Regards,
                    Harpreet

                    Comment

                    • coolsti
                      Contributor
                      • Mar 2008
                      • 310

                      #11
                      *rubs eyes*

                      Am I missing something here? The original poster presented this line as the way he was getting data from the user interface to his script:

                      /mailsend.php?ii d=1

                      This is telling me that he is not "POST"ing the variable, but sending it as part of the URL, so that the proper way to retrieve the variable is to use

                      $_GET['$name']

                      rather than

                      $_POST['$name']

                      Just so as not to confuse the OP if his variable is showing up in the $_GET array rather than the $_POST array.

                      /Steve, Denmark

                      Comment

                      Working...