Web Analytics Made Easy -
StatCounter Need Help: Getting Error on PHP/MySQL script! - CodingForum

Announcement

Collapse
No announcement yet.

Need Help: Getting Error on PHP/MySQL script!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Help: Getting Error on PHP/MySQL script!

    Okay, I am developing a web app called Tudit. I am having major trouble with a script that is supposed to add something we're calling a "channel".

    The code I am using is as follows:

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Tudit: Create Channel</title>
    </head>

    <body>


    <?php
    $user
    =$_SESSION['email'];
    require_once (
    '../mysql_connect.php'); // Connect to the database

    // Insert channel
    $query "INSERT INTO channels (channame, source1, name1, source2, name2, source3, name3, source4, name4, source5, name5) VALUES ('$_GET['channame']', '$_GET['source1']', '$_GET['name1']', '$_GET['source2']', '$_GET['name2']', '$_GET['source3']', '$_GET['name3,']', '$_GET['source4']', '$_GET['name4']', '$_GET['source5']', '$_GET['name5']')";        
            
    $result = @mysql_query ($query);
            

    ?>
                <p><h3>Please enter sources (RSS/ATOM files only!):</h3>
                <br /><form action="createchannel.php" method="GET">
                <input type="text" name="channame" value="Channel Name" /><br/>
    <input type="text" name="source1" size="50" maxlength="100" value="Source #1" /><input type="text" name="name1" size="50" maxlength="150" value="Name of Source #1" />
    <br /><input type="text" name="source2" size="50" maxlength="100" value="Source #2" /><input type="text" name="name2" size="50" maxlength="150" value="Name of Source #2" />
    <br /><input type="text" name="source3" size="50" maxlength="100" value="Source #3" /><input type="text" name="name3" size="50" maxlength="150" value="Name of Source #3" />
    <br /><input type="text" name="source4" size="50" maxlength="100" value="Source #4" /><input type="text" name="name4" size="50" maxlength="150" value="Name of Source #4" />
    <br /><input type="text" name="source5" size="50" maxlength="100" value="Source #5" /><input type="text" name="name5" size="50" maxlength="150" value="Name of Source #5" />
    <br /><input type="submit" value="Create-it!">
    </p>
    </form>
    </body>
    </html>
    And the error message I am getting is:

    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/25/d114722137/htdocs/tudit/dynamic/html/createchannel.php on line 16

    Also, line 16 is:

    PHP Code:
    $query "INSERT INTO channels (channame, source1, name1, source2, name2, source3, name3, source4, name4, source5, name5) VALUES ('$_GET['channame']', '$_GET['source1']', '$_GET['name1']', '$_GET['source2']', '$_GET['name2']', '$_GET['source3']', '$_GET['name3,']', '$_GET['source4']', '$_GET['name4']', '$_GET['source5']', '$_GET['name5']')"
    Can anyone help me?!

  • #2
    Possible solution

    I suspect you will need to remove the extra quotes plus the extra comma next to name3.

    Like this
    PHP Code:
    $query "INSERT INTO channels (channame, source1, name1, source2, name2, source3, name3, source4, name4, source5, name5) VALUES ($_GET['channame'], $_GET['source1'], $_GET['name1'], $_GET['source2'], $_GET['name2'], $_GET['source3']', $_GET['name3'], $_GET['source4'], $_GET['name4'], $_GET['source5']', $_GET['name5'])";        
            
    $result = @mysql_query ($query); 
    or if you must have the quotes then

    PHP Code:
    $query "INSERT INTO channels (channame, source1, name1, source2, name2, source3, name3, source4, name4, source5, name5) VALUES ('"$_GET['channame']. "', '"$_GET['source1']. "', '"$_GET['name1']. "', '"$_GET['source2']. "', '"$_GET['name2']. "', '"$_GET['source3']. "'', '"$_GET['name3']. "', '"$_GET['source4']. "', '"$_GET['name4']. "', '"$_GET['source5']. "', '"$_GET['name5']. "')";      
            
    $result = @mysql_query ($query); 
    PHP is weakly typed, so if $_Get is a string it will be deduced without the extra quotes.

    Hope this helps.
    Last edited by mylegoh; Oct 12, 2006, 07:04 PM.

    Comment


    • #3
      Actually MySQL syntax requires quotes around string values, so the second correction mylegoh provided would work.

      Comment


      • #4
        Okay, the second one worked. But there is a major problem: it is not sending the data tot he database, and it isnt even coming up with an error!

        Comment


        • #5
          The first rule of Queries, don't talk about Queries. No just kidding, the first rule of Queries, always check to see if the query worked.

          So instead of:
          PHP Code:
          $query "super duper query";
          $result mysql_query($query); 
          You want something like:
          PHP Code:
          $query "super duper query";
          $result mysql_query($query);
          //check the results of the query call!
          if (!$result) {
              print 
          "oops, there is a SQL error with a query.<br />Query: $query<br />error: ".mysql_error();

          Comment


          • #6
            Ok, so immediately when I open the page I get this (and the values for data being sent to the database are blank because nothing has been sent yet):

            oops, there is a SQL error with a query.
            Query: INSERT INTO channels (channame, source1, name1, source2, name2, source3, name3, source4, name4, source5, name5) VALUES ('', '', '', '', '', ''', '', '', '', '', '')
            error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '''', '', '', '', '', '')' at line 1

            Please help me fix this page!

            Comment


            • #7
              echo out the value for $query so you can see what you are sending to the database.

              Comment


              • #8
                Originally posted by guelphdad View Post
                echo out the value for $query so you can see what you are sending to the database.
                huh? wut it sends is the values of the $_GET fields, but in the begin inning, its not sending anything, but it tries to. Im kinda confused, sorry.

                Comment


                • #9
                  You are already echoing out the value of $query, no worries. But, take a close look at what the error message tells you. There is a syntax error, and your query looks like this:

                  Query: INSERT INTO channels (channame, source1, name1, source2, name2, source3, name3, source4, name4, source5, name5) VALUES ('', '', '', '', '', ''', '', '', '', '', '')
                  You see anything wrong with that? Apart from the fact you are inserting a row all empty values (which would work normally but is quite useless), you have one little extra quote in there causing the query to fail. After you fix that, you'll want to fix the problem with the values all being empty I'm sure.

                  Comment


                  • #10
                    Well, it finally works! I can't believe I had an extra character and didn't realize it... I feel like such an idiot sometimes... Thank you guys so much!

                    Comment

                    Working...
                    X