a small guest book

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
siyaco
Forum Commoner
Posts: 26
Joined: Mon Feb 05, 2007 1:36 am
Location: Kurdistan Mountains

a small guest book

Post by siyaco »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i have been writing a small guest book code. first a text box to write and send it to database;

Code: Select all

<html>
<head>
<title>ziyaretci defteri</title>
<body>  <center>
<form name="ziyaretci" action="insert1.php" method="POST">
<p>isminiz : <input type="text" size="20" maxlength="30" name="user"></p>
<p>mesajiniz : <textarea name="message" rows="4" cols="40"></textarea></p>
<p><input type="submit" name="gonder" value="gonder">
</form>



<?php
    $user=$_POST['user'];
    $message=$_POST['message'];
    $gonder=$_POST['gonder'];
    $date=date('Y-n-j');
    
   if($gonder)
   {
 $db=mysql_connect('localhost', 'root', '123456') or die('not connected');
 if($db)

 mysql_select_db('siyabendd') or die('not selected');
 
  // Performing SQL query
$query = "INSERT INTO forum1 VALUES('".$user."', '".$date."', '".$message."')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());



// Closing connection
mysql_close($db);
   }
           
?>
and then browse the messages

Code: Select all

<html>
<head>
<title>ziyaretci defteri</title>
<body>  <center>
<form name="ziyaretci" action="insert1.php" method="POST">
<p>isminiz : <input type="text" size="20" maxlength="30" name="user"></p>
<p>mesajiniz : <textarea name="message" rows="4" cols="40"></textarea></p>
<p><input type="submit" name="gonder" value="gonder">
</form>



<?php
    $user=$_POST['user'];
    $message=$_POST['message'];
    $gonder=$_POST['gonder'];
    $date=date('Y-n-j');
    
   if($gonder)
   {
 $db=mysql_connect('localhost', 'root', '123456') or die('not connected');
 if($db)

 mysql_select_db('siyabendd') or die('not selected');
 
  // Performing SQL query
$query = "INSERT INTO forum1 VALUES('".$user."', '".$date."', '".$message."')";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());



// Closing connection
mysql_close($db);
   }
           
?>

but i have two problems;
1- when the user wants to write his message and enters to go the new line and send the all message is shown in only one line with my second code. so this view is not good. how can i display the message as the user had writen.
2- this is about view of message, too. when the message is too long, it goes to right and a horizantal scroll bar appears. why it doesn't go down a new line at the end of the table.

thanks all in advance


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Try looking at nl2br(). As for the rest, I think it is taking it as a literal string and putting that entire one liner into the database. I think.
Post Reply