Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 05-21-2006, 02:18 PM   #11
BSOD
 
MSFanBoy's Avatar
 
Join Date: May 2006
Posts: 190
Default Re: 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 .

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>
&nbsp;&nbsp;&nbsp;
$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.
__________________

MSFanBoy is offline   Reply With Quote
Old 05-21-2006, 06:24 PM   #12
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: Mistake of the Day (Help Please)

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.
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 05-22-2006, 11:11 AM   #13
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Mistake of the Day (Help Please)

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

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>
&nbsp;&nbsp;&nbsp;
$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?
j03 is offline   Reply With Quote
Old 05-22-2006, 12:33 PM   #14
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: Mistake of the Day (Help Please)

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.
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 05-22-2006, 03:01 PM   #15
BSOD
 
MSFanBoy's Avatar
 
Join Date: May 2006
Posts: 190
Default Re: Mistake of the Day (Help Please)

No problem man.
MSFanBoy is offline   Reply With Quote
Old 05-23-2006, 11:24 AM   #16
j03
~~~~~~~~
 
Join Date: Jan 2005
Location: Wales
Posts: 5,556
Send a message via MSN to j03
Default Re: Mistake of the Day (Help Please)

Quote:
Originally Posted by samurai
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
__________________

j03 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 06:02 PM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0