hi, i cant get my html table to display the new contents of my database table when i update it. i dont think my script is updating the database table either. any help or advice greatly appreciated. thank you. derek
here is the db connection script
Code:
<?php
////////////////////////////////////////
/// connect to database
////////////////////////////////////////
/// include file
$host = "localhost";
$database = "php_lessons";
$username = "root";
$password = "";
mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error());
mysql_select_db($database);
?>
here are the entire contents of the php script. at the top it inserts data into the table, or is supposed to, below that it is supposed to output the new contents of the table., and below that is the form i use to update the contents of the table.
Code:
<?php
include("connections.php");
////////////////////////////////////////
////////////////////////////////////////
/// query db and loop through rows example
$field2 = $_POST['data2'];
$field3 = $_POST['data3'];
$field4 = $_POST['data4'];
$field5 = $_POST['data5'];
$field6 = $_POST['data6'];
if($field2 && $field3 && $field4){
mysql_query("INSERT INTO table1 (field2,field3,field4,field5,field6)VALUES('$field2','$field3','$field4','$field5','$field6')");
}else{
}
//////////////////////////////////////////////////////////output data into a table///////////////////////////////
$query = mysql_query("SELECT * FROM table1");
$table = "<table width=\"40%\" border=\"1\">
<tr>
<td>heading1</td>
<td>heading2</td>
<td>heading3</td>
<td>heading4</td>
<td>heading5</td>
<td>heading6</td>
</tr>";
while($row = mysql_fetch_array($query)){
$table .= " <tr>
<td>".$row['record_id']."</td>
<td>".$row['field2']."</td>
<td>".$row['field3']."</td>
<td>".$row['field4']."</td>
<td>".$row['field5']."</td>
<td>".$row['field6']."</td>
</tr>";
}
$table .= "</table>";
echo $table;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insert Statement</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="lesson8_test.php">
<table width="31%" border="0">
<tr>
<td width="32%">Data2</td>
<td width="68%"><input name="data2" type="text" id="data2" /></td>
</tr>
<tr>
<td>Data3</td>
<td><input name="data3" type="text" id="data3" /></td>
</tr>
<tr>
<td>Data4</td>
<td><input name="data4" type="text" id="data4" /></td>
</tr>
<tr>
<td>Data5</td>
<td><input name="data5" type="text" id="data5" /></td>
</tr>
<tr>
<td>Data6</td>
<td><input name="data6" type="text" id="data6" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>
|