Hi there everyone. I have a form on my webpage that allows visitors to submit a short piece of text to the site, which is then added to a MySQL database. I would like to create/find a script that would automatically create a webpage which would display just that piece of text (ie.: "domain.com/contentid=6546"). I have seen this used on many websites out there and have searched around online but I can't seem to find out how it can be done. Could anyone please point me in the right direction? Regards, GLD
If it gets stored in MySQL with a unique ID you can (simplified): $article_id = $_GET['contentid']; SELECT article from your_table WHERE id = $article_id Echo $article;
Thanks for the quick reply. What I'm actually looking to do though is create a unique webage for each of the users submissions (much like they have at urbandictionary.com, or everything2.com). Every submission will automatically create a page.)
Do you want an actual file created for each submission or something dynamic that uses one file like the above sites and example? -the mole
I was actually looking for something dynamic. My post wasn't very clear - sorry about that. I think T0PS3O's suggestion may have been what I was looking for. I'm trying it now... EDIT: Here is what I'm using, but it's not working. Could anyone please explain why?
name_id is still set to your GET var is probably where you're getting mixed up. Give this a shot: <html> <body> <?php // connect to the server mysql_connect( 'host', 'user', 'password' ) or die( "Error! Could not connect to database: " . mysql_error() ); // select the database mysql_select_db( 'database' ) or die( "Error! Could not select the database: " . mysql_error() ); $name_id = $_GET['contentid']; $query = "SELECT `name` FROM `yourday` WHERE `id` = `$name_id`"; $result= mysql_query( $query ); $row = mysql_fetch_array( $result ); $user_submitted_content = stripslashes( $row['name'] ); echo $user_submitted_content; ?> </body> </html> Code (markup): -the mole
Hmm, I get an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/domain.com/testpage.php on line 20...
mysql_connect( 'host', 'user', 'password' ) <-- did you change those? mysql_select_db( 'database' ) <-- more likely.. did you change this? $query = "SELECT `name` FROM `yourday` WHERE `id` = `$name_id`"; <-- MOST likely... are these correct
Yep I changed host, user, password and database. And yes those are correct. $name_id was defined further up wasn't it? Am I supposed to replace the contentid though? ("$name_id = $_GET['contentid']")
what u can do instead of using databases is to write their text into a text file, surroubd it with whatever html tags you want (maybe ur sites logo) and write it to the web directory
No contentid should be in the URL. With register_globals on http://mysite.com/?contentid=1234 should be fine. Try an object fetch instead.
Thanks for all the help guys - I got it working, to some extent. <html> <body> <?php if ( isset($_GET['contentid']) ): // connect to the server mysql_connect( 'host', 'user, 'password' ) or die( "Error! Could not connect to database: " . mysql_error() ); // select the database mysql_select_db( 'database' ) or die( "Error! Could not select the database: " . mysql_error() ); $query = mysql_query("SELECT * FROM yourday WHERE id=". (int)$_GET['contentid']) or die(mysql_error()); $user_submitted_content = mysql_fetch_object($query); $user_submitted_content = $user_submitted_content->name; $user_submitted_content = stripslashes( $user_submitted_content ); echo $user_submitted_content; else: echo "Default page"; endif; ?> </body> </html> PHP: Problem is: I can't figure out how to output more than a single field (eg: name, and other...). How can I do this?
This line is the key: $user_submitted_content = $user_submitted_content->name; Since you have your query set to SELECT * (Meaning ALL) Just do something like $user_submitted_content1= $user_submitted_content->name; $user_submitted_content2 = $user_submitted_content->address; $user_submitted_content3= $user_submitted_content->phone; $user_submitted_content4 = $user_submitted_content->zip; And echo them accordingly
That's because you are trying to assign the same variable diferent values. Only the last assignment will stick.