unre4l
-
Posts
2 -
Joined
-
Last visited
Never
Posts posted by unre4l
-
-
Hey,
I'm trying to make a schedule that can be updated on one page and then displayed on another. The only problem is the code for the update page isnt actually updating the sql database...
Could anyone take a look at this code and see where the problems are. (I'm new to php so ya)
<?
include("config.php");
if (!$_POST[update])
{
$schedule = mysql_query("SELECT * from schedule where day='Monday'");
$schedule = mysql_fetch_array($schedule);
echo("
<center><form method=\"POST\">
<table width=499>
<tr>
<td align=\"right\" width=\"25%\">
12am - 1am</td><td align=\"left\">
<input size=\"25\" name=\"twelveam\" value=\"$schedule[twelveam]\"></td>
</tr>
Lots more like this, removed them for space
<td align=\"right\" width=\"25%\">
11pm - 12am</td>
<td align=\"left\">
<input size=\"25\" name=\"elevenpm\" value=\"$schedule[elevenpm]\"></td>
</tr>
<tr>
<td align=\"center\">
</td>
<td align=\"left\">
<input type=\"submit\" name=\"update\" value=\"Update\"></td>
</tr>
</table>
</form>
</center>");
}
else
{
$twelveam = htmlspecialchars($_POST[twelveam]);
$oneam = htmlspecialchars($_POST[oneam]);
$twoam = htmlspecialchars($_POST[twoam]);
$threeam = htmlspecialchars($_POST[threeam]);
echo ("Monday has been updated.");
$update = mysql_query("update schedule set twelveam = '$twelveam',
oneam = '$oneam', twoam = '$twoam', threeam = '$threeam', fouram = '$fouram', fiveam = '$fiveam', sixam = '$sixam', sevenam = '$sevenam', eightam = '$eightam', nineam = '$nineam', tenam = '$tenam', elevenam = '$elevenam', twelvepm = '$twelvepm', onepm = '$onepm', twopm = '$twopm', threepm = '$threepm', fourpm = '$fourpm', fivepm = '$fivepm', sixpm = '$sixpm', sevenpm = '$sevenpm', eightpm = '$eightpm', ninepm = '$ninepm', tenpm = '$tenpm', elevenpm = '$elevenpm' where day = 'Monday'");
}
}
else
{
// They aren't logged in!
echo ("<a href=\"login.php\">You must login</a>");
}
?>
Hope someone can help.
Cheers
Update mysql via php form
in PHP Coding Help
Posted
The new version doesnt connect to the database at all, so it wont be able to update it.
I'd have two pages, the one to show the information from the mysql database and the one to update the database information.
One would be a form that when you submit the form data it replaces the mysql record information with the updated version. Thats what the html form was for.