SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member Cas's Avatar
    Join Date
    Jun 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm Just Starting out and need some help

    Hi everyone,
    I'm new to this forum and new to PHP to be honest. Ive started to learn PHP by following the tutorial featured on this site; Building a Database-Driven Web site using PHPetc

    Everything has been going fine until it was time for PHP to start talking to MySQL.
    I am running PHP 4 on a windows based laptop with WinmySQLadmin ver1.0 and Xiami server software.
    Ive managed to create a jokes database using the MySQL.exe interface and have also run some simple PHP scripts, following the tutorial to the letter. I have advanced in the tutorial to the section where PHP connects with SQL.

    The script that I have used to connect with MySQL is as follows:

    <TITLE> Our List of Jokes </TITLE>
    <HEAD>
    <BODY>
    <?php
    // Connect to the database server $dbcnx = @mysql_connect("localhost", "computer", "hello");
    if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" );
    exit(); }
    </BODY></HTML>

    This works i.e. it shows no error message strangely though (even when I change the passwords or hostname around)
    However, when I combine this with the rest of the script as per the tutorial.

    <TITLE> Our List of Jokes </TITLE>
    <HEAD>
    <BODY>
    <?php
    // Connect to the database server $dbcnx = @mysql_connect("localhost", "computer", "hello");
    if (!$dbcnx) { echo( "<P>Unable to connect to the " . "database server at this time.</P>" );
    exit(); }
    </BODY></HTML>
    // Select the jokes database
    if (! @mysql_select_db("jokes") ) { echo( "<P>Unable to locate the joke " . "database at this time.</P>" ); exit(); }
    ?><P> Here are all the jokes in our database: </P><BLOCKQUOTE>
    <?php // Request the text of all the jokes $result = mysql_query( "SELECT JokeText FROM Jokes"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); }
    // Display the text of each joke in a paragraph while ( $row = mysql_fetch_array($result) ) { echo("<P>" . $row["JokeText"] . "</P>"); }
    ?>
    </BLOCKQUOTE></BODY></HTML>

    I get the following in my browser window:

    Here are all the jokes in our database:

    Error performing query: " . mysql_error() . "
    "); exit(); } // Display the text of each joke in a paragraph while ( $row = mysql_fetch_array($result) ) { echo("
    " . $row["JokeText"] . "
    "); } ?>

    Even with my small amount of knowledge in PHP and MySQL I know something is not quite right. Please, can anyone help me out and point me in the right direction. With a bit of luck and some good advice I can carry on learning this great language.

    Thank you in advance

    Cas
    "Tell me and I will forget , show me and I'll learn.
    Involve me and I will remember. " Confucius.

  2. #2
    ********* Addict
    Join Date
    Apr 2000
    Location
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could it be that the PHP code is not parsed? Make sure you have set up PHP properly. You can use something like http://www.nusphere.com if you can't be bothered to install it. Nusphere is quite large though.

  3. #3
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is:
    <?php // Request the text of all the jokes $result = mysql_query( "SELECT JokeText FROM Jokes"); if (!$result) { echo("<P>Error performing query: " . mysql_error() . "</P>"); exit(); }
    // Display the text of each joke in a paragraph while ( $row = mysql_fetch_array($result) ) { echo("<P>" . $row["JokeText"] . "</P>"); }

    All one line?

    After:

    <?php you should leave a line before commenting and then another another line for $result

  4. #4
    SitePoint Member Cas's Avatar
    Join Date
    Jun 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks petesmc, pedro_gb

    pedro wrote "Could it be that the PHP code is not parsed"

    Do you mean, is PHP reading the script? Well I think so all my PHP scripts have worked thus far with no difficulty at all.

    Ill try running the script as petesmc advised, and see if that works.

    Has anyone else got MySQL and Xitami up and running on a window based PC if so what was your set up procedure? Id also appreciate any other advice for setting up and learning MySQL and PHP. Ive looked at the FAQs on many web sites, but I cant seem to get the info I need.

    Thanks in advance
    Cas
    "Tell me and I will forget , show me and I'll learn.
    Involve me and I will remember. " Confucius.

  5. #5
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it was the problem with everything being on one line, you might like to get a text editor that colour codes your code. This way it would be easier to see if you comment stuff out by mistake or not.

    Give editplus a spin:
    http://www.editplus.com

  6. #6
    SitePoint Member Cas's Avatar
    Join Date
    Jun 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good news bad news im afraid

    Good news- I think that Im being acknowledged by PHP and MySQL. The scripts are running fine.

    Bad news- (Getting me down) I still cant get access to MySQL through PHP.
    Checked PHP running ok
    Checked Server running ok
    Checked MySQL running ok
    Checked MySQLadmin I think ok

    Code Im using

    <HTML>
    <HEAD>
    <TITLE> Our List of Jokes </TITLE>
    <HEAD>
    <BODY>
    <?php
    // Connect to the database server

    $dbcnx = @mysql_connect("localhost", "root", "Yes");
    if (!$dbcnx) {
    echo( "<P>Unable to connect to the " . "database server at this time.</P>" );
    exit();
    }

    ?>
    </BLOCKQUOTE></BODY></HTML>

    A copy of my.ini file

    [WinMySQLAdmin]
    Server=C:/MYSQL/bin/mysqld.exe
    user=root
    password=YES

    [mysqld]
    basedir=C:/MYSQL
    #bind-address=127.0.0.1
    datadir=C:/MYSQL/data
    #language=C:/MYSQL/share/your language directory
    #slow query log#=
    #tmpdir#=
    #port=3306
    #set-variable=key_buffer=16M


    An idea , Ive just had. Should the host, user , password appear in quote marks, e.g. root above in the ini file and in MySQLadmin ini (I realise they are the same thing)
    Any further help would be greatly appreciated.
    Thanks in advance
    Cas
    "Tell me and I will forget , show me and I'll learn.
    Involve me and I will remember. " Confucius.

  7. #7
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is your password lowercase and uppercase like you put in?
    Also use GRANT to

    grant select, insert, update, delete, on database.* to xxx@localhost identified by 'password';

    grant all on database.* to user@localhost;

    John

  8. #8
    SitePoint Member Cas's Avatar
    Join Date
    Jun 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you everyone for you help.
    Everything is fine and I can carry on learning MySQL and PHP.
    I re-installed MySQL and went through the processes from start to finish. Following the MySQL manual to the letter.

    I seem to be using different MySQL server software now though.
    I'm positive I'll be making use of this Forums in the future.

    Thanks again
    Cas
    "Tell me and I will forget , show me and I'll learn.
    Involve me and I will remember. " Confucius.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •