Web Development



PHP/MySql function not working. Cant figure out why!

By grady ·
[pre]I am using several functions to manage content on my pages. They all work but these two. The function terms() builds the page properly but updterms() doesn't even try to run. Also, there is another submit button named 'back' that works fine in every other function on the site but not this one.

Thanks in advance for your help.

Here's the function that builds the page:

function terms($_POST) {
$query = 'SELECT terms FROM content';
$result = mysql_query($query);
$row = mysql_fetch_assoc($result);
echo "<div class='content'>";
echo "<form action='contentmgmt.php' method='post'>";
echo "<b>Terms and Conditions Text:</b><br />";
echo "<textarea name='terms' cols='88' rows='12'>".$row['terms']."</textarea><br /><br />";
echo "<input type='submit' name='updterms' value='Save Changes' /><input type='submit' name='back' value='Cancel' />";
echo "</form>";
echo "</div>";

And here's the function that processes it:

function updterms($_POST) {
$query = "UPDATE content SET terms='".$_POST['terms']."'";
$result = mysql_query($query);
header("Location: http://localhost/admin/adminpage.php");

Here are the switch statements I am using:

switch($_POST) {
case isset($_POST['terms']):
case isset($_POST['updterms']):

You can see in updterms() that the expected behavior is to update a database row and then send header information. All that happens is the current page (the terms() page) reloads.[/pre]

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Just a random guess but....

by robo_dev In reply to PHP/MySql function not wo ...

does it fail any differently if you do a REQUIRE for dbconn instead of an Include?
<? require(?dbconn.php?); ?>

Also, with dbconn, shouldnt your query be:

Not sure it matters, but tick versus quote may be part of the issue.

'SELECT terms FROM content'; verus
"SELECT terms FROM content"; are not the same, afaik.


BTW, if you get sick of coding stuff like this, there is a cool tool I've used called PHP-maker. They also make ASP-Maker, ASP.NET maker, etc. It does all the db connection stuff and builds pages instantly and automatically...and it's dirt cheap. I've build gobs of ASPmaker pages....it's sooooo cool..saved me 500 hours work, easy.


Related Discussions

Related Forums