Issue with posting data to mysql table

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

    Issue with posting data to mysql table

    I have this php code that I can get most of the data to post, but I am having a little bit of trouble..

    I am passing the actualy student number to the page i.e. ?&id=1 this is used to pull the information from another table.

    When I submit this data, it will post the time, date and the sender id... but nothing else is posted.

    Here is the code.

    [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();

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

    _v('mode;i:id') ;
    _v('msg_from,ms g_to,msg_body,m sg_date,msg_tim e,msg_subject,m sg_isread,msg_s id,msg_tid');


    if ($mode=='adds')
    {
    _v('msg_from,ms g_to,msg_body,m sg_date,msg_tim e,msg_subject,m sg_isread,msg_s id,msg_tid');
    $query = mysql_query("IN SERT INTO email VALUES ('' ,'$from', '$to', '$msg', '$now', '$t', '$subject', '1', '$myID', '$tid')") or die(mysql_error ());

    echo " <br><br><br><Br > ";

    goto('mail.php' );
    die();
    }


    $query = mysql_query("SE LECT * FROM `instructors` WHERE id='$myID'");
    $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='emailme .php'>

    <table border=0 width=99% cellpadding=0 cellspacing=0>
    <Td wdith=100%>";

    $query = mysql_query("SE LECT * from instructors WHERE id='$id'");
    $Row = mysql_fetch_arr ay($query);
    extract($Row);
    $tid = $Row['id'];
    $name1 = $Row['first_name'] . " " . $Row['last_name'];

    echo "


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


    <p><span class='text'>To : <b>$name1 - $tid</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='to' value='$id'>
    <input type='hidden' name='from' value='$name'>
    <input type='hidden' name='mode' value='adds'>
    <p><input type=submit name='submit' value='Send Message' class='input' >
    </form>
    </p>


    </td>
    </table>";



    include('navbot .php');

    ?>
    [/php]

    Thank you
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    First of all, you don't have <tr> anywhere. Tables should be made like:
    [HTML]<table>
    <tr>
    <td>
    {content}
    </td>
    </tr>
    </table>[/HTML]

    Also, your form is all over the place?! U Start with echo-ing a </form>??? Why? I don't think these are the problems but it is very hard to troubleshoot when you need to work through bad html.

    I have made some minor changes to the code, just so others can read it a bit better. Feel free to scan through and check what changes I have made so you can get an idea what I'm on about.

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

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

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

    _v('mode;i:id') ;
    _v('msg_from,ms g_to,msg_body,m sg_date,msg_tim e,msg_subject,m sg_isread,msg_s id,msg_tid');


    if ($mode=='adds')
    {
    _v('msg_from,ms g_to,msg_body,m sg_date,msg_tim e,msg_subject,m sg_isread,msg_s id,msg_tid');
    $query = mysql_query("IN SERT INTO email VALUES ('' ,'$from', '$to', '$msg', '$now', '$t', '$subject', '1', '$myID', '$tid')") or die(mysql_error ());

    echo " <br><br><br><br > ";

    goto('mail.php' );
    die();
    }


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

    echo "
    <table border=0 width=100% class=leftMenut op1>
    <tr>
    <td>
    <form method='post' name='frmado' action='emailme .php'>

    <table border=0 width=99% cellpadding=0 cellspacing=0>
    <tr>
    <td wdith=100%>";

    $query = mysql_query("SE LECT * FROM instructors WHERE id='$id'");
    $Row = mysql_fetch_arr ay($query);
    $tid = $Row['id'];
    $name1 = $Row['first_name'] . " " . $Row['last_name'];

    echo "
    <p><br><p><sp an class='text'>Fr om: <b>$name</b></p>
    <p><span class='text'>To : <b>$name1 - $tid</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='to' value='$id'>
    <input type='hidden' name='from' value='$name'>
    <input type='hidden' name='mode' value='adds'>
    <p><input type=submit name='submit' value='Send Message' class='input' ></p>

    </td>
    </tr>
    </table>

    </form>

    </td>
    </tr>
    </table>";

    include('navbot .php');
    ?>
    [/code]

    That is not complete, but your code needs some going through. Fix up those things and then we can move onto the real problem.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi.

      You say that it does post the time, date and the sender id... I can't see <input> elements for any of those in your code. I suspect it has something to do with your _v() function... but I don't really know.

      Is there something I'm not seeing here?

      Also...
      A couple of tips

      Avoid using the <?...?> tags in your code. They are not enabled by default and can cause problems if you ever switch servers, or your current server is updated. Use <?php ... ?> instead. It's much safer ;)

      I would also recommend against using the wild-card (*) in your SELECT queries. It will instruct your SQL server to return all columns, which will most likely transfer much more data than you actually use. Specify only the columns you need. It's just good practice ;)

      Comment

      Working...