SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2001
    Location
    France
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error message for PHP script

    Hi all,

    I hope to get some light shedded on my first PHP script I made.
    I'm a complete beginner, so bare with me!
    I am trying to make a database driven website and just for trying I have made a table called "Jeanine", with 6 columns.
    On the first page of my site I have a form, from which a user can choose from 4 options, 1 = tous, 2 = Castillonès, 3 = Monpazier, 4 = Villeréal. The options are sent trough the "GET" method.

    Here's the complete script, whatever I do, I always get an error message (parse error) on line 27. There are probably more errors to be found in this.....


    <?php

    $dbcnx = @mysql_connect("localhost","root","");
    if (!dbcnx) {
    echo("<P> La connection avec la base de données est impossible pour l'instant.</P>");
    exit ();
    }

    if (!@mysql_select_db ("jeanine")){
    echo("<P> Selection du table impossible.</P>");
    exit ();
    }


    IF ($Lieu == "1" );
    $result = mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix");

    ELSEIF ($Lieu == "2");
    $result = mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix WHERE lieu = 'Castillonès'");


    ELSEIF ($Lieu == "3");
    $result = mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix WHERE lieu = 'Monpazier'");

    ELSEIF ($Lieu == "4");
    $result = mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix WHERE lieu = 'Villeréal'");

    WHILE ($row = mysql_fetch_array ($result) {
    echo ("<P> . $row ["lieu, description, prix, photo"] .</P>");
    }

    ?>

    I'm so very sorry, if this is stupid, but I'm just trying to learn!
    Thanks for helping me out on this!

    Karin
    signature

  2. #2
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand -- we all, at one time or another, had to begin somewhere.

    Without knowing exactly which line 27 is, I'm going to guess it's your sequence of elseif statements. They do not need to be capitalized (this isn't your problem though), but you have the syntax wrong. Those are functions, not statements, therefore you need {'s instead of ;'s. Also, you didn't concatenate your code in the last while loop and it was missing an extra ) at the end:
    Code:
    <?php
    echo ("<P>" . $row ["lieu, description, prix, photo"] . "</P>");
    Anyway, try this code:
    PHP Code:
    <?php
    $dbcnx 
    = @mysql_connect("localhost","root","");
    if (!
    dbcnx) {
    echo(
    "<P> La connection avec la base de données est impossible pour l'instant.</P>");
    exit ();
    }
    if (!@
    mysql_select_db ("jeanine"))
    {
    echo(
    "<P<Selection du table impossible.</P>");
    exit ();
    }
    if (
    $Lieu == "1" )
    {
    $result mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix");
    }
    elseif (
    $Lieu == "2")
    {
    $result mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix WHERE lieu = 'Castillonès'");
    }
    elseif (
    $Lieu == "3")
    {
    $result mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix WHERE lieu = 'Monpazier'");
    }
    elseif (
    $Lieu == "4")
    {
    $result mysql_query ("SELECT lieu, description, prix, photo FROM Jeanine ORDER BY prix WHERE lieu = 'Villeréal'");
    }
    while (
    $row mysql_fetch_array ($result))
    {
    echo (
    "<P>" $row ["lieu, description, prix, photo"] . "</P>");
    }
    ?>
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  3. #3
    SitePoint Member
    Join Date
    Aug 2001
    Location
    France
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    Thanks for your answer, but "hélas" it didn't work neither!
    I think I now know where the problem is...... On my first page I have a form with 4 options, the value of these options (1,2,3,or 4) is send through the GET method.
    somehow I can't set the $Lieu (the option) right on the second page...
    Each value should give a different SELECT query to MySQL.

    Other ideas are greatly appreciated!

    Karin
    signature

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Border Collie
    Hi!

    Thanks for your answer, but "hélas" it didn't work neither!
    I think I now know where the problem is...... On my first page I have a form with 4 options, the value of these options (1,2,3,or 4) is send through the GET method.
    somehow I can't set the $Lieu (the option) right on the second page...
    Each value should give a different SELECT query to MySQL.

    Other ideas are greatly appreciated!

    Karin
    is the $Lieu the same case all places it is used?? remember php variables are case sensitive...if this isnt it (doubtful) please post your code for your first page, so that we can understand better what is going on
    signature

  5. #5
    SitePoint Member
    Join Date
    Aug 2001
    Location
    France
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code from the first page....

    form action = "sansnom3.php" Method = GET>
    <p>&nbsp;<font color="navy">Lieuselect name="Lieu" size="1">
    <option selected value="1">tous</option>
    <option value="2">Castillon&egrave;s</option>
    <option value="3">Monpazier</option>
    <option value="4">Viller&eacute;al</option>
    </select></font></p>

    I know have been thinking if I shouldn't have given the value the name of the cities. And I also thought I should use switch instead of if. But I'm not sure how to use switch.

    Anyway, for each value, the search in the database should find all the entries with the same value for the cityname. So value 2 or Castillonès should find all entries with cityname "Castillonès".

    I have been told there was also something wrong with the last $row
    I thought it was $row["column 1, column 2, etc,"]
    Wrong also?

    Thanks for any answer!

    Karin


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
  •