Results 1 to 4 of 4

Thread: Help with Displaying Data from database

  1. #1
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Help with Displaying Data from database

    Hi I am a noob so be gentle,

    I have got the database written, also the upload form, wich works....

    What I want todo is to pull the information into a table (as Devined below)
    to display all the entries in an array of tables...

    This is where I am completly stuck, anyone can help I would be greatful..

    Upload form:
    Code:
    <?php
    
    # DATABASE CONFIGURE
    
    $hostname = "localhost";
    $db_user = "root";
    $db_password = "root";
    $database = "film";
    $db_table = "film_info";
    
    
    # STOP HERE
    
    # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE
    $db = mysql_connect($hostname, $db_user, $db_password);
    mysql_select_db($database,$db);
    ?>
    <html>
    <head>
    <title>Upload Form</title>
    </head>
    <body>
    
    <?php
    if (isset($_REQUEST['Submit'])) {
    
    $sql = "INSERT INTO $db_table(title,info,download,view,year,plus) values ('".mysql_real_escape_string(stripslashes($_REQUEST['title']))."','".mysql_real_escape_string(stripslashes($_REQUEST['info']))."','".mysql_real_escape_string(stripslashes($_REQUEST['download']))."','".mysql_real_escape_string(stripslashes($_REQUEST['view']))."','".mysql_real_escape_string(stripslashes($_REQUEST['year']))."','".mysql_real_escape_string(stripslashes($_REQUEST['plus']))."')";
    if($result = mysql_query($sql ,$db)) {
    echo '<h1>Thank you</h1>Your information has been entered into our database<br><br><h3><a href="upload.php">New Entry</a></h3>';
    } else {
    echo "ERROR: ".mysql_error();
    }
    } else {
    ?>
    <h1>Films Update Form</h1><hr>
    <form method="post" action="">
    <b>Title:</b>   <br>
    <input type="text" name="title" size="100">
    <br>
    <b>Info:</b>    <br>
    <input type="text" name="info" size="100">
    <br>
    <b>Download:</b> <br>
    <input type="text" name="download" size="100" value=".avi">
    <br>
    <b>View:</b>    <br>
    <input type="text" name="view" size="100" value=".php">
    <br>
    <b>Year:</b>   <br>
    <input type="text" name="year" size="100" value="2009">
    <br>
    <b>Plus:</b>  <br>
    <input type="text" name="plus" size="100">
    <br>
    <br><br>
    <input type="submit" name="Submit" value="Submit">
    </form>
    <?php
    }
    ?>
    </body>
    </html>

    Table Format:
    Code:
    <table border="1" width="301">
        <tr>
            <td width="291">
                <table width="292">
                    <tr>
                    <td width="282" height="40" align="center"> . $row['title'] . </td>
                    </tr>
                    <tr>
                        <td width="282" height="66"> . $row['info'] . </td>
                    </tr>
                </table>
                <table width="292">
                    <tr>
                        <td width="153" align="center" height="44"> . $row['year'] . </td>
                        <td width="64" height="44">
                            <p align="center"><a href="" . $row['view'] . "" target="detail" title="View Film"><img src="FILMSTRIp.GIF" border="0"></a></p>
                        </td>
                        <td width="61" height="44">
                            <p align="center"><a href="" . $row['download'] . "" title="Download Film"><img src="download_48.png" border="0"></a></p>
                        </td>
                    </tr>
    </table>
    
            </td>
        </tr>
    </table>

  2. #2
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    Your form will need an action variable. You can have it send the submitted info back to the file your working on.

    This is to update fields in the DB.
    Code:
    $a = "UPDATE db_name SET field='value' WHERE condition";	
    	$b = mysqli_query ($dbinfo, $a) or trigger_error("Query: $a\n<br />MySQL Error: " . mysqli_error($dbinfo));
    This is to call fields from the DB.
    Code:
    $a = "SELECT field FROM db_name WHERE condition";
    $whatyouwantdisplayed = mysqli_query ($dbinfo, a) or trigger_error("Query: $a\n<br />MySQL Error: " . mysqli_error($dbinfo));
    I too am a n00b so I hope this will help you. Goodluck.

  3. #3
    Join Date
    Dec 2005
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Wow that lost me completly...............

    Quote Originally Posted by AdrielGreene View Post
    Your form will need an action variable. You can have it send the submitted info back to the file your working on.

    This is to update fields in the DB.
    Code:
    $a = "UPDATE db_name SET field='value' WHERE condition";	
    	$b = mysqli_query ($dbinfo, $a) or trigger_error("Query: $a\n<br />MySQL Error: " . mysqli_error($dbinfo));
    This is to call fields from the DB.
    Code:
    $a = "SELECT field FROM db_name WHERE condition";
    $whatyouwantdisplayed = mysqli_query ($dbinfo, a) or trigger_error("Query: $a\n<br />MySQL Error: " . mysqli_error($dbinfo));
    I too am a n00b so I hope this will help you. Goodluck.

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    What I do is the basic PHP query:-

    $result = mysql_query('SELECT * FROM `mytable` WHERE condition');

    I then put the field values into variables:-

    $name=mysql_result($result,$id,"Name");
    $company=mysql_result($result,$id,"Enterprise");

    and then in the HTML secion I use this to display the values from the table for a form input:-


    <td>input type="text" name="FName" value="<? echo "$name"?>" /></td>

    Hope this is what you were looking for.
    Last edited by forum_amnesiac; 04-14-2009 at 12:19 PM. Reason: spelling

Bookmarks

Posting Permissions

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