Populating MySQL Data in my webpage
Posted: Sat Apr 24, 2010 9:12 pm
OK, hopefully someone here is able to help. I have a table with the following columns: tag, message, and date.
Right now, I have successfully setup a script that will:
A) Find record(s) matching the 'tag' when entered into a form
B) Insert a new record using a form.
What I would like to do is to know how to setup my page so that it will pull data from the SQL table and fill it into an HTML table so I can style the page properly. (I will be creating an iPhone webapp and would like to show the messages that match the 'tag' entered to show up in a table where a user will be able to click it to view more details.)
Any help would be greatly appreciated...and I have attached my code below:
Index.html
Search.php
insert.php
Right now, I have successfully setup a script that will:
A) Find record(s) matching the 'tag' when entered into a form
B) Insert a new record using a form.
What I would like to do is to know how to setup my page so that it will pull data from the SQL table and fill it into an HTML table so I can style the page properly. (I will be creating an iPhone webapp and would like to show the messages that match the 'tag' entered to show up in a table where a user will be able to click it to view more details.)
Any help would be greatly appreciated...and I have attached my code below:
Index.html
Code: Select all
<html>
<head>
<title>Check Your Tag</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#333" style="color:white;">
<div id="container">
<table width="100%" border="0" align="center">
<tr>
<td width="50%">Use the search form below to see if anybody has left a message for your license plate! </td>
<td width="50%">Use the form below to send a message to a license plate that you saw on the road:</td>
</tr>
<tr>
<td><div align="center" id="checkmessages"><form action="search.php" method="post">
Search:
<input type="text" name="term" />
<br />
<input type="submit" name="submit" value="Submit" />
</form></div></td>
<td><div align="center" id="sendmessage"><form action="insert.php" method="post">
License Plate:
<input type="text" name="tag" />
Message:
<input type="text" name="message" />
<input type="submit" />
</form></div></td>
</tr>
</table>
<p></p>
</div>
</body>
</html>
Code: Select all
<?php
mysql_connect ("localhost", "text_tag","qivbz7d6") or die (mysql_error());
mysql_select_db ("text_tag");
$term = $_POST['term'];
$sql = mysql_query("select * from testtable where tag like '$term'");
while ($row = mysql_fetch_array($sql)){
echo 'Your Tag: '.$row['tag'];
echo '<br/> Message: '.$row['message'];
echo '<br/><br/>';
}
?>
Code: Select all
<?php
$con = mysql_connect("localhost","text_tag","qivbz7d6");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("text_tag", $con);
$sql="INSERT INTO testtable (tag, message)
VALUES
('$_POST[tag]','$_POST[message]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Your message has been sent";
mysql_close($con)
?>