SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard masm50's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    2,508
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    I can't fiind what is wrong with this PHP script, any ideas?

    I am trying to make an admin area to my site, where reviews can be added, then they would automatically become part of my site.

    Here is the whole PHP script that I wrote (Thanks to the great Sitepoint tutorials):

    <HTML>
    <HEAD>
    <title>Add New Review</title>
    </HEAD>
    <BODY>
    <?php

    if ($submit):

    if ($aid == "") {
    echo("<P>You must choose an author.</P>");
    exit();
    }

    if ($lid == "") {
    echo("<P>You must choose a license.</P>");
    exit();
    }

    if ($rid == "") {
    echo("<P>You must choose a rating.</P>");
    exit();
    }

    if ($cid == "") {
    echo("<P>You must choose a category.</P>");
    exit();
    }

    $dbcnx = @mysql_connect(
    "localhost", "audiomelody", "Bollinger");
    mysql_select_db("audiomelody");

    $sql = "INSERT INTO Reviews SET " .
    "Title='$title', " .
    "Version='$version', " .
    "ReviewText='$reviewtext', " .
    "Date='CURDATE()', " .
    "FileSize='$filesize', " .
    "ScreenURL='$screenurl', " .
    "DownloadURL='$downloadurl', " .
    "LicenseInfo='$licenseinfo', " .
    "SystemReq='$systemreq', " .
    "AID='$aid', " .
    "LID='$lid', " .
    "RID='$rid', " .
    "CID='$cid'," ;
    if (mysql_query($sql)) {
    echo("<P>New review added</P>");
    } else {
    echo("<P>Error adding new review: " .
    mysql_error() . "</P>");
    }
    ?>

    <?php
    else:
    $dcnx = @mysql_connect(
    "localhost","audiomelody", "Bollinger");
    mysql_select_db("audiomelody");

    $authors = mysql_query (
    "SELECT ID, Name FROM Authors");
    $licenses = mysql_query (
    "SELECT ID, Name FROM Licenses");
    $ratings = mysql_query (
    "SELECT ID, Name FROM Ratings");
    $cats = mysql_query (
    "SELECT ID, Name FROM Categories");
    ?>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter Software TitleBR>
    <TEXTAREA NAME="title" ROWS=1 COLS=45 WRAP>
    </TEXTAREA>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter VersionBR>
    <TEXTAREA NAME="version" ROWS=1 COLS=45 WRAP>
    </TEXTAREA>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter New ReviewBR>
    <TEXTAREA NAME="reviewtext" ROWS=15 COLS=45 WRAP>
    </TEXTAREA>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter File SizeBR>
    <TEXTAREA NAME="filesize" ROWS=1 COLS=45 WRAP>
    </TEXTAREA>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter Screenshot URLBR>
    <TEXTAREA NAME="screenurl" ROWS=2 COLS=45 WRAP>
    </TEXTAREA>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter Download URLBR>
    <TEXTAREA NAME="downloadurl" ROWS=2 COLS=45 WRAP>
    </TEXTAREA>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter License InfoBR>
    <TEXTAREA NAME="licenseinfo" ROWS=5 COLS=45 WRAP>
    </TEXTAREA>

    <FORM ACTION="<?php echo(PHP_SELF); ?>" METHOD=POST>
    <P>Enter System RequirementsBR>
    <TEXTAREA NAME="systemreq" ROWS=5 COLS=45 WRAP>
    </TEXTAREA>

    <P>Author:
    <SELECT NAME="aid" SIZE=1>
    <OPTION SELECTED VALUE="">Select One
    <OPTION VALUE="">---------
    <?php
    while ($author = mysql_fetch_array($authors)) {
    $aid = $author["ID"];
    $name = $author["Name"];
    echo("<OPTION VALUE='$aid'>$aname\n");
    }
    ?>
    </SELECT></P>

    <P>License:
    <SELECT NAME="lid" SIZE=1>
    <OPTION SELECTED VALUE="">Select One
    <OPTION VALUE="">---------
    <?php
    while ($license = mysql_fetch_array($licences)) {
    $lid = $license["ID"];
    $name = $license["Name"];
    echo("<OPTION VALUE='$lid'>$lname\n");
    }
    ?>
    </SELECT></P>

    <P>Rating:
    <SELECT NAME="rid" SIZE=1>
    <OPTION SELECTED VALUE="">Select One
    <OPTION VALUE="">---------
    <?php
    while ($rating = mysql_fetch_array($ratings)) {
    $rid = $rating["ID"];
    $name = $rating["Name"];
    echo("<OPTION VALUE='$rid'>$rname\n");
    }
    ?>
    </SELECT></P>

    <P>Category:
    <SELECT NAME="cid" SIZE=1>
    <OPTION SELECTED VALUE="">Select One
    <OPTION VALUE="">---------
    <?php
    while ($cat = mysql_fetch_array($cats)) {
    $cid = $cat["ID"];
    $name = $cat["Name"];
    echo("<OPTION VALUE='$cid'>$cname\n");
    }
    ?>

    <?php

    if ($submit):

    if ($aid == "") {
    echo("<P>You must choose an author.</P>");
    exit();
    }

    if ($lid == "") {
    echo("<P>You must choose a license.</P>");
    exit();
    }

    if ($rid == "") {
    echo("<P>You must choose a rating.</P>");
    exit();
    }

    if ($cid == "") {
    echo("<P>You must choose a category.</P>");
    exit();
    }

    $dbcnx = @mysql_connect(
    "localhost", "audiomelody", "Bollinger");
    mysql_select_db("audiomelody");

    $sql = "INSERT INTO Reviews SET " .
    "Title='$title', " .
    "Versio='$version', " .
    "ReviewText='$reviewtext', " .
    "Date='CURDATE()', " .
    "FileSize='$filesize', " .
    "ScreenURL='$screenurl', " .
    "DownloadURL='$downloadurl', " .
    "LicenseInfo='$licenseinfo', " .
    "SystemReq='$systemreq', " .
    "AID='$aid', " .
    "LID='$lid', " .
    "RID='$rid', " .
    "CID='$cid'," ;
    if (mysql_query($sql)) {
    echo("<P>New review added.");
    } else {
    echo("<P>Error adding new review: " .
    mysql_error() . "</P>");
    }
    ?>

    </P>
    <P><INPUT TYPE=SUBMIT NAME="submit" VALUE="SUBMIT"></P>
    </FORM>
    <?php endif; ?>
    </BODY>
    </HTML>

    I then get the error message:

    Parse error: parse error in c:\program files\apache group\apache\htdocs\addreview5.php on line 218

    Which I find odd, as that line only says : </HTML>

    I would appreciate all the help I can get,

    Cheers (thanks in advance)

    Tim

  2. #2
    Digital Warrior Renegade's Avatar
    Join Date
    Nov 2000
    Location
    Portland, OR
    Posts
    480
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A couple things that might help you out

    1) Make only one form. Meaning, use only one <form> tag. Instead of a <form> tag for each form element.

    2) you have "if submit" in two places. YOu only need them in one place. (usually at the top)

    If you get a parse error on the last line of your script, and it is not PHP code, then look up until you DO reach a line of PHP code:

    <?php endif; ?>

    I don't believe there is an endif; statement. You should probably just have a closing } instead.

    good luck
    --There's my 1.5 cents, now where is my change!?!?

  3. #3
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have 2 lines with if($submit): and one else: and only one endif;
    also, i'd recommend just using
    PHP Code:
    if(condition)
    {
      
    //do stuff
    }
    else
    {
      
    //do stuff

    for your ifs. or at least pick a constant.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  4. #4
    SitePoint Wizard masm50's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    2,508
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Thanks guys

    I noticed the double if statement about 10 mins after I posted - I should have edited my post I suppose.

    Thanks for the other tips though,

    see how I go,

    Cheers

    Tim


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
  •