PDA

View Full Version : Any help with guestbook?



auriaks
08-08-2009, 12:32 PM
I have problems with information which i want to receive...
It must show messages posted before, but it doesnt.
Can you tell me whats wrong??


<?php

echo "<h1>Guestbook</h1><hr>";

//connect to the database
$connect = mysql_connect("server","aur","king") or die("Error connecting to db");
//select table
mysql_select_db("phpacademy") or die("Error selecting db");

//use query to get ALL data
$queryget = mysql_query("SELECT * FROM guestbook") or die("Error with query");

while ($row = mysql_fetch_assoc($querryget))
{
// get row data and store in variables
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$message = $row['message'];
$date = $row['date'];
$time = $row['time'];

// show data to user
echo "
<table>
<tr>
<td>
<b>Posted by $name ($email) on $date and $time</b>
</td>
</tr>
<tr>
<td>
".n12br(strip_tags($message))."
</td>
</tr>
</table>
";
}

echo "<hr>";

if ($_POST['submit'])
{

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$date = date("Y-m-d");
$time = date("H:i:s");

if ($name&&$email&&$message)
{

$querypost = mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')");
echo "Please wait...<meta http-equiv='refresh' content='2'>";

}
else
echo "Please fill out all fields!";


}

echo "
<form action='guestbook.php' method='POST'>
<table width='100%'>
<tr>
<td width='17%' valign='top'>
Your name:
</td>
<td>
<input type='text' name='name' maxlenght='25'>
</td>
</tr>

<tr>
<td valign='top'>
Your email:
</td>
<td>
<input type='text' name='email' maxlenght='35'>
</td>
</tr>

<tr>
<td valign='top'>
Your message:
</td>
<td>
<textarea cols='20' rows='2' name='message' maxlenght='250'></textarea>
<p>
<input type='submit' value='Post'>
</td>
</tr>
</table>
</form>
";

?>
login and pass changed

bluewalrus
08-08-2009, 01:24 PM
I've never used that n12br but a google says its nl not 1 nl2br(); so try this out. I fiddled with the formatting of some things to you can swap that if you dont link but i think you'll end up with a lot of tables the way you had it






<h1>Guestbook</h1><hr>
<?php
//connect to the database
$connect = mysql_connect("server","aur","king") or die("Error connecting to db");
//select table
mysql_select_db("phpacademy") or die("Error selecting db");

//use query to get ALL data
$queryget = mysql_query("SELECT * FROM guestbook") or die("Error with query");
?>
<table>
<tr>
<td><strong>Posted by</strong><td><strong>On</strong></td><td><strong>Message</strong></td></tr>
<?php

while ($row = mysql_fetch_assoc($querryget))
{
// get row data and store in variables
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$message = $row['message'];
$date = $row['date'];
$time = $row['time'];

// show data to user
?>
<tr>
<td><?php echo $name . "(" . $email .")"; ?></td>
<td><?php echo $date; ?><?php echo $time; ?></td>
<td><?php nl2br(strip_tags($message)); ?></td>
</tr>
<?php
}
?>
</table>
<hr>
<?php
if ($_POST['submit'])
{

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$date = date("Y-m-d");
$time = date("H:i:s");

if ($name&&$email&&$message)
{

$querypost = mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')");
echo "Please wait...<meta http-equiv='refresh' content='2'>";

}
else
echo "Please fill out all fields!";


}
?>
<form action='guestbook.php' method='POST'>
<table width='100%'>
<tr>
<td width='17%' valign='top'>
Your name:
</td>
<td>
<input type='text' name='name' maxlenght='25'>
</td>
</tr>

<tr>
<td valign='top'>
Your email:
</td>
<td>
<input type='text' name='email' maxlenght='35'>
</td>
</tr>

<tr>
<td valign='top'>
Your message:
</td>
<td>
<textarea cols='20' rows='2' name='message' maxlenght='250'></textarea>
<p>
<input type='submit' value='Post'>
</td>
</tr>
</table>
</form>

auriaks
08-08-2009, 02:59 PM
But this line just apears between two lines... nothing changed. I still cant see my messages.


<table>
<tr>
<td><strong>Posted by</strong><td><strong>On</strong></td><td><strong>Message</strong></td></tr>

bluewalrus
08-09-2009, 07:15 AM
Opps my mistake forgot to close a cell

<td><strong>Posted by</strong></td>
<td><strong>On</strong></td>
<td><strong>Message</strong></td></tr>

What does it display nothing this with blank info or an error? Is there a link?

auriaks
08-09-2009, 10:43 AM
Opps my mistake forgot to close a cell

<td><strong>Posted by</strong></td>
<td><strong>On</strong></td>
<td><strong>Message</strong></td></tr>

What does it display nothing this with blank info or an error? Is there a link?

it desplays a line of words: Posted by On Message... but i need a message from mySQL.

JShor
08-09-2009, 03:42 PM
You misspelled the variable $querryget. Your calling var is named $queryget with 1 "r" and the other is $querryget w/2 "r"s.

