Announcement

Collapse
No announcement yet.

How to display database records on screen?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to display database records on screen?

    I have successfully created forms with ABVFP and now they are working nice. My problem is how to display back the information to the screen. Like if someone wants to see their profile or query a list. how are these information displayed. I appreciate any input. thanks.

  • #2
    Re: How to display database records on screen?

    You need a script to do this. Especially to query the database. There are many programing and security issues involved. In any case, you need to study a bit about MySQL and php. Google it, there are hundreds of online free tutorials.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment


    • #3
      Re: How to display database records on screen?

      Well heres a nice code that should work for displaying a users data.
      PHP Code:
      function displayUsersData($username$table) {
       
      $con connect() // <--- THIS LINE IS JUST FOR THE CODE, REPLACE IT WITH YOUR DB CONNECTION
       
      $query "SELECT * FROM " .$table" WHERE username='$username'"//SELECTS ALL INFO FROM THE DB WHERE THE USERNAME IS THE USERS USERNAME, thats weird to say
       
      $result mysql_query($query$con) or die(mysql_error()); //THE QUERY
       
      while($data mysql_fetch_array($result)){
        echo 
      $data['email']; //This will echo the row in the database called email, replace this with whatever row you want and you can add more lines, see below
        
      echo $data['id']; //And more
        
      echo $data['something']; //And so on...
       
      }
      }
      //TO CALL THE FUNCTION
      displayUsersData($username$table_name); //Replace with your values 
      Does this answe your question?

      Comment


      • #4
        Re: How to display database records on screen?

        Sorry forgot the ';' This is the code you should use
        PHP Code:
        function displayUsersData($username$table) { 
         
        $con connect(); // <--- THIS LINE IS JUST FOR THE CODE, REPLACE IT WITH YOUR DB CONNECTION 
         
        $query "SELECT * FROM " .$table" WHERE username='$username'"//SELECTS ALL INFO FROM THE DB WHERE THE USERNAME IS THE USERS USERNAME, thats weird to say 
         
        $result mysql_query($query$con) or die(mysql_error()); //THE QUERY 
         
        while($data mysql_fetch_array($result)){ 
          echo 
        $data['email']; //This will echo the row in the database called email, replace this with whatever row you want and you can add more lines, see below 
          
        echo $data['id']; //And more 
          
        echo $data['something']; //And so on... 
         


        //TO CALL THE FUNCTION 
        displayUsersData($username$table_name); //Replace with your values 

        Comment


        • #5
          Re: How to display database records on screen?

          Thanks, Phouber. I appreciate it.

          I also got other codes for login, querying, etc. but where will I put them on the page?
          Should i put them on the ACTION part of the form, or no need to make a form?
          The BVBuilder icon for script is only good for VBScript not php.

          Just need a little help here.
          Appreciate any input from anyone.
          Thanks.

          Comment


          • #6
            Re: How to display database records on screen?

            The action of your form should link to another page (or the same page if you know how to do it, but that add complexity, its easier to set the action to a separate page). On the page that the action leads to you insert the php code.

            You can insert the php code as if it was html code, keeping in mind the page needs to have a .php extension, and the code needs to be surrounded with <? and ?>

            Register/Login Script
            Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

            Comment


            • #7
              Re: How to display database records on screen?

              Hi,

              Be careful because it has ocurred to me with WAMP that the php entrance tag <? did not work and forced me to change all my code to tag <?php.

              About showing the table content I would suggest to use a class that would show that content no matter the fields/sizes/etc/etc of that table.
              This class would read all tables no matter what.

              This is an example of the code:

              <?php
              include("include/config.php");
              $table = $_GET['t'];
              $lines = $_GET['l'];
              $page = $_GET['p'];
              require ("classes/class_pagination.php");
              $page= new pagination;
              $page->conect_to("$hostname", "$user_db", "$pass_db","$database");
              $page->setLines($lines);
              $page->setTable("$table");
              $page->showLines();
              $page->showPagelinks($lines);
              ?>

              File config.php would contain Your database info.
              File classe_pagination.php would contain the class program.

              With this example You can consult/list all Your tables.

              The syntax at the browser would be:
              www.yourdomain.com/list_table.php?t=tablename&l=linesperpage&p=pagenu mber

              Hope I've helped,
              pipesportugal

              Comment


              • #8
                Re: How to display database records on screen?

                Thanks all.
                You know I am not even there yet.
                I mean displaying the record on screen because I am still on the login page.
                The site would ask for the username and password, then the record will be located and displayed on screen.
                That's how its supposed to work.
                I thought I would pass this easy but turns out I am stuck here.
                Here is the site:http://www.godhearme.org/GHM/ProfileAccess.php
                It just would not pull the record to populate another screen.
                keeps coming back to the login page.
                Whats wrong?
                Need help here.. appreciate it. thanks.

                sample username: ana password:112233

                Here are the codes for the login script:
                <?
                require_once "ghm_conn.php";

                if(isset($s1))
                {
                if(!empty($username1) && !empty($password1))
                {
                $sql = "SELECT * FROM _Form_Nr_2 WHERE username = '$username1' AND password = '$password1'";
                $result = mysql_query($sql);
                if(mysql_num_rows($result) == "1")
                {
                $a = mysql_fetch_array($result);
                $username1 = $a['username'];
                $_SESSION[username] = $username1;
                header("location:Profile.php");
                exit();
                }

                }
                }
                include_once "ProfileMain.php";
                ?>
                <center>
                <br>
                <br>
                <br>
                <br>
                <br>
                <br>
                <br>
                <br>
                <span class=HeaderClass>Members Login </span>
                <p class=BlackLink>You must log in to access this area of the site.<br> If you are
                not a registered user, <a href="http://www.godhearme.org/GHM/Register.html" class=TNA> click here</a> to sign up.</p>
                <p>

                <form name=jsl method="post" action="ProfileAccess.php">
                <table align=center class=BlackText>
                <tr>
                <td align=right>Username:</td>
                <td> <input type="text" name="username1" size="30" maxlength=30></td>
                </tr>
                <tr>
                <td align=right>Password:</td>
                <td><input type="password" name="password1" size="30" maxlength=30></td>
                </tr>
                <tr>
                <td>&nbsp;</td>
                <td>
                <input type=hidden name=job_id value=<? echo $_GET[job_id]?>>
                <input type="submit" name=s1 value=" Login " style="font-family:verdana; font-weight:bold; color:#993300; background-color:white">
                </td>
                </tr>

                <tr>
                <td colspan=2 align=center>
                <br>
                <a class=TNA href=forgot.php> Forgot your username/password? </a></td></tr>

                </table>
                </form></p>
                </center>

                <?

                Comment


                • #9
                  Re: How to display database records on screen?

                  As a main problem, i can say that you are retrieving the row (as $a) but yiu are not setting the $username to be $a['username'] which is necessary. See part in red in your post.

                  Since other pieces of your code are nor included in your post, i can't know if they are correct or not.
                  Navaldesign
                  Logger Lite: Low Cost, Customizable, multifeatured Login script
                  Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                  DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                  Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                  Comment


                  • #10
                    Re: How to display database records on screen?

                    well, it didnt really help. the logon screen still keeps on looping.
                    other codes with this login script is below.

                    Appreciate any help. thanks.

                    The ghm_conn.php are the following :
                    (password is xxx for security)
                    <?
                    $db_host = "localhost";
                    $db_username = "rhidsrn_maryfil";
                    $db_password = "xxx";
                    $db_name = "rhidsrn_GHM";
                    $script_dir = "GHM";
                    //////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////
                    //////////////////////////////////////////////////////
                    //connect to the database server
                    $connection = mysql_connect($db_host, $db_username, $db_password) or die(mysql_error());

                    //select database
                    $db = mysql_select_db($db_name, $connection);
                    session_start();
                    if(!empty($script_dir))
                    {
                    $dir = "/".$script_dir;
                    }
                    $t = time();
                    ?>

                    Comment


                    • #11
                      Re: How to display database records on screen?

                      The connection looks fine, whats the code on "ProfileMain.php"

                      and..
                      Originally posted by pipesportugal View Post
                      Be careful because it has ocurred to me with WAMP that the php entrance tag <? did not work and forced me to change all my code to tag <?php.
                      Thats just because short tags are disabled, you need to configure your php.ini for WAMP, I guess short tags are disabled by default. (The majority of web hosts have it enabled so its not a problem normally)

                      Register/Login Script
                      Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

                      Comment


                      • #12
                        Re: How to display database records on screen?

                        i think the ProfileMain.php is working fine. It is the background form.
                        The loop happens when you enter the username and password.
                        it just never got to the next page.

                        Thanks.

                        anyways, below is ProfileMain
                        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
                        <html>
                        <head>
                        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                        <title>ProfileMain</title>
                        <meta name="KEYWORDS" content="prayers, God, problem, suicide, 'group prayer', angels, problems">
                        <meta http-equiv="Page-Enter" content="revealTrans(Duration=1,Transition=1)">
                        <meta name="GENERATOR" content="Created by BlueVoda">
                        <style type="text/css">
                        div#container
                        {
                        width: 769px;
                        position: relative;
                        margin-top: 0px;
                        margin-left: auto;
                        margin-right: auto;
                        text-align: left;
                        }
                        body
                        {
                        text-align: center;
                        margin: 0;
                        }
                        </style>
                        <script type="text/javascript">
                        <!--
                        function SwapImage()
                        {
                        var doc=document, args=arguments;
                        doc.$imgSwaps = new Array();
                        for(var i=2; i<args.length; i+=2)
                        {
                        var elem=FindObject(args[i]);
                        if(elem)
                        {
                        doc.$imgSwaps[doc.$imgSwaps.length]=elem;
                        elem.$src=elem.src;
                        elem.src=args[i+1];
                        }
                        }
                        }
                        // -->
                        </script>
                        <script type="text/javascript">
                        <!--
                        function FindObject(id, doc)
                        {
                        var child, elem;
                        if(!doc)
                        doc=document;
                        if(doc.getElementById)
                        elem=doc.getElementById(id);
                        else
                        if(doc.layers)
                        child=doc.layers;
                        else
                        if(doc.all)
                        elem=doc.all[id];
                        if(elem)
                        return elem;
                        if(doc.id==id || doc.name==id)
                        return doc;
                        if(doc.childNodes)
                        child=doc.childNodes;
                        if(child)
                        {
                        for(var i=0; i<child.length; i++)
                        {
                        elem=FindObject(id,child[i]);
                        if(elem)
                        return elem;
                        }
                        }
                        var frm=doc.forms;
                        if(frm)
                        {
                        for(var i=0; i<frm.length; i++)
                        {
                        var elems=frm[i].elements;
                        for(var j=0; j<elems.length; j++)
                        {
                        elem=FindObject(id,elems[i]);
                        if(elem) return elem;
                        }
                        }
                        }
                        return null;
                        }
                        // -->
                        </script>
                        </head>
                        <body bgcolor="#FFE4E1" text="#000000">
                        <div id="container">
                        <div id="bv_" style="position:absolute;left:0px;top:0px;width:76 8px;height:108px;z-index:0" align="left">
                        <img src="bv01302.gif" id="Shape3" align="top" alt="" border="0" width="768" height="108"></div>
                        <div id="bv_" style="position:absolute;left:24px;top:0px;width:2 88px;height:81px;z-index:1" align="left">
                        <img src="bv01301.gif" id="Shape2" align="top" alt="" border="0" width="288" height="81"></div>
                        <div id="bv_" style="position:absolute;left:384px;top:27px;width :240px;height:38px;z-index:2" align="left">
                        <font style="font-size:27px" color="#000000" face="Comic Sans MS">Your Profile</font></div>
                        <div id="bv_" style="position:absolute;left:48px;top:0px;width:2 37px;height:46px;z-index:3" align="center">
                        <font style="font-size:19px" color="#000000" face="Lucida Sans Unicode"><b><br>
                        www.GodHearMe.org</b></font></div>
                        <div id="bv_" style="position:absolute;left:48px;top:81px;width: 648px;height:19px;z-index:4" align="left">
                        <font style="font-size:16px" color="#000000" face="Times New Roman"><b> &quot;Surely the arm of the LORD is not too short to save, nor his ear too dull to hear.&quot;&nbsp; Isaiah 59</b></font></div>
                        <img src="j0423103[1].jpg" id="Image2" alt="" align="top" border="0" width="120" height="108" style="position:absolute;left:24px;top:432px;width :120px;height:108px;z-index:5">
                        <a href="http://www.godhearme.org/index.html"><img src="homepage.jpg" id="Image1" alt="" align="top" border="0" width="40" height="45" style="position:absolute;left:672px;top:27px;width :40px;height:45px;z-index:6"></a>
                        <div id="bv_" style="position:absolute;left:24px;top:161px;width :131px;height:220px;z-index:7" align="center">
                        <table border="0" cellpadding="0" cellspacing="0" id="NavigationBar1">
                        <tr>
                        <td align="left" valign="top" width="131" height="30"><a href="http://www.godhearme.org/index.html"><img id="bv01310" src="bv01310.gif" alt="Home" title="Home" align="top" border="0" width="131" height="30" onmouseover="SwapImage(1,0,'bv01310','bv01310_over .gif')" onmouseout="SwapImage(0,0,'bv01310','bv01310.gif') "></a></td>
                        </tr>
                        <tr><td height="8"></td></tr><tr>
                        <td align="left" valign="top" width="131" height="30"><a href="http://www.godhearme.org/Request.html"><img id="bv01312" src="bv01312.gif" alt="Edit Profile" title="Edit Profile" align="top" border="0" width="131" height="30" onmouseover="SwapImage(1,0,'bv01312','bv01312_over .gif')" onmouseout="SwapImage(0,0,'bv01312','bv01312.gif') "></a></td>
                        </tr>
                        <tr><td height="8"></td></tr><tr>
                        <td align="left" valign="top" width="131" height="30"><a href="http://www.godhearme.org/Profile.html"><img id="bv01311" src="bv01311.gif" alt="Your Profile" title="Your Profile" align="top" border="0" width="131" height="30" onmouseover="SwapImage(1,0,'bv01311','bv01311_over .gif')" onmouseout="SwapImage(0,0,'bv01311','bv01311.gif') "></a></td>
                        </tr>
                        <tr><td height="8"></td></tr><tr>
                        <td align="left" valign="top" width="131" height="30"><a href="http://www.godhearme.org/Testimony.html"><img id="bv01315" src="bv01315.gif" alt="YourTestimony" title="YourTestimony" align="top" border="0" width="131" height="30" onmouseover="SwapImage(1,0,'bv01315','bv01315_over .gif')" onmouseout="SwapImage(0,0,'bv01315','bv01315.gif') "></a></td>
                        </tr>
                        <tr><td height="8"></td></tr><tr>
                        <td align="left" valign="top" width="131" height="30"><a href="http://www.godhearme.org/PrayForSomeone.html"><img id="bv01313" src="bv01313.gif" alt="Your Prayers" title="Your Prayers" align="top" border="0" width="131" height="30" onmouseover="SwapImage(1,0,'bv01313','bv01313_over .gif')" onmouseout="SwapImage(0,0,'bv01313','bv01313.gif') "></a></td>
                        </tr>
                        <tr><td height="8"></td></tr><tr>
                        <td align="left" valign="top" width="131" height="30"><a href="http://www.godhearme.org/AnsweredPrayers.html"><img id="bv01314" src="bv01314.gif" alt="Commitments" title="Commitments" align="top" border="0" width="131" height="30" onmouseover="SwapImage(1,0,'bv01314','bv01314_over .gif')" onmouseout="SwapImage(0,0,'bv01314','bv01314.gif') "></a></td>
                        </tr>
                        </table>
                        </div>
                        <div id="bv_" style="position:absolute;left:24px;top:540px;width :144px;height:19px;z-index:8" align="center">
                        <font style="font-size:16px" color="#000000" face="Arial"><b>God loves you!</b></font></div>
                        </div>
                        </body>
                        </html>

                        Comment


                        • #13
                          Re: How to display database records on screen?

                          Hey

                          I'm sorry I asked for the code of the wrong page. Whats the code for "Profile.php"

                          I'm thinking there is a condition on this page that has it redirect back to your login, and because of some bug or logical error that condition is being met, which is causing the loop. That is to say your login form is redirecting to profile.php because it just logged you in. When you get to profile.php, its not validating that login to its redirecting back to the login page.

                          On a side note:
                          In your script, all of your posted variables are not being properly registered. (As it is now they will still work, I will explain this in the next paragraph). For each variable like $s1, $username1, or $password1 you need to either change each to $_POST['s1'], or before they are used in the script assign each to their posted value, such as $s1 = $_POST['s1'];

                          As it is now, it is using what is called register_globals, which is obsolete feature. A feature disabled by default in php5, and a feature that won't be present at all in php6. Using it will very likely cause your script to not work at some point. If you plan on using this script (once working that is) for an extended period of time (for years to come) you need to make sure it doesn't rely on register globals.

                          Register/Login Script
                          Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script

                          Comment


                          • #14
                            Re: How to display database records on screen?

                            Why don't you start by changing this line:

                            if(!empty($_POST['$username1']) && !empty($_POST['$password1]))

                            and

                            if(isset($_POST['s1']))

                            and see how this is?

                            Most probably register_globals is ALREADY disabled in your server.
                            Navaldesign
                            Logger Lite: Low Cost, Customizable, multifeatured Login script
                            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
                            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
                            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

                            Comment


                            • #15
                              Re: How to display database records on screen?

                              Originally posted by navaldesign View Post
                              Thats just because short tags are disabled, you need to configure your php.ini for WAMP, I guess short tags are disabled by default. (The majority of web hosts have it enabled so its not a problem normally)
                              naval, Thanks for the explanation, I have never even opened that file to see what's inside.
                              Have You seen my other thread about the new user to reserved area link ? Can You help? Please.

                              Cheers,

                              pipesportugal

                              Comment

                              Working...
                              X