Im having a hard time doing this. This is basiclly what I want:
are you trying to do it in flash or no? also, are you going to use a mysql db or text files? preferably you would use a mysql db.
AJAX… Of course it may not be necessary depending on the setup of your site/page.
Have Javascript grab the quote from the text field (and check it). Send it to PHP (or whatever) to get stored into the database (db would be best but you could use a file - text or XML). Then when you get a response that everything went well, put the quote on the page (or show an error if something went wrong).
oh common, u dont need to use AJAX for somthing like that, i think u need to describe what you want better
Flatfile or MySQL?
Depends. If that’s part of a larger page why reload the entire page each time someone submits a quote? Send it via get/post and you’re just reloading the entire page when that’s not necessary - bandwidth gets sucked up when it doesn’t need to. If it’s on a smaller page then yeah, AJAX wouldn’t be needed. But because I don’t know any more details about the set up I was simply offering Crayon-Inc another option. And it’s also why I had put:
Of course it may not be necessary depending on the setup of your site/page.
Either way I’m sure he can manage the front-end the way he’d like it. It’s just the backend that matters, and that’s normally the same ajax or not (probably slight differences, but VERY slight).
Oh and I prefer not to use AJAX, too javascripty
I have acsess to mySQL, so yeahhh flatfile or mySQL would be good =)
I think I have some horrid example of a quote system in flatfile from about a year ago. Let me dig it out.
^
Ok that would be nice…
Anyone else have a clue how to do this?
here’s basically what you need to learn w/php and mysql:
- passing variables to php through an html form
- mysql INSERT queries
- php rand function
- mysql SELECT queries
you can search for those items up the wazoo and find tons of info and tutorials. i would try it first, then post code here if you are having trouble.
I couldn’t find that thing.
I’ll just spell it out for yaa…
In order to submit, you have the form submit a post to a php file. In the php file, accept the variable, do all of your syntax checking to make sure it’s nice and sexy, and if it is, INSERT into the mysql database. When displaying, you can just use the query SELECT * FROM table
ORDER BY rand() LIMIT 1. Then of course display the results.
I’ve decided that I was going to do it flat-file, this is what I’ve started…
<?php
//Get the stuff in the textbox
$add = $_GET['bananaphone'];
//Put it in a var
$entry_line = "$add n";
//Open logs.txt
$fp = fopen("logs.txt", "a");
//Put the stuff in
fputs($fp, $entry_line);
//Close logs.txt
fclose($fp);
?>
^
Did I do anything wrong to that?
bananaphone
Im doing something wrong now…
<form action="randomstart.php" method="post">
Add your quote: <input type="text" name="bananaphone" />
<input type="submit" name="Submit" value="Submit">
When I go to logs.txt it only shows the letter n
Yep. You used POST on the form, and GET in the PHP. Change the GET in the PHP code to POST. Also what’s the purpose of the n, you mean new line? If so that’s
, or
… not just n
^
Forgot the slash… thanks
Lemme test it out
w00t it works… now i need to randomize the stuff and then display the quote… any ideas?
Easy. www.php.net/file
$array = file(“file.txt”);
print $array[rand(0,sizeof($array)-2)];