Mistake of the Day (Help Please)

Hate to double post, but I worked on this mistake of the day script using mysql for quite a few minutes :p.

If you do decide to use mysql here is the query you will use:

Code:
CREATE TABLE mistakes (  
           id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,  
           name VARCHAR(255) NOT NULL,  
           mistake VARCHAR(255) NOT NULL,   
           userip VARCHAR(255) NOT NULL,  
           datesub VARCHAR(255) NOT NULL 
           )  
           TYPE = myisam;

Use this file called submit_mistake.php:

Code:
<?php

// This file will insert the data entered in the fields to the database

// Connect to database

$host = "localhost";
$dbuser = "";
$dbpass = "";
$dbname = "";

mysql_connect($host, $dbuser, $dbpass) or die('Error connecting to the database');
mysql_select_db($dbname) or die('Could not select database');

// If the submit button is pushed

if(isset($_POST['submit'])) {

// POST Variables

$name = $_POST['name'];

$mistake = $_POST['mistake'];

$datesub = $_POST['datesub'];

$userip = $_POST['userip'];
// I added IP just so if anyone spams you, you can IP ban them

$query = mysql_query("INSERT INTO `mistakes` ( `name`, `mistake`, `datesub`, `userip` ) VALUES ('$name', '$mistake', '$datesub', '$userip');");

}

?>

<form action="" method="POST">
	Name:<input type="text" name="name" value="$name" />
<br />
	Your Mistake:<input type="text" name="mistake" value="$mistake" />
<input type="hidden" name="datesub" value="<?php echo date('m/d/Y'); ?>" />
<input type="hidden" name="userip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
<Br />
	<input type="submit" name="submit" value="Submit" />

And this file called mistakes.php:

Code:
<?php

// Connect to database

$host = "localhost";
$dbuser = "";
$dbpass = "";
$dbname = "";

mysql_connect($host, $dbuser, $dbpass) or die('Error connecting to the database');
mysql_select_db($dbname) or die('Could not select database');

// Mistakes file to retrieve the data from the database

$query = "SELECT * FROM mistakes ORDER BY id DESC";

$result = mysql_query($query) or die('Could not retrieve the information from the database');
if(mysql_num_rows($result) == 0){
echo("There are no mistakes yet!");
}

while($query=mysql_fetch_array($result)){
extract($query);

echo "
<b>$name</b> - $datesub
<BR>
   
$mistake
<BR><BR><BR>
";

} 

?>

It is all tested and works fine, it displays it like this:
John - 5/21/2006
My mistake was I forgot to flush.
 
indeed, using a database is a lot better, but there are a few things that a database can't be used for... (this isn't one of them though)...

Do you have error reporting turned on, and do you know what the error is?
I'd guess it's most likely that the webserver is not allowed to write files into the data directory,

so, I suggest that you create a directory called data, and have the web server have read and write permissions over that directory, then store the data there.
 
MSFanBoy said:
Hate to double post, but I worked on this mistake of the day script using mysql for quite a few minutes :p.

If you do decide to use mysql here is the query you will use:

Code:
CREATE TABLE mistakes (  
           id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,  
           name VARCHAR(255) NOT NULL,  
           mistake VARCHAR(255) NOT NULL,   
           userip VARCHAR(255) NOT NULL,  
           datesub VARCHAR(255) NOT NULL 
           )  
           TYPE = myisam;

Use this file called submit_mistake.php:

Code:
<?php

// This file will insert the data entered in the fields to the database

// Connect to database

$host = "localhost";
$dbuser = "";
$dbpass = "";
$dbname = "";

mysql_connect($host, $dbuser, $dbpass) or die('Error connecting to the database');
mysql_select_db($dbname) or die('Could not select database');

// If the submit button is pushed

if(isset($_POST['submit'])) {

// POST Variables

$name = $_POST['name'];

$mistake = $_POST['mistake'];

$datesub = $_POST['datesub'];

$userip = $_POST['userip'];
// I added IP just so if anyone spams you, you can IP ban them

$query = mysql_query("INSERT INTO `mistakes` ( `name`, `mistake`, `datesub`, `userip` ) VALUES ('$name', '$mistake', '$datesub', '$userip');");

}

?>

<form action="" method="POST">
	Name:<input type="text" name="name" value="$name" />
<br />
	Your Mistake:<input type="text" name="mistake" value="$mistake" />
<input type="hidden" name="datesub" value="<?php echo date('m/d/Y'); ?>" />
<input type="hidden" name="userip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
<Br />
	<input type="submit" name="submit" value="Submit" />

And this file called mistakes.php:

Code:
<?php

// Connect to database

$host = "localhost";
$dbuser = "";
$dbpass = "";
$dbname = "";

mysql_connect($host, $dbuser, $dbpass) or die('Error connecting to the database');
mysql_select_db($dbname) or die('Could not select database');

// Mistakes file to retrieve the data from the database

$query = "SELECT * FROM mistakes ORDER BY id DESC";

$result = mysql_query($query) or die('Could not retrieve the information from the database');
if(mysql_num_rows($result) == 0){
echo("There are no mistakes yet!");
}

while($query=mysql_fetch_array($result)){
extract($query);

echo "
<b>$name</b> - $datesub
<BR>
   
$mistake
<BR><BR><BR>
";

} 

?>

It is all tested and works fine, it displays it like this:
John - 5/21/2006
My mistake was I forgot to flush.

Oh my god i love you guys! You are lotsandlotsandlots of help! I will installify it now, and tell you if it worked in a few mins! Thanks soooooo much! In the future, i am planning to add a comments system and a "pagination" Thing. I am not in a rush for that, i am off to tutorialized.com now. Anyway, what do you think of the idea for "Mistake of the Day?" Lol!

-edit-
I have installed it, but.... IT WORKS! Yay! http://www.joesstuff.co.uk/submit_mistake.php! I am gonna "Implement" It into my website theme thing now, Ciao all! Bye for now!

-edit-

Is there any way of m,aking it so the textbox does not say $name and $mistake in it?
 
yes.
Code:
<form action="" method="POST">
	Name:<input type="text" name="name" value="$name" />
<br />
	Your Mistake:<input type="text" name="mistake" value="$mistake" />
<input type="hidden" name="datesub" value="<?php echo date('m/d/Y'); ?>" />
<input type="hidden" name="userip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
<Br />
	<input type="submit" name="submit" value="Submit" />

needs to be

Code:
<form action="" method="POST">
	Name:<input type="text" name="name"  />
<br />
	Your Mistake:<input type="text" name="mistake"  />
<input type="hidden" name="datesub" value="<?php echo date('m/d/Y'); ?>" />
<input type="hidden" name="userip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" />
<Br />
	<input type="submit" name="submit" value="Submit" />

or you could just change the value on the form elements rather than just getting rid of the value.
 
samurai said:
Is there any way of m,aking it so the textbox does not say $name and $mistake in it?

Its okay now - I have fixed it. Iwas a newb question anyway :)
 
Back
Top Bottom