SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26
  1. #1
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Error with PHP/MySQL code...

    Ok, I wrote this code, following a tutorial...

    I will just show you the bit of code that is causing a problem, so I don't have to go through and explain the entire tutorial:

    PHP Code:
    $query="insert into user set username='$name', email='$email"
    When I upload and run the file, I get this error:

    Code:
    Parse error: parse error, unexpected T_VARIABLE in /jabird/htdocs/phplearn/sql/1.php on line 54
    I have search php.net for T_VARIABLE, to possibly find someone else that had the same error... no luck

    I did notice, that there is no (') after $email in that code...

    PHP Code:
    email='$email"; 
    now, I am new to this whole thing, but I do think, that there should be a ' after the $email (especially after looking at "username='$name',)

    correct me if I'm wrong, but from what I've learned thus far, there needs to be a ' after $email...

    sorry about my rambling there...

    I did try adding a ' after $email, but it still didn't work

    so if anyone has any suggestions, feel free


    Pre-Thank you
    ~Jabird

  2. #2
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually you're entire line should be:

    $query="insert into user set username='$name', email='$email'";

  3. #3
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Be sure to be consistant with your single and double quotes!

  4. #4
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am still getting the T_VARIABLE error after copying word-for-word, the code that you gave me...

  5. #5
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is that the code that is on line 54?

  6. #6
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes it is

  7. #7
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Huh, post can you post lines 40 - 60 please?

  8. #8
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    mysql_select_db($databasename);
    
    $sql = "create table users(" .
    "ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " .
    "username text, ".
    "email text)";
    mysql_query($sql)
    
    //************************************\\
    // That code connects to the database \\
    //       creates the tables           \\
    //      and creates the rows...       \\
    //************************************\\
    
    $query="insert into user set username='$name', email='$email'";
    
    mysql_query($query)
    
    //********************\\
    // Inserts data into  \\
    // the set 'username' \\
    40-60... Got bored, so made my comments like that


    ~Jabird

  9. #9
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need a semi-colon after:

    mysql_query($query)

    mysql_query($query);

  10. #10
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, cleared that one up now... but getting this error now:

    Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /jabird/htdocs/phplearn/sql/first.php on line 65

    Line 65 code:
    PHP Code:
    echo $row["username""\n"); 
    Code, that comes before and after that:

    PHP Code:
    $selection mysql_query("SELECT * FROM users");
    while ( 
    $row mysql_fetch_array($selection) ) {
    echo 
    $row["username""\n");

    I know it says "Expecting , or ;", but hmmm.... I just don't know


    ~Jabird
    I think I will be buying me a PHP Beginners book REAL soon, if stuff like this keeps up

  11. #11
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change line 65 to:

    echo $row['username']."\n");

    Although you don't really need the newline. You can just:

    echo $row['username'];

    You need to concantenate the variable with the string

  12. #12
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Get programming PHP from amazon.com. This goes over basic syntax very well. Or try w3schools.com

    I know how you feel, I still get basic errors all the time, but you just need to read your code carefully. You'll eventually get consistant with the syntax

  13. #13
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, actually, on line 65 do this:

    echo $row['username']."<BR>");

  14. #14
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I will most likely wind up getting that book, I already took the PHP tutorial at w3schools... I always go there, any time I am considering learning a language... or learning one...

    changing it to

    PHP Code:
    echo $row['username']; 
    Worked... Thanks for your patience, and help!

    ~Jabird

  15. #15
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad I could help. Also with quotes. Use "" double quotes if there are instructions in the string, use '' if it's a literal string. This saves time on parsing.

    ie.

    $string = 'My dog is brown';


    //////

    $color = 'brown';
    $instruction = "My dog is $color";

  16. #16
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    EDIT: I got it fixed... heres what I changed line 65 too:
    echo $row['username'], ("<BR>");

    ^^Took out the . and added the Parenthesis (sp?) and added the comma... works now , thanks for all your help, and I will look into that book.

    cool, thanks for the info...

    but when I tried to make line 65:

    echo $row['username']."<BR>");

    ^Parse Error:

    Code:
    Parse error: parse error, unexpected ')', expecting ',' or ';' in /jabird/htdocs/phplearn/sql/first.php on line 65

  17. #17
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops, change line 65 to:

    echo $row['username']."<BR>";

    NO parenthesis are needed

  18. #18
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ya, I got that part figured out now... thank you...

    but now, I added ALOT more to that code, and now I get this parse error:

    Parse error: parse error, unexpected $ in /jabird/htdocs/phplearn/sql/first.php on line 103

    Code on line 103:
    </html>

    hmmm.... no $ in there :|

    I also even tried removing </html>... and it told me unexpected $ on line 102... (The </body> line)...

    I even moved </html> down ALOT, parse error on line 3093092 (No, thats not how far I moved it down... I just don't remember is all...)

    ~Jabird

  19. #19
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay there is an error somewhere in the code, but PHP doesn't know where, so it says the last readable line of code. that's why it followed the </html> tag. You'll need to post all of your code for me to debug it.

  20. #20
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $username
    ='removed';
    $password='removed';
    $hostname='removed';
    $databasename='removed';

    $connection = @mysql_connect($hostname$username$password);

    mysql_select_db($databasename);

    $sql "create table users(" .
    "ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " .
    "username text, ".
    "email text)";
    mysql_query($sql);

    $query="insert into user set username='$name', email='$email'";

    mysql_query($query);
    ?>
    Username&nbsp&nbsp|&nbsp&nbsp;Email Address<BR>
    <?php
    $selection 
    mysql_query("SELECT * FROM users");
    while ( 
    $row mysql_fetch_array($selection) ) {
    echo 
    $row['username'];
    ?>
    &nbsp&nbsp|&nbsp&nbsp
    <?php
    echo $row['email'], ("<BR>");
    }
    ?>
    <?php
    $sql 
    "create table data(" .
    "ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY, " .
    "data1 text, ".
    "data2 text)";
    mysql_query($sql);

    $query="insert into user set data='$data'";
    $query="insert into user set data='$about'";

    mysql_query($query)

    ?>
    Extracting data from a MySQL Table:
    <?php
    $selection 
    mysql_query("SELECT * FROM data");
    while ( 
    $row mysql_fetch_arrar($selection) ) {
    echo 
    $row['data'];
    ?>
    Thats ALL the code, except for the comments, and of course my website IP, username and password...

    Please tell me if I missed anything potentially harmful, if in the wrong hands, and I will remove it ASAP

  21. #21
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're missing the end bracket for your last while loop


    Extracting data from a MySQL Table:
    <?php
    $selection
    = mysql_query("SELECT * FROM data"
    );
    while (
    $row = mysql_fetch_arrar($selection
    ) ) {
    echo
    $row['data'
    ];
    }
    ?>

  22. #22
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't miss anything harmful, but one question is Where does $name and $email come from

    $_POST or $_GET or what?

  23. #23
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $name and $email, are the rows in the table I created earlier in the code... dunno if it is right...

    and, I also spelled "array", "arrar" lol

    Thanks for the help, it works now

    EDIT: Atleast, it works, until I decide to add something different too it

  24. #24
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great. Good luck learning PHP. It's worth it from here to buy the Harry Fuecks PHP Anthology. I bought it, and it's freaggin awesome.

    Eventually you'll want to delve into OOP and get away from Procedural programming. It's much more effecient and scalable.

    Have fun!

  25. #25
    011110010110000101111001 jabird's Avatar
    Join Date
    Aug 2004
    Location
    U.S.
    Posts
    593
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, I will make a little note about those 2 books... and look into some OOP (When I learn a little more about the basics...)

    Kinda sad, 104 lines of code, 4 lines of output

    Thanks again, for all your help

    ~Jabird


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
  •