what's wrong here.

Discussion in 'PHP' started by P_Namal, Feb 25, 2010.

  1. #1
    what's wrong here. not entering datas to database


    <html>
    <head>
    <title>xxxxxxxxxxxxxx</title>
    </head>
    <body>

    <form method="post" action="" name="myform">
    Name
    <input type="text" name="text">
    <input type="submit" value="add record" name="submit">
    </form>

    <?php
    $name=$_POST["text"];

    $linkz=mysql_connect("localhost","root","")or die("no");
    mysql_select_db("test")or die("no db");
    $sql="INSERT INTO student(tname)VALUES($name)";

    mysql_query($sql,$linkz);
    echo "OK".$name."entered";
    mysql_close($linkz);
    ?>


    </body>
    </html>
     
    P_Namal, Feb 25, 2010 IP
  2. P_Namal

    P_Namal Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    pls help. enybody
     
    P_Namal, Feb 25, 2010 IP
  3. hireme

    hireme Member

    Messages:
    58
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #3
    try adding quotes to $name:

    $sql="INSERT INTO student(tname)VALUES('$name')";
     
    hireme, Feb 25, 2010 IP
  4. P_Namal

    P_Namal Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks i will try
     
    P_Namal, Feb 25, 2010 IP
  5. P_Namal

    P_Namal Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks lot. it's workink now
     
    P_Namal, Feb 25, 2010 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    When you are adding a sql command in add or die(mysql_error())) at the end. Keep that when you are creating the software. Will save you a lot of debugging time in the end.
     
    HuggyStudios, Feb 26, 2010 IP