Solve this PHP problem

Discussion in 'QnA (read only)' started by JhonCena, Dec 27, 2006.

Thread Status:
Not open for further replies.
  1. JhonCena

    JhonCena New Member

    Joined:
    Nov 7, 2006
    Messages:
    130
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    in steel cage
    Plzzz solve this php problem:

    Code:
    <html>
    <head>
    <title>The Joke database</title>
    </head>
    <body>
    
    <?php if (isses($_GET['addjoke'])):
    ?>
    
    <form action="<?echo $_SERVER['PHP_SELF']; ?>" mehod='post'>
    <label>Type your joke here:<br />
    </textarea></label><br />
    <input type="submit" value="SUBMIT" />
    </forum>
    
    <?php
    else:$dbcnx = @mysql_connect('localhost', 'root', '********');
    if (!dbcnx) {
    exit('<p>Unable to connect to the ' .
    'database server at this time.</p>');
    }
    
    if (!@mysql_select_db('ijdb')) {
    exit('<p>Unable</p>');
    }
    
    if (isset($_POST['joke'])) {
    $joke = $_POST['joke'];
    $sql = "INSERT INTO joke SET
    joke='$joke',
    jokesate=CURDATE()";
    if (mysql_query($sql)) {
    echo '<p>Your joke has been added. </p>';
    } else {
    echo '<p>EROR adding submitted joke ' .
    mysql_eror() . '</p>';
    }
    
    echo '<p>Here are all the jokes in our database.</p>';
    
    $result = @mysql_query('SELECT joke FROM joke');
    if (!result) {
    exit('<p>Eror</p>');
    }
    
    while ($row = mysql_fetch_array($result)) {
    echo '<p>' . $row['joke'] . '</p>';
    }
    
    echo '<p><a href="' . $_SERVER['PHP_SELF'] .
    '?addjoke=1">Add a Joke!</a></p>';
    
    endif;
    
    ?>
    
    </body>
    </html>


    Error:

    Code:
    Parse error: parse error, unexpected T_ENDIF in C:\Program Files\VertrigoServ\www\tutorial\jokes.php on line 53

    Solve this prob plzzz
     
  2. Saharika

    Saharika New Member

    Joined:
    Oct 18, 2004
    Messages:
    437
    Likes Received:
    0
    Trophy Points:
    0
    any way looking at the code...it shows that you are new to php and trying to edit some script (i think i saw it in zend site)

    about script bad news is that it may have suffered even bigger problem as i feel like you have not gone php toturials or books ...as you have not read about main function like isset...
    (i am not saying it negatively)

    so keep it up but rather than directly editing others codes first read the basics...may be good books ,toturials site...and then may be edit...

    here main cause of error seem to be end if
    so may be you can do like this

    <html>
    <head>
    <title>The Joke database</title>
    </head>
    <body>

    <?php if (isset($_GET['addjoke'])):
    {
    ?>

    <form action="<?echo $_SERVER['PHP_SELF']; ?>" mehod='post'>
    <label>Type your joke here:<br />
    </textarea></label><br />
    <input type="submit" value="SUBMIT" />
    </form>

    <?php
    }
    else
    $dbcnx = @mysql_connect('localhost', 'root', '********');

    if (!dbcnx)
    {
    exit('<p>Unable to connect to the ' .'database server at this time.</p>');
    }

    if (!@mysql_select_db('ijdb'))
    {
    exit('<p>Unable</p>');
    }

    if (isset($_POST['joke']))
    {
    $joke = $_POST['joke'];
    $sql = "INSERT INTO joke SET joke='$joke',jokesate=CURDATE()";

    if (mysql_query($sql))
    {
    echo '<p>Your joke has been added. </p>';
    }
    else
    {
    echo '<p>EROR adding submitted joke ' .
    mysql_eror() . '</p>';
    }


    echo '<p>Here are all the jokes in our database.</p>';

    $result = @mysql_query('SELECT joke FROM joke');
    if (!result)
    {
    exit('<p>Eror</p>');
    }

    while ($row = mysql_fetch_array($result))
    {
    echo '<p>' . $row['joke'] . '</p>';
    }

    echo '<p><a href="' . $_SERVER['PHP_SELF'] .'?addjoke=1">Add a Joke!</a></p>';



    }//close of main if showing form
    ?>

    </body>
    </html>


    i dont saw much logical things but saw just semantical things


    and other bitter truth is you usually get good support for php things here may be try www.sitepoint.com/forums

    and may be i have also written a joke script for foreign client ..if u seriously need it
    www.jokes.bestcyberzone.com
    not ad as this is not my site...means not owner

    enjoy
     
  3. OP
    OP
    JhonCena

    JhonCena New Member

    Joined:
    Nov 7, 2006
    Messages:
    130
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    in steel cage
    Now there is

    Parse error: parse error, unexpected $end in C:\Program Files\VertrigoServ\www\tutorial\j2.php on line 69

    I am very new to php and mysql and I got this from an ebook by kevin yank. tell me links of some more tutorials and free ebooks to learn php and mysql

    Plzzz use code tags next time
     
  4. Pathik

    Pathik Google Bot

    Joined:
    Aug 28, 2005
    Messages:
    9,747
    Likes Received:
    20
    Trophy Points:
    0
    try w3schools.com 4 html,php etc
     
  5. mediator

    mediator New Member

    Joined:
    Mar 18, 2005
    Messages:
    2,491
    Likes Received:
    16
    Trophy Points:
    0
    Location:
    In ur Evil Mind!
    @john ......... Can u execute simple insert and fetch mysql query from php on windows?
     
  6. Saharika

    Saharika New Member

    Joined:
    Oct 18, 2004
    Messages:
    437
    Likes Received:
    0
    Trophy Points:
    0
    ya the problem seems to be with the config rather than syntax
    you would be better to post it in forum like
    sitepoint.com/forums

    by the way it is almost like official forum for that yank book so u will get great support there
     
  7. OP
    OP
    JhonCena

    JhonCena New Member

    Joined:
    Nov 7, 2006
    Messages:
    130
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    in steel cage
    ^^^^^^^^^^^Thank you very much for providing the link^^^^^^^^^^
     
  8. bpeel

    bpeel New Member

    Joined:
    Jan 5, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I think you forgot a } for the if statement from this piece of code:

    if (isset($_POST['joke'])) {
    $joke = $_POST['joke'];
    $sql = "INSERT INTO joke SET joke='$joke', jokesate=CURDATE()";
    if (mysql_query($sql)) {
    echo '<p>Your joke has been added. </p>';
    }
    else
    {
    echo '<p>EROR adding submitted joke ' . mysql_eror() . '</p>';
    }
     
  9. OP
    OP
    JhonCena

    JhonCena New Member

    Joined:
    Nov 7, 2006
    Messages:
    130
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    in steel cage
    Thanks for the late reply

    I think you are very new to this forum
    hi and welcome to thinkdigit forum. and happy foruming. hope you ll like to stay here. read all the rules of thinkdigit forum before proceeding

    next time use code tags ([CODE some code [/CODE)
    thanx 4 reply I 'll try this later
     
Thread Status:
Not open for further replies.

Share This Page