X96 Web Design
04-14-2009, 02:18 AM
Hi All,
I want to have a simple two-field form update a table row of two values.
So far it'll read the table, but I can't get it to update the table. I'm pretty new to PHP, but can read it better than I can code it...
I have two pages, the form page (index.php) and the output (page.php), index.php holds the form, and posts the form data to page.php.
page.php holds the following: (I removed the username/password from this post)
<?php
$con = mysql_connect("localhost","My Username","My Password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("learningphp_cms", $con);
?>
<?php
$result = mysql_query("SELECT * FROM page1");
$chickenpie = mysql_query("SELECT title FROM page1");
$beefstew = mysql_query("SELECT bodytext FROM page1");
while($row = mysql_fetch_array($result))
{
echo "<h1>" . $row['title'] . "</h1> <p>" . $row['bodytext'] . "</p>";
echo "<br />";
}
$sql = 'UPDATE `my database`.`page1` SET `title` = $_POST[\'title\'], `bodytext` = $_POST[\'bodytext\'] WHERE CONVERT(`page1`.`title` USING utf8) = mysql_fetch_array($chickenpie) AND CONVERT(`page1`.`bodytext` USING utf8) = mysql_fetch_array($beefstew) LIMIT 1;';
?>
And index.php holds this: (I removed the styles)
<form action="page.php" method="post">
<h1>Website Title</h1>
<input type="text" name="title" /><br/><br/>
<h1>Site Content (Body Text)</h1>
<textarea name="bodytext"></textarea><br/>
<input type="submit" value="Update Page" name="submit" style="font-size:25px; padding:0 10px 0 10px;" />
</form>
If anyone could help, it would be greatly appreciated!
Thanks,
<X96 Web Design>
I want to have a simple two-field form update a table row of two values.
So far it'll read the table, but I can't get it to update the table. I'm pretty new to PHP, but can read it better than I can code it...
I have two pages, the form page (index.php) and the output (page.php), index.php holds the form, and posts the form data to page.php.
page.php holds the following: (I removed the username/password from this post)
<?php
$con = mysql_connect("localhost","My Username","My Password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("learningphp_cms", $con);
?>
<?php
$result = mysql_query("SELECT * FROM page1");
$chickenpie = mysql_query("SELECT title FROM page1");
$beefstew = mysql_query("SELECT bodytext FROM page1");
while($row = mysql_fetch_array($result))
{
echo "<h1>" . $row['title'] . "</h1> <p>" . $row['bodytext'] . "</p>";
echo "<br />";
}
$sql = 'UPDATE `my database`.`page1` SET `title` = $_POST[\'title\'], `bodytext` = $_POST[\'bodytext\'] WHERE CONVERT(`page1`.`title` USING utf8) = mysql_fetch_array($chickenpie) AND CONVERT(`page1`.`bodytext` USING utf8) = mysql_fetch_array($beefstew) LIMIT 1;';
?>
And index.php holds this: (I removed the styles)
<form action="page.php" method="post">
<h1>Website Title</h1>
<input type="text" name="title" /><br/><br/>
<h1>Site Content (Body Text)</h1>
<textarea name="bodytext"></textarea><br/>
<input type="submit" value="Update Page" name="submit" style="font-size:25px; padding:0 10px 0 10px;" />
</form>
If anyone could help, it would be greatly appreciated!
Thanks,
<X96 Web Design>