Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    Hi guys,
    Just Bought "PHP with MySQL by Nat Macbride and I'm having a few Difficultys.
    PHP Code:
    <? include 'sqlconnect.php' ?>
    <? $select 
    "SELECT first_name, last_name
    FROM customers
    WHERE id = 1 ;
    $result = mysql_query($link,$select);
    $row = mysql_fetch_array($result) ;
    $fn = $row['first_name'] ;
    $ln = $row['last_name'] ;
    echo"
    First Name$fn 
    <br/>
    Last Name$ln "
    ?>

    Wrote this code from the book and am getting the following error:
    Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in main.php on line 8
    please could someone help me solve this issue as im getting really frustrated :angry:
    Regards Phil,


  2.  

  3. #2
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    Ok Solved That Problem with this code

    PHP Code:
    <? include 'sqlconnect.php' ?>
    <? $select 
    "SELECT first_name, last_name
    FROM customers
    WHERE id = 1 ;
    $result = mysql_query($link,$select);
    $row = mysql_fetch_array($result) ;
    $fn = $row ['first_name'];
    $ln = $row ['last_name'];
    echo"
    First Name $fn Last Name $ln "
    ?>
    But i now get Parse Error unexpected T_STRING on line 14
    Regards Phil,


  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey.

    When you include a file, the contents of that file will affect the line that you are told the error is on. Just so you now.

    Your problem is that you are missing a closing " in your query. Try this:

    PHP Code:
    <?php
      
    include 'sqlconnect.php';
    $select "SELECT first_name, last_name FROM customers WHERE id = 1";
    $result mysql_query($link,$select);
    $row mysql_fetch_array($result) ;
    $fn $row ['first_name'];
    $ln $row ['last_name'];
    echo
    "First Name $fn Last Name $ln ";
    ?>
    Works for me.

  5. #4
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    Sorry about this noobish error
    Regards Phil,


  6. #5
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    Ok now solved all of the other issues including updating for latest PHP and MySQL versions with the following code:
    PHP Code:
    <?php
    include 'sqlconnect.php';
    $select "SELECT first_name, last_name FROM customers WHERE id = 1";
    $result "mysqli_query($link,$select)" ;
    $row "mysqli_fetch_array($result)" ;
    $first $row ['first_name'] ;
    $last $row ['last_name'] ;
    echo
    "First Name $first Last Name $last ";
    "mysqli_close($link)"
    ?>
    and now get the following
    First Name m Last Name m
    yet in the database "id 1 is First Name Dave then Last Name Burton
    any ideas
    and also do i need double quotes (") around the variables that define where "first_name" and "last_name" go
    Regards Phil,


  7. #6
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    What's the myslqi_... for ? Isn't it just mysql_...

    Try

    PHP Code:
    echo 'First Name '.$first.' Last Name '.$last
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us

  8. #7
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    This didnt work as im still getting the output
    First Name m Last Name m
    wheras I should be getting
    First Name: Scott Last Name: Lumley
    About hte mysqli_ its changed in the latest version of PHP
    Regards Phil,


  9. #8
    Senior Member karinne's Avatar
    Join Date
    Dec 2003
    Location
    Aylmer QC Canada
    Posts
    1,607
    Member #
    4335
    Liked
    8 times
    Ok... I hope you didn't put the BEGIN__VBULLETIN__CODE__SNIPPET .. not sure why that's there. Just the echo part that I wanted to show you.
    [a web design portfolio - Currently NOT AVAILABLE for work | web design | Re-coding | PSD-to-HTML]
    I'm also on: virb - facebook - twitter - flickr - del.icio.us

  10. #9
    Senior Member leprechaun13's Avatar
    Join Date
    May 2005
    Location
    Northampton
    Posts
    487
    Member #
    10058
    no i didnt put the BEGIN__VBULLETIN__CODE__SNIPPET as i didint get that in my browser
    Regards Phil,


  11. #10
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Quote Originally Posted by karinne
    Ok... I hope you didn't put the BEGIN__VBULLETIN__CODE__SNIPPET .. not sure why that's there. Just the echo part that I wanted to show you.
    The software powering these forums tends to add that for no reason sometimes.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:57 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com