Insert data into table- simple problrm

Discussion in 'PHP' started by progfrog, Dec 14, 2008.

  1. #1

    Hi!
    I posted the data in this script from a form - the variables in this code stored the data inserted from the textboxes in the form.
    from some reasom this doesn't work.

    Any Idea?
    
    
    <?php
    $x = $_POST['name'];
    $y = $_POST['age'];
    $z= $_POST['subject'];
    
    $mysql_link= mysql_connect('localhost','root','') or die("ERROR:cannot connect");
    echo "connected successfully to MySQL server.";
    
    mysql_select_db('pets',$mysql_link) or die ("could not open db".mysql_error());
    echo "connected successfully to pets.";
    
    mysql_query("INSERT INTO students (name, age, subject) 
    VALUES ($x, $y, $z)"); 
    mysql_close($mysql_link);
    ?>
    
    
    PHP:

     
    progfrog, Dec 14, 2008 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    Try:

    VALUES ('$x', '$y', '$z)');
     
    Colbyt, Dec 14, 2008 IP
  3. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #3
    And PLEASE escape your data...
     
    Danltn, Dec 14, 2008 IP