Jump to content

Creating a direct edit form


fdmagazine

Recommended Posts

I want to setup a form that will put the field data directly into a webpage.  I figure the script I need is similar to a forum script, but I can't seem to find a good one.  Plus, the tutorials on forums at phpfreaks have been removed.

 

The idea is to allow users of the site who are not code-savvy (or do not have Dreamweaver) to contribute (ironically the name of the software that allows this).  Any ideas?

 

Thanks in advance,

Jon

Link to comment
https://forums.phpfreaks.com/topic/64142-creating-a-direct-edit-form/
Share on other sites

It sounds like you want to have a running thread going? So one user posts something and then when the next guy posts something it shows under the other guys?

 

You probably want to set up an sql database and store the posts in there, then read the sql to display them on your page.

Basically u could create two pages, one ex. view.php and the other post.php. In view.php u could show all the posts and in post.php u could have a submit form.

 

view.php

<?php
$query = @mysql_query("SELECT * FROM posts") or die(mysql_error());
while($values = mysql_fetch_array($query)){
echo "Posted by: " . $values['user'] . "<br />";
echo "Message: " . $values['text'];
}
?>

 

post.php

<form name="form1" method="post" action="">
  <input type="text" name="user" />
  <input type="text" name="message" />
  <input type="button" name="submit" value="Add" />
</form>

<?php
if(array_key_exists('text', $_POST)){
$user = mysql_real_escape_string($_POST['user']);
$message = mysql_real_escape_string($_POST['message']);
$date = date('m-d-y H:i:s');
if($user != "" and $message != ""){
	$queryAdd = @mysql_query("INSERT INTO posts (user, message, date) VALUES('$user', '$message', '$date')") or die(mysql_error());
	echo "Thank you for your time";
	echo "<a href=\"view.php\">Return to View.php</a>";
} else{
	echo "Please fill in all the fields";
}
}
?>

 

And u may have a database with fields like: user, message, date.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.