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


Problems with MySQL database!!!





alalex
I want to create a database for comments, so people can comment some flash tutorials... So I created a database called "username_example" for that. Now,
I wrote this:
Code:

<?php
        $handle = mysql_connect('localhost','username_example','password');
        if(handle == FALSE){
        echo "Could not connect to database";
        }
        $db = mysql_select_db('username_example_comments);
        if($db == FALSE){
        echo "Database not available";
        }
        $query = 'SELECT comment FROM username_example_comments WHERE comments = 1';
        $result = mysql_query($query, $handle);
        if($result == FALSE){
        echo "No available comments";
        while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
        print_r($row);
        }
        mysql_close($handle);
?>


Can someone tell me why it is not working and how to display only one comment. i.e. Comment number 3.
Thanks!!
Atomo64
maybe if you give us the table structure, and the contents of it, we could help you Smile
jabapyth
replace
Code:
if(handle == FALSE){

with
Code:
if($handle == FALSE){

(you forgot the '$')
dont worry, its a common mistake with those who have worked in laguages that don't utilize the '$'.

Good Luck!
alalex
Thanks!!!
alalex
OK, now it works, but I need to enter the database (already done) And I need to show only the first comment!! Someone can tell me how to create the record in the database and then display it in there.

The page is this: http://mundodiseno.frih.net/tuto_move.php
But right now is not working... What does it mean "unexpected $end"?
Jamatu
Quote:
OK, now it works, but I need to enter the database (already done) And I need to show only the first comment!! Someone can tell me how to create the record in the database and then display it in there.

To display the first comment you should have an 'id' row set to auto_increment so it's unique. Have you got access to phpMyAdmin or not? If you have then you can add the row through that.

To add a comment use the following, but don't forget your gonna need a textbox etc to get the users comment.
Code:
$query = "INSERT INTO user_example_comments (id,comment) VALUES ('','$commentstring')";

If you want the first comment then you can just use
Code:
$query = "SELECT id,comment FROM user_example_comments WHERE id = '1'";


Quote:
The page is this: http://mundodiseno.frih.net/tuto_move.php
But right now is not working... What does it mean "unexpected $end"?

The URL isn't working for me.

By the way Instead of
Code:
        $handle = mysql_connect('localhost','username_example','password');
        if(handle == FALSE){
        echo "Could not connect to database";
        }
        $db = mysql_select_db('username_example_comments);
        if($db == FALSE){
        echo "Database not available";
        }
You could have
Code:
        $handle = mysql_connect('localhost','username_example','password') or die ("Could not connect to database");
        $db = mysql_select_db('username_example_comments) or die ("Database not available");
alalex
Thanks, yes I have the acces. Actually I am using a .frih.net host, from this forum...

Why did you leave the ' ' empty?? Where you put:
Quote:

To add a comment use the following, but don't forget your gonna need a textbox etc to get the users comment.
Code:

$query = "INSERT INTO user_example_comments (id,comment) VALUES ('','$commentstring')";

alalex
Do you mean write "or" instead of
Code:

If($handle == FALSE)...??
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.