Log in

View Full Version : Help with Displaying Data from database



Feckie
04-09-2009, 04:29 PM
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:


<?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:


<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>

AdrielGreene
04-09-2009, 11:12 PM
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.

$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.

$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.

Feckie
04-10-2009, 07:18 AM
Wow that lost me completly...............:confused:


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.

$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.

$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.

forum_amnesiac
04-14-2009, 12:19 PM
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.