Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts

    How to display database table info in browser

    Hello all,

    I'm playing around with a database trying to get a better understanding of it all. Anyway, I've set it up where anyone can add their information to the database. On the confirmation page, it says a simple "you're information has been added. However, I'd like to change it to where it displays all the information in the table beneath it. This is what I have so far. Any help?

    PHP Code:
    <?php require_once("db_connx.php");
    $first $_POST['first'];
    $last $_POST['last'];
    $email =  $_POST['email'];
    $cell $_POST['cell'];
    $major $_POST['major'];
    $gpa $_POST['gpa'];
    $startDate $_POST['startDate'];

    if (
    mysql_query ("INSERT INTO student (FirstName, LastName, Email, CellPhone, Major, GPA, StartDate) VALUES ('$first', '$last', '$email','$cell', '$major', '$gpa', '$startDate')"))
    { echo 
    "Student successfully added to the database <br />" 
     
    }
    else
    { echo 
    "Error adding student"; }
    require_once(
    "db_connx_close.php");
    ?>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    PHP Code:
    { echo "Student successfully added to the database <br />" 
     

    Instead of the above, save the string into a variable, like
    PHP Code:
    $success"Student successfully added to the database <br />" ;
     } 
    and then, add the following code where you need to get the printed result.
    PHP Code:
    <?php
    if(isset($success))
      echo 
    $success;
    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    javanewbie7 (04-24-2012)

  • #3
    Regular Coder
    Join Date
    Oct 2010
    Posts
    127
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by iBall View Post

    As a side issue, if this was for the real world then you would also have to validate and sanitise all the user inputs before inserting them into the database table.
    Would this be a good link to look at to learn how to do what you suggested (validating).

    http://www.w3schools.com/php/php_fil...p?output=print


  •  

    Posting Permissions

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