www.webdeveloper.com
Results 1 to 6 of 6

Thread: some one reply how to make it

  1. #1
    Join Date
    Jun 2013
    Posts
    3

    Angry some one reply how to make it

    i m new in php i make two pages first was first.php
    the second was insert.php the codes are below but it show Notice: Undefined index:
    how to remove this error
    thanks

    first page

    <!DOCTYPE html>
    <html>
    <body>
    <form id="firstform" action="insert.php" method="post">
    <center> My First Page in PHP </center>
    <center>Name:<input type="text" id="name" size=20>
    FatherName: <input type="text" id="fname" size=20>
    Address:<input type="text" id="add" size=20>
    <input type="submit" name="sub">
    </form>
    </body>
    </html>

    insert page

    <html>
    <body>
    <?php

    $con=mysqli_connect("localhost","root","khan","first");
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $sql="INSERT INTO bio(name, fathername , address)
    VALUES
    ('$_POST[name]','$_POST[fname]','$_POST[add]')";

    if (!mysqli_query($con,$sql))
    {
    die('Error: ' . mysqli_error($con));
    }
    echo "1 record added";

    mysqli_close($con);
    ?>
    </body>
    </html>

  2. #2
    Join Date
    Mar 2011
    Posts
    1,160
    I see at least one error. Replace
    Code:
    $sql="INSERT INTO bio(name, fathername , address) VALUES
    ('$_POST[name]','$_POST[fname]','$_POST[add]')";
    with
    Code:
    $sql="INSERT INTO bio (name, fathername , address) VALUES (\"" .
    $_POST['name'] . "\",\"" $_POST['fname'] . "\",\"" . $_POST['add'] . "\")";
    You should never directly include data from $_POST or $_GET in a MySQL query. It is vulnerable to hacking. To make your code more secure, check out http://www.php.net/manual/en/mysqli....ape-string.php including the examples.

  3. #3
    All right, so most people might not think of email as a social network. But the fact is they’re limiting their mentality—and sales potential. Social networks are just digital platforms designed to help people interact in real time, and spread the word about topics they care about. Email provides the same connection and sharing potential!

  4. #4
    Join Date
    Jun 2013
    Posts
    2
    In addition to what rtrethewey mentioned.
    you need to put the name attribute in the HTML as well.

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <form id="firstform" action="insert.php" method="post">
    <center> My First Page in PHP </center>
    <center>Name:<input type="text" id="name" name="name" size=20>
    FatherName: <input type="text" id="fname" name="fname"  size=20> 
    Address:<input type="text" id="add" name="add" size=20> 
    <input type="submit" name="sub">
    </form>
    </body>
    </html>

  5. #5
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    Did my post get removed from this thread?

  6. #6
    Join Date
    Aug 2012
    Location
    TX
    Posts
    293
    bases on
    http://en.kioskea.net/faq/3140-php-n...ndefined-index

    it seems he is posting information to the database and hes not matching up the names right.
    Last edited by Nicholas Diaz; 06-19-2013 at 08:43 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles