plz solove my prob...

Discussion in 'PHP' started by yasir_php_lover, Jun 17, 2013.

  1. #1
    i have created two pages,
    1. login.php
    2. connect.php
    3. same fields in database.
    but data could not inserted in database, ????



    <head>
    <title>Hello!</title>
    </head>

    <body>

    <form action="connect.php" mathod="post">
    Username :<input type="text" name="fname"></br>
    Password :<input type="password" name="pwd"></br>
    Click here :<input type="submit" name="submit" value="Submit">
    </form>

    </body>

    </html>

    ==========
    <?php

    mysql_connect('localhost','root','') or die ('Could not connect');

    echo('Connected Successfully!')."<br />";

    mysql_select_db('yasir') or die ('Database not found');

    echo('Connected Successfully with Database!');

    $name = $_POST['fname'];

    $company = $_POST['pwd'];

    $sql ="INSERT into user(`firstname`, `password`) values('$name','$company')";

    $query = mysql_query($sql);

    if($query){

    echo mysql_error();
    } else {

    echo 'inserted successfully';
    }
    ?>
     
    yasir_php_lover, Jun 17, 2013 IP
  2. amber.long83

    amber.long83 Active Member

    Messages:
    144
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #2
    add id too .. and try

    Username :<input type="text" name="fname" id="fname"></br>
    Password :<input type="password" name="pwd" id="pwd"></br>
     
    amber.long83, Jun 17, 2013 IP
  3. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #3
    malky66, Jun 18, 2013 IP
  4. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #4
    IDs aren't important in this case.

    if($query){
    
    echo mysql_error();
    } else {
    
    echo 'inserted successfully';
    }
    PHP:
    What was this supposed to do?
     
    ActiveFrost, Jun 18, 2013 IP
  5. sorindsd

    sorindsd Well-Known Member

    Messages:
    201
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    118
    #5
    mathod="post" is the problem ... should be method="post"
     
    sorindsd, Jun 18, 2013 IP
  6. samyak

    samyak Active Member

    Messages:
    280
    Likes Received:
    7
    Best Answers:
    4
    Trophy Points:
    90
    #6
    Yeah, as sorindsd said, you have a misspelled method to 'mathod' causing the form varialbles $_POST['fname'] and $_POST['pwd'] to be empty. I am guessing that multiple entries were added in the tables, all with empty name and password.
     
    samyak, Jun 18, 2013 IP
  7. webdeveloperindia

    webdeveloperindia Active Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    73
    #7
    Hi!
    Every thing i perfect just check spilling mistake in html tags and attributes.
    To solve the issue change this line :
    
    <form action="connect.php" mathod="post">
    
    Code (markup):
    to this :
    
    <form action="connect.php" method="post">
    
    Code (markup):
    To avoid these kind of mistakes, It will be better if you use a good text editor like Note++ or Dreamweaver !
     
    webdeveloperindia, Jun 19, 2013 IP
  8. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #8
    I think the problem has already been solved, but thanks for telling us all what we already know. :)
     
    HuggyStudios, Jun 19, 2013 IP
  9. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #9
    Oh and you can also check if the script receives a POST from a form with

    
    if ($_SERVER['REQUEST_METHOD'] == "POST")
    {
    // do your thing
    }
    
    PHP:
     
    EricBruggema, Jun 21, 2013 IP