Additionally, mysql_fetch_assoc(); will only return a specified row. Since none is specified, use mysql_fetch_array(); instead.



<?php

echo "<h1>Guestbook</h1><hr>";

//connect to the database
$connect = mysql_connect("server","aur","king") or die("Error connecting to db");
//select table
mysql_select_db("phpacademy") or die("Error selecting db");

//use query to get ALL data
$queryget = mysql_query("SELECT * FROM guestbook") or die("Error with query");

while ($row = mysql_fetch_array($queryget))
{
// get row data and store in variables
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$message = $row['message'];
$date = $row['date'];
$time = $row['time'];

// show data to user
echo "
<table>
<tr>
<td>
<b>Posted by $name ($email) on $date and $time</b>
</td>
</tr>
<tr>
<td>
".n12br(strip_tags($message))."
</td>
</tr>
</table>
";
}

echo "<hr>";

if ($_POST['submit'])
{

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$date = date("Y-m-d");
$time = date("H:i:s");

if ($name&&$email&&$message)
{

$querypost = mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')");
echo "Please wait...<meta http-equiv='refresh' content='2'>";

}
else
echo "Please fill out all fields!";


}

echo "
<form action='guestbook.php' method='POST'>
<table width='100%'>
<tr>
<td width='17%' valign='top'>
Your name:
</td>
<td>
<input type='text' name='name' maxlenght='25'>
</td>
</tr>

<tr>
<td valign='top'>
Your email:
</td>
<td>
<input type='text' name='email' maxlenght='35'>
</td>
</tr>

<tr>
<td valign='top'>
Your message:
</td>
<td>
<textarea cols='20' rows='2' name='message' maxlenght='250'></textarea>
<p>
<input type='submit' value='Post'>
</td>
</tr>
</table>
</form>
";

?>


HTH:)

auriaks
08-10-2009, 01:33 AM
JShor, now i can see my msges :D thanks to you... but still one problem, i cant add posts.

JShor
08-10-2009, 01:45 PM
$_POST['submit'] wasn't declared in your button function. So the if..else statement becomes invalidated, which means the SQL query won't run. You need to add the name="submit". Here's the fixed code:



<?php

echo "<h1>Guestbook</h1><hr>";

//connect to the database
$connect = mysql_connect("server","aur","king") or die("Error connecting to db");
//select table
mysql_select_db("phpacademy") or die("Error selecting db");

//use query to get ALL data
$queryget = mysql_query("SELECT * FROM guestbook") or die("Error with query");

while ($row = mysql_fetch_array($queryget))
{
// get row data and store in variables
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$message = $row['message'];
$date = $row['date'];
$time = $row['time'];

// show data to user
echo "
<table>
<tr>
<td>
<b>Posted by $name ($email) on $date and $time</b>
</td>
</tr>
<tr>
<td>
".n12br(strip_tags($message))."
</td>
</tr>
</table>
";
}

echo "<hr>";

if ($_POST['submit'])
{

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$date = date("Y-m-d");
$time = date("H:i:s");

if ($name&&$email&&$message)
{

$querypost = mysql_query("INSERT INTO 'guestbook' VALUES('','$name','$email','$message','$date','$time')");
echo "Please wait...<meta http-equiv='refresh' content='2'>";

}
else
echo "Please fill out all fields!";


}

echo "
<form action='guestbook.php' method='POST'>
<table width='100%'>
<tr>
<td width='17%' valign='top'>
Your name:
</td>
<td>
<input type='text' name='name' maxlenght='25'>
</td>
</tr>

<tr>
<td valign='top'>
Your email:
</td>
<td>
<input type='text' name='email' maxlenght='35'>
</td>
</tr>

<tr>
<td valign='top'>
Your message:
</td>
<td>
<textarea cols='20' rows='2' name='message' maxlenght='250'></textarea>
<p>
<input type='submit' value='Post' name='submit'>
</td>
</tr>
</table>
</form>
";

?>


HTH:)

auriaks
08-10-2009, 11:56 PM
still no changes... no adding. somethin is missing.

auriaks
08-11-2009, 02:26 AM
while my guestbook didnt work, i use another guestbook... but in it isnt LITHUANIAN letters like: ąčęėįšųūž... what i have to do, to correct that? you can download this guestbook here: http://swat.xz.lt/auriaks

JShor
08-11-2009, 02:44 PM
Well, it's not in the coding that you'd fix the problem, it's in the database. I assume you're using MySQL, so go into your phpMyAdmin [or whatever db admin you have] and change the MySQL connection collation: setting to utf8_lithuanian_ci on the phpMyAdmin home. I'm not sure how this is done on other db systems.

Lemme know if this solves the problem,bc it may be that you have to chg the unicode in the php code to connect to mysql.

auriaks
08-11-2009, 05:31 PM
just look at all files... it uses no database. All msges are storing in .txt file. But thanks for info, i corrected my phpmyadmin language for my new guestbook :D