Using a HTML form and a PHP script to save an avarage number
Posted: Fri Dec 31, 2010 6:49 pm
Hello! I am new here but I am hoping that this forum could be friendly and help me.
I am trying to create a rating system that would start with a page where some one would enter in the name of the person they were rating and use methode=post to send into a SQL database. Now my main problems with this is that I don't want 150 of the same username over and over and over again, but I cant figure out how to get it to decide weather to create a new database entry or just add the next one. I also want to add a comment system at some point and I was wondering if it was possible.
I would also be willing to use a way that it could save to a regular HTML Page too. (I might like that idea more actually)
Here is the code I have so far
Then just the empty HTML file
I am trying to create a rating system that would start with a page where some one would enter in the name of the person they were rating and use methode=post to send into a SQL database. Now my main problems with this is that I don't want 150 of the same username over and over and over again, but I cant figure out how to get it to decide weather to create a new database entry or just add the next one. I also want to add a comment system at some point and I was wondering if it was possible.
I would also be willing to use a way that it could save to a regular HTML Page too. (I might like that idea more actually)
Here is the code I have so far
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Sign-up Page</title>
</head>
<body>
<center><h1 style="font-family:arial;color:red;"> Give feedback!</h1>
<center><p style="font-family:arial"> I don't know if I can merge these users onto the next version of the site but I want to get somthing up now. So if you sign up there are no garuntees that you wont have to do this again. Basicly what this current script is doing is saving to a .txt but I can get it to retrive from there. So I am going to make the next script organize the users based on the information already in the text file.</p>
<br />
<center><a href="users.txt"> The results! Comments coming soon too!</a></center>
<form name="input" method="post" action="signup.php">
Username of seller (this field must be exact!): <input type="text" name="firstname" /><br />
<p>Rating</p>
<br />
<input type="radio" name="rating" value="1"/> 1 out of 10<br />
<input type="radio" name="rating" value="2"/> 2 out of 10<br />
<input type="radio" name="rating" value="3"/> 3 out of 10<br />
<input type="radio" name="rating" value="4"/> 4 out of 10<br />
<input type="radio" name="rating" value="5"/> 5 out of 10<br />
<input type="radio" name="rating" value="6"/> 6 out of 10<br />
<input type="radio" name="rating" value="7"/> 7 out of 10<br />
<input type="radio" name="rating" value="8"/> 8 out of 10<br />
<input type="radio" name="rating" value="9"/> 9 out of 10<br />
<input type="radio" name="rating" value="10"/> 10 out of 10<br />
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
Code: Select all
<?php
$firstname = $_POST['firstname'];
$rating = $_POST['rating'];
//the data
$data = "$firstname\r\n | $rating\r\n";
//open the file and choose the mode
$fh = fopen("users.html", "a");
if
fwrite($fh, $data);
//close the file
fclose($fh);
print "User Submitted...hopefully";
?>