insert data

Discussion in 'PHP' started by Alice24, Apr 18, 2011.

  1. #1
    I don't know why this code isn't word :(
    <?php 
     require_once('config.php');
    //This code runs if the form has been submitted
    if (isset($_POST['cere'])) { 
    
    
    // now we insert it into the database
    $insert = "INSERT INTO comment (nume, mail, comentariu)
    VALUES ('".$_POST['nume']."', '".$_POST['email']."', '".$_POST['comentariu']."')";
    $add_member = mysql_query($insert);
    ?>
    Data has been edited
    <meta http-equiv='Refresh' content='2; URL=test.php'>
    
    <?php 
    } 
    else 
    { 
    ?> 
     
    
    
    
    
                                    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    
                                      Numele tau*:<br /> 
    				 <input type="text" name="nume" size="50" /><br />
                                     Email-ul tau*:<br /> 
    	                        <input type="text" name="email" size="50" /><br />
    	                         COMENTARIU*:<br />
                                    <TEXTAREA NAME="comentariu" COLS=60 ROWS=9></TEXTAREA><br />	
    				*Campurile marcate cu steluta sunt obligatorii.<br /> 
    				<input id="buton" type="submit" name="cere" value="Trimite" style="margin-top:5px;"/> 
    				<input id="buton" type="reset" name="reset" value="Reseteaza" style="margin-top:5px;"/> 
    </form>
    
    <?php
    }
    ?>
    PHP:

     
    Alice24, Apr 18, 2011 IP
  2. AdM.as

    AdM.as Peon

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What's the error you are receiving? Is the page showing up and submitting but nothing is being placed into the database?
     
    AdM.as, Apr 18, 2011 IP
  3. phppro9x

    phppro9x Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    what is error, please post it
     
    phppro9x, Apr 18, 2011 IP
  4. Good Point

    Good Point Well-Known Member

    Messages:
    287
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    123
    #4
    Yes, an error message would be great....

    I've broken up your code though and tested it. Your SQL syntax seems to be ok (Just by glancing at it, i can't see an error).

    So my bet is on bad mysql login details, or you simply haven't setup a connection at all in your config.php file.

    But again, just speculation without more information on the error you're receiving.
     
    Good Point, Apr 19, 2011 IP
  5. Alice24

    Alice24 Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    it has no error message .
    it says Data has been edited
    but is not introducing anything in the table... i check the table name .. i check the config.php... everything is ok . but the script is not working :(
     
    Last edited: Apr 19, 2011
    Alice24, Apr 19, 2011 IP
  6. Safe Data

    Safe Data Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    mysql_query($insert) or die(mysql_error());
    PHP:
    Do you still get Data has been edited ?
     
    Safe Data, Apr 19, 2011 IP
  7. littlejohn199

    littlejohn199 Peon

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Also, to avoid SQL injection, you should clean up an user's input before inserting the data into your database.
     
    littlejohn199, Apr 19, 2011 IP
  8. Alice24

    Alice24 Greenhorn

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    Thank you guys now is working.
    @littlejohn199 what do you recommend for that?
    i really need to know how to do this.
     
    Alice24, Apr 20, 2011 IP
  9. jdoerr

    jdoerr Active Member

    Messages:
    121
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #9
    jdoerr, Apr 21, 2011 IP