textbox for members only

Started on the old forum in December 2011 · view the original in the archive · old links redirect here

2 replies · 958 views · started 14 years ago · 1 min read

2 participants
miic8310 Junior · 36 posts #1

hi ive got a register/login part completed. i basically want to create a site where you can log in, write a post and log back out (twitter style). ive got a textbox with button but cannot work out how to make the text in the box show up somewhere and how to link the sql to it. i know this is quite basic lol but ive been searching for a while on google 🙁

thanks

miic8310 Junior · 36 posts #2

have found this but when the site is loaded i get an error

message; ?> Posted by name; ?> on newdate; ?>

Post a message

Name:

Your message:

and when press the send button get... The requested URL /< was not found on this server.

mysite.co.uk/<?php echo $_SERVER['REQUEST_URI']; ?>

anyone know what i need to do???

thanks

<?php /** * Create the table in your MySQL database: * * CREATE TABLE 'guests' ( * 'id' int(10) NOT NULL auto_increment, * 'name' varchar(50) NOT NULL, * 'message' varchar(255) NOT NULL, * 'date' timestamp(14) NOT NULL, * PRIMARY KEY ('id') , * ); * * Change the database login settings to your own * * The script is now ready to run */ // Change these to your own database settings $host = "localhost"; $user = "user"; $pass = "pass"; $db = "db"; mysql_connect($host, $user, $pass) OR die ("Could not connect to the server."); mysql_select_db($db) OR die("Could not connect to the database."); $name = stripslashes($_POST['txtName']); $message = stripslashes($_POST['txtMessage']); if (!isset($_POST['txtName'])) { $query = "SELECT id, name, message, DATE_FORMAT(date, '%D %M, %Y @ %H:%i') as newdate FROM guests ORDER BY id DESC"; $result = mysql_query($query); while ($row = mysql_fetch_object($result)) { ?> <?php echo $row->message; ?>

Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?>

<?php } ?>

Post a message

<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">

<label for="txtName">Name:</label>

<input type="text" title="Enter your name" name="txtName" />

<label for="txtMessage">Your message:</label>

<textarea title="Enter your message" name="txtMessage"></textarea>
<label title="Send your message"> <input type="submit" value="Send" /></label> </form> <?php } else { // Adds the new entry to the database $query = "INSERT INTO guests SET message='$message', name='$name', date=NOW()"; $result = mysql_query($query); // Takes us back to the entries $ref = $_SERVER['HTTP_REFERER']; header ("Location: $ref"); } ?>
arnage Lead · 811 posts #3

You need to point the <form> to the processing page, $_SERVER['REQUEST_URI'] should be changed.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close