SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member mAd 'ArriS's Avatar
    Join Date
    Oct 2003
    Location
    Finland
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP / MYSQL Connect Error

    Just trying to learn PHP and MYSQL. I have setup with IIS on Windows 2000 - The first text php script "The date according to this server... " works OK.

    Problem is when I try to connect to the mysql database I get the following error

    "Warning: Unknown(C:\users\work\NEW WEB\php\email1.php): failed to open stream: No such file or directory in Unknown on line 0

    Warning: (null)(): Failed opening 'C:\users\work\NEW WEB\php\email1.php' for inclusion (include_path='.;c:\php4\pear') in Unknown on line 0"

    I am thinking maybe I have missed something in the setup somewhere... can anyone help??

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Can we see the PHP code you're using to connect to the database?

  3. #3
    SitePoint Member mAd 'ArriS's Avatar
    Join Date
    Oct 2003
    Location
    Finland
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    Can we see the PHP code you're using to connect to the database?
    The code is straight from Kevin Yank's book... Just to be clear, I do connect to the database, if I try to load a second page then I get the error... In the example from the book there is the following code:-

    <html>
    <head>
    <title>The Internet Joke Database </title>
    </head>
    <body>
    <?php
    if (isset($_GET ['addjoke']))://If the user wants to add a joke
    ?>
    <form action="<?=$_SERVER ['PHP_SELF']?>"method="post">
    <p>Type your joke herebr />
    <textarea name="joketext"rows="10"cols="40"wrap>
    </textarea><br />
    <input type="submit"name="submitjoke"value="SUBMIT"/>
    </p>
    </form>
    <?php
    else://Default page display
    //Connect to the database server
    $dbcnx =@mysql_connect('localhost','root','mypasswd');
    if (!$dbcnx){
    die('<p>Unable to connect to the '.
    'database server at this time.</p>');
    }
    //Select the jokes database
    if (!@mysql_select_db('jokes')){
    die('<p>Unable to locate the joke '.
    'database at this time.</p>');
    }
    //If a joke has been submitted,
    //add it to the database.
    if (isset($_POST ['submitjoke'])){
    $joketext =$_POST ['joketext'];
    $sql ="INSERT INTO Jokes SET
    JokeText='$joketext',
    JokeDate=CURDATE()";
    if (@mysql_query($sql)){
    echo('<p>Your joke has been added.</p>');
    }else {
    echo('<p>Error adding submitted joke:'.
    mysql_error().'</p>');
    }
    }
    //If a joke has been deleted,
    //remove it from the database.
    if (isset($_GET ['deletejoke'])){
    $jokeid =$_GET ['deletejoke'];
    $sql ='DELETE FROM Jokes
    WHERE ID=$jokeid';
    if (@mysql_query($sql)){
    echo('<p>The joke has been deleted.</p>');
    }else {
    echo('<p>Error deleting joke:'.
    mysql_error().'</p>');
    }
    }
    echo('<p>Here are all the jokes in our database/p>');
    //Request the ID and text of all the jokes
    $result =@mysql_query('SELECT ID,JokeText FROM Jokes');
    if (!$result){
    die('<p>Error performing query:'.
    mysql_error().'</p>');
    }
    //Display the text of each joke in a paragraph
    //with a "Delete this Joke"link next to each.
    while ($row =mysql_fetch_array($result)){
    $jokeid =$row ['ID'];
    $joketext =$row ['JokeText'];
    echo('<p>'.$joketext .
    '<a href="'.$_SERVER ['PHP_SELF'] ..
    '?deletejoke='.$jokeid .'">'.
    'Delete this Joke</a></p>');
    }
    //When clicked,this link will load this page
    //with the joke submission form displayed.
    echo('<p><a href="'.$_SERVER ['PHP_SELF'] ..
    '?addjoke=1">Add a Joke!</a></p>');
    endif;
    ?>
    </body>
    </html>

    Now this code works to load the page and siaply the jokes initially, but if I click the link to add a joke I then get the error message... I have tried reinstalling MySQL etc...

  4. #4
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's easier to read if you use the php forum tags.

    PHP Code:
    <html>
    <head>
    <title>The Internet Joke Database </title>
    </head>
    <body>
    <?php
    if (isset($_GET ['addjoke']))://If the user wants to add a joke
    ?>
    <form action="<?=$_SERVER ['PHP_SELF']?>"method="post">
    <p>Type your joke here:<br />
    <textarea name="joketext"rows="10"cols="40"wrap>
    </textarea><br />
    <input type="submit"name="submitjoke"value="SUBMIT"/>
    </p>
    </form>
    <?php
    else://Default page display
    //Connect to the database server
    $dbcnx =@mysql_connect('localhost','root','mypasswd');
    if (!
    $dbcnx){
    die(
    '<p>Unable to connect to the '.
    'database server at this time.</p>');
    }
    //Select the jokes database
    if (!@mysql_select_db('jokes')){
    die(
    '<p>Unable to locate the joke '.
    'database at this time.</p>');
    }
    //If a joke has been submitted,
    //add it to the database.
    if (isset($_POST ['submitjoke'])){
    $joketext =$_POST ['joketext'];
    $sql ="INSERT INTO Jokes SET
    JokeText='
    $joketext',
    JokeDate=CURDATE()"
    ;
    if (@
    mysql_query($sql)){
    echo(
    '<p>Your joke has been added.</p>');
    }else {
    echo(
    '<p>Error adding submitted joke:'.
    mysql_error().'</p>');
    }
    }
    //If a joke has been deleted,
    //remove it from the database.
    if (isset($_GET ['deletejoke'])){
    $jokeid =$_GET ['deletejoke'];
    $sql ='DELETE FROM Jokes
    WHERE ID=$jokeid'
    ;
    if (@
    mysql_query($sql)){
    echo(
    '<p>The joke has been deleted.</p>');
    }else {
    echo(
    '<p>Error deleting joke:'.
    mysql_error().'</p>');
    }
    }
    echo(
    '<p>Here are all the jokes in our database:</p>');
    //Request the ID and text of all the jokes
    $result =@mysql_query('SELECT ID,JokeText FROM Jokes');
    if (!
    $result){
    die(
    '<p>Error performing query:'.
    mysql_error().'</p>');
    }
    //Display the text of each joke in a paragraph
    //with a "Delete this Joke"link next to each.
    while ($row =mysql_fetch_array($result)){
    $jokeid =$row ['ID'];
    $joketext =$row ['JokeText'];
    echo(
    '<p>'.$joketext .
    '<a href="'.$_SERVER ['PHP_SELF'] ..
    '?deletejoke='.$jokeid .'">'.
    'Delete this Joke</a></p>');
    }
    //When clicked,this link will load this page
    //with the joke submission form displayed.
    echo('<p><a href="'.$_SERVER ['PHP_SELF'] ..
    '?addjoke=1">Add a Joke!</a></p>');
    endif;
    ?>
    </body>
    </html>


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
  •