FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Guestbook problem. PLEASE HELP!





catscratches
This is the code:
Main guestbook:
Code:
<html>
<head>
<title>Guestbook</title>
</head>
<body>
<b><u>Guestbook</b></u><br><br>
Write post:<br>
<form method="post" action="thanks_guest.php">
Name: <input type="text" name="name" value="" size="35"><br>
E-mail: <input type="text" name="mail" value="" size="35"><br>
Comment: <input type="text" name="comment" value="" size="500"><br>
<input type="submit" name="submit" value="Post!">
</form><br><br>
<?
$con=mysql_connect('localhost','catscrat_guest',secret password which I won't tell :p);
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}
$db=mysql_select_db('catscrat_guestbook', $con);
if (!$db)
{
   die ("Can\'t use the database : " . mysql_error());
}
$coms=mysql_query('SELECT * FROM post', $db);
while ($row != mysql_fetch_array($coms))
{
    echo $row['name'] . '<br> ' . $row['mail'] . '<br>' . $row['comment'] or die (mysql_error());
}

mysql_close($con);
?>
</body>
</html>

Thanks code:
Code:
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<?
$con=mysql_connect('localhost','catscrat_guest',secret password which I won't tell :p);
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}
$db=mysql_select_db('catscrat_guestbook', $con);
if (!$db)
{
   die ("Can\'t use the database : " . mysql_error());
}
mysql_query('INSERT INTO post ("name","mail","comment") VALUES ("' . $_POST[name] . '","' . $_POST[mail] . '","' . $_POST[comment] . ')',$con);
mysql_close($con);
?>
<u><b>Thanks for your post!</u></b><br><br>
<a href="guestbook.php">Back to Guestbook</a><br>
<a href="index.php">Main</a>
</body>
</html>

here's the code which I created the TABLE with:
Code:
<?
$con=mysql_connect('localhost','catscrat_guest',secret password);
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}
$db=mysql_select_db('catscrat_guestbook', $con);
if (!$db)
{
   die ("Can\'t use the database : " . mysql_error());
}
mysql_query('CREATE TABLE post(name VARCHAR(35), mail VARCHAR(35), comment VARCHAR(500))');
mysql_close($con);
?>


What's wrong? I'm a noob so please explain!
ncwdavid
Well where does it say the problem is? Im not going throught all that code not knowing what to look for sorry.
The3dx
i dont know what is the problem...
but some versions of PHP know to read php code like that <?php
and not just <? ...
tell us what is the output error
catscratches
Code:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/catscrat/domains/catscratches.frih.net/public_html/guestbook.php on line 25

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/catscrat/domains/catscratches.frih.net/public_html/guestbook.php on line 26
in guestbook.php

http://catscratches.frih.net/guestbook.php
TomS
Please post the source of "guestbook.php". A least lines 23-28
hexkid
catscratches wrote:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/catscrat/domains/catscratches.frih.net/public_html/guestbook.php on line 25


the second parameter to mysql_query() is a connection resource (such as the return from mysql_connect()), not a bool value (such as the return from mysql_select_db()).

http://php.net/mysql_connect
http://php.net/mysql_select_db
http://php.net/mysql_query
catscratches
My site was down for a time, but now it's up again Smile I changed it but now the problem is:
Code:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/catscrat/domains/catscratches.frih.net/public_html/guestbook.php on line 26
hexkid
catscratches wrote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/catscrat/domains/catscratches.frih.net/public_html/guestbook.php on line 26


mysql_fetch_array() needs a resource returned from mysql_query() (for SELECT, SHOW, DESCRIBE or EXPLAIN SQL statements).
When the mysql_query() fails (for whatever reason) it doesn't return a resource; it returns false. You really should test the return value before applying mysql_fetch_array() to it.

Code:
$coms=mysql_query('SELECT * FROM post', $db);
###
### TEST THE RETURN VALUE OF mysql_query()
if ($coms === false) {
    ### there was an error!!!!!!
    ### for simplicity sake, print the error and exit
    exit(mysql_error());
}
while ($row != mysql_fetch_array($coms))
catscratches
Thx alot!
Following error returned:
Table 'catscrat_guestbook.post' doesn't exist

This is the code used for creating the table:
Code:
<?
$con=mysql_connect('localhost','catscrat_guest',secret password:P);
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}
$db=mysql_select_db('catscrat_guestbook', $con);
if (!$db)
{
   die ("Can\'t use the database : " . mysql_error());
}
mysql_query('CREATE TABLE post(name VARCHAR(35), mail VARCHAR(35), comment VARCHAR(500))');
mysql_close($con);
?>

Ah, I see the problem! Ahaa!!
EDIT: WTF? Still doesn't work after adding $con to the mysql_query()
catscratches
Code:
Too big column length for column 'comment' (max = 255). Use BLOB instead


What is a BLOB and how to use it???
hexkid
catscratches wrote:
Code:
mysql_query('CREATE TABLE post(name VARCHAR(35), mail VARCHAR(35), comment VARCHAR(500))');
You do realize VARCHAR columns are limited to 255 characters and your comment column will be transformed into TEXT automagically? Anyway, that's not where your problem is.

catscratches wrote:
EDIT: WTF? Still doesn't work after adding $con to the mysql_query()
Hmmmm, the $db I used was a fast copy/paste error Smile

Why doesn't it work now? What is the error message from mysql_error()?
Or is it a PHP thing? Add the line in my sig to the top of your script to have PHP check your code more thoroughly than it does otherwise with the default configuration.
catscratches
Everything allright until thanks_guest.php now!
Code:
<html>
<head>
<title>Thanks!</title>
</head>
<body>
<?
$con=mysql_connect('localhost','catscrat_guest',secret password);
if (!$con)
{
   die('Could not connect: ' . mysql_error());
}
$db=mysql_select_db('catscrat_guestbook', $con);
if (!$db)
{
   die ("Can\'t use the database : " . mysql_error());
}
$quest='INSERT INTO post ("name","mail","comment") VALUES ("' . $_POST[name] . '","' . $_POST[mail] . '","' . $_POST[comment] . '")'
$coms=mysql_query($quest,$con);
if ($coms == false) {
    exit(mysql_error());
}
mysql_close($con);
?>
<u><b>Thanks for your post!</u></b><br><br>
<a href="guestbook.php">Back to Guestbook</a><br>
<a href="index.php">Main</a>
</body>
</html>

Error:
Code:
Parse error: syntax error, unexpected T_VARIABLE in /home/catscrat/domains/catscratches.frih.net/public_html/thanks_guest.php on line 18
hexkid
catscratches wrote:
catscratches wrote:
<?
...
$quest='INSERT INTO post ("name","mail","comment") VALUES ("' . $_POST[name] . '","' . $_POST[mail] . '","' . $_POST[comment] . '")'
$coms=mysql_query($quest,$con);
...

Error:
Code:
Parse error: syntax error, unexpected T_VARIABLE in /home/catscrat/domains/catscratches.frih.net/public_html/thanks_guest.php on line 18


no semicolon between $quest = '...' and $coms = mysql_query(...)

=-=-=-=-=-=-=-=-=-=-=-=-=-=
I've just noticed you use "<?" to enter PHP mode. I prefer to use "<?php" and not having to worry about the server configuration if I need to move the script to another server. Also it (short_open_tags) will be disabled in future versions of PHP to avoid confusion with xml tags (<?xml ... ?>)
catscratches
:S How is it supposed to be then? Completely lost -.-

Ok, I'll change to <?php
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.