Steven Vona
asked on
PHP database help
I am writing a little php script just to learn php and mysql a little bit. The code is attached below, for some reason it is not writing to the database. Any help would be appreciated.
Database resides on the same machine, and all database user permissions are correct. I long log into mysql command line and add to the database as this user.
Database resides on the same machine, and all database user permissions are correct. I long log into mysql command line and add to the database as this user.
<?php
$usr = "dailystat";
$pwd = "okaydokay";
$db = "statrepo";
$host = "localhost";
// connect to database
$cid = mysql_connect($host,$usr,$pwd);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
?>
<html>
<head>
<title>Vona Daily Status Repository</title>
</head>
<body bgcolor="#ffffff">
<p><font size=5><b> Add a status... </b> </font></p>
<?php
// this is processed when the form is submitted
// back on to this page (POST METHOD)
if ($_SERVER['$REQUEST_METHOD'] == 'POST') {
// double-up apostrophes
// $stat1 = str_replace("'","''",$stat1);
// $stat2 = str_replace("'","''",$stat2);
// $stat3 = str_replace("'","''",$stat3);
// $stat4 = str_replace("'","''",$stat4);
// $stat5 = str_replace("'","''",$stat5);
// $stat6 = str_replace("'","''",$stat6);
$stat1 = $_POST['stat1'];
$stat2 = $_POST['stat2'];
$stat3 = $_POST['stat3'];
$stat4 = $_POST['stat4'];
$stat5 = $_POST['stat5'];
$stat6 = $_POST['stat6'];
echo ( $stat1 );
// setup SQL statement
$SQL = " INSERT INTO dailyupdate (stat1,stat2,stat3,stat4,stat5,stat6) VALUES ('$stat1','$stat2','$stat3','$stat4,'$stat5','$stat6') ";
//execute SQL statement
$result = mysql_db_query($db,"$SQL",$cid);
// check for error
if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); }
echo ("<p><b>New Status Added</b></p>\n");
}
?>
<form name="fa" action="insert_status.php" method="post">
<table>
<tr><td valign=top><b>Status Update #1: </b> </td><td> <textarea name="stat1" rows=5 cols=100></textarea></td></tr>
<tr><td valign=top><b>Status Update #2: </b> </td><td> <textarea name="stat2" rows=5 cols=100></textarea></td></tr>
<tr><td valign=top><b>Status Update #3: </b> </td><td> <textarea name="stat3" rows=5 cols=100></textarea></td></tr>
<tr><td valign=top><b>Status Update #4: </b> </td><td> <textarea name="stat4" rows=5 cols=100></textarea></td></tr>
<tr><td valign=top><b>Status Update #5: </b> </td><td> <textarea name="stat5" rows=5 cols=100></textarea></td></tr>
<tr><td valign=top><b>Status Update #6: </b> </td><td> <textarea name="stat6" rows=5 cols=100></textarea></td></tr>
<tr><th colspan=2><p><input type="submit" value="Add Updates to DB"></p></th></tr>
</table>
</form>
<?php
mysql_close($cid);
?>
</body>
</html>
What the error, if any?
This page http://us3.php.net/manual/en/function.mysql-db-query.php recommends a different way of doing that.
Are you getting an error messages? To make sure you see any errors, put the code below at the top of your PHP code.
Are you getting an error messages? To make sure you see any errors, put the code below at the top of your PHP code.
// Report all PHP errors
error_reporting(E_ALL);
ASKER
This is the error I am getting in the httpd error log:
PHP Notice: Undefined index: $REQUEST_METHOD in /var/www/html/insert_statu s.php on line 23, referer: http://localhost/insert_status.php
If I remove the following if statement the database is updated fine.
if ($_SERVER['$REQUEST_METHOD '] == 'POST') {
PHP Notice: Undefined index: $REQUEST_METHOD in /var/www/html/insert_statu
If I remove the following if statement the database is updated fine.
if ($_SERVER['$REQUEST_METHOD
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works like a charm now!
Good, glad to help.