Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    rwt
    rwt is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    INSERT INTO not working??

    hello all.
    I have this mySQL/php code that basicly inserts a textarea in a mySQL table:


    PHP Code:
    <form name="write" method="post" action="<?php echo $_SERVER['PHP_SELF']."?t=".$_GET['t']."&u=".$_GET['u']; ?>">
        <label> write new<br>
        </label>
        <table border="0" cellspacing="0" cellpadding="0">
            <?php if($_SESSION['logged'] !== true){echo'<tr>
                <td><label>Name </label></td>
                <td><label>
                    <input type="text" name="name" id="name">
                </label></td>
            </tr>'
    ;}?>
            <tr>
                <td>&nbsp;</td>
                <td><textarea name="writearea" id="writearea" cols="45" rows="5"></textarea></td>
            </tr>
        </table>
            <label>
            <input type="submit" name="submit" id="submit" value="Submit">
            </label>
        </p>
    </form>
    <?php
    $datetime 
    date("y-m-d h:i:s");
    if(
    $_SESSION['logged'] !== true){
        if(!isset(
    $_POST['name'])){ $_POST['name'] = 'Anonymous';}
    }
    if(isset(
    $_POST['writearea'])){
        
    mysql_query("INSERT INTO replies (SecretID, Name, User, Reply, DateTime)
        VALUES ('$user', '$_POST[name]', '$_SESSION[username]', '$_POST[writearea]', '$datetime',)"
    );
        echo
    "$user - $_POST[name] - $_SESSION[username] - $_POST[writearea] - $datetime<br />";
    }
    theres gotta be something wrong! I mean, the variables work as well as the arrays, but nothing is inserted into the database.

    By the way, the mySQL connection lines are in the script, I just didn't post them here.


    And this form is inclued in this code (as form_msg.php ):

    PHP Code:
    if($_GET['t'] == staff){
        
    $user $_GET['u'];
        
    $checkuser mysql_query("SELECT * FROM users WHERE ID='$user' and IsStaff=1 ;");
        
    $userfetch mysql_fetch_array($checkuser);
        
    $queryreplies mysql_query("SELECT * FROM replies WHERE SecretID='$user' ;");
        if(
    $_SESSION['isstaff'] == true)
        {
            if (
    $userfetch !== false){
                echo 
    'Welcome on '.$userfetch['Name'].'\'s page<br />';
                include(
    "form_msg.php");
                while(
    $fetchreplies mysql_fetch_array($queryreplies)){
                    echo 
    $fetchreplies['Name'].", on ".$fetchreplies['DateTime'].".<br />";
                    echo 
    "wrote".$fetchreplies['Reply']."<br />";
                }
            }
        }


  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    There is an extra coma at the end of the list of values. If you had some error checking and error reporting on your mysql_query() function call, PHP/mysql would have alerted you about this syntax error.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    rwt
    rwt is offline
    New Coder
    Join Date
    Jul 2006
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    arf, thanks, pretty stupid error I did.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •