Results 1 to 7 of 7

Thread: strange error

  1. #1
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default strange error

    PHP Code:
    <table>
    <tr><td width=200><b><u>Your Current Stocks:</u></b></td></tr><?php 
    $stockmarket
    ="mysql_query(select * from stocks where $userstats3[ID]='Owner')";
    $stockup="mysql_fetch_array($stockmarket)";
    ?>
    <tr><td>Name: Law And Order</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Law And Order"){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: P.A.F.A.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="P.A.F.A."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Crime Investigators Inc.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Crime Investigators Inc."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Whore House Co.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Whore House Co."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Ghetto Mart Inc.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Ghetto Mart Inc."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Weapons Co.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Weapons Co."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Pimp Inc.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Pimp Inc."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Playboy Inc.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Playboy Inc."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Homeless Rights Inc.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Homeless Rights Inc."){ echo "$stockup[Shares]"; } ?></td></tr>
    <tr><td>Name: Black Market Co.</td><td width=100></td><td>Shares: <?php if($stockup[Name]="Black Market Co."){ echo "$stockup[Shares]"; } ?></td></tr>
    </tr></table>
    why is this code printing the following:

    Code:
    Name: Law And Order  Shares: L 
    Name: P.A.F.A.  Shares: P 
    Name: Crime Investigators Inc.  Shares: C 
    Name: Whore House Co.  Shares: W 
    Name: Ghetto Mart Inc.  Shares: G 
    Name: Weapons Co.  Shares: W 
    Name: Pimp Inc.  Shares: P 
    Name: Playboy Inc.  Shares: P 
    Name: Homeless Rights Inc.  Shares: H 
    Name: Black Market Co.  Shares: B
    http://www.insanecombat.com << bored? check out ma game

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What's strange about it? You're assigning strings there, never actually performing a query. Also, where are the constants ID and Shares defined?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2007
    Location
    Earth
    Posts
    133
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default

    do you mind telling me how to fix it? lol i know theres stuff wrong with it
    http://www.insanecombat.com << bored? check out ma game

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Your code is wrong in very basic ways such that I'm not entirely certain what you're trying to do. The PHP tutorial might help you.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    1. Quotes do not go around functions.
    A random number, for example:
    $a = rand(0,1);
    Not "rand(0,1)"

    2. You will need quotes on any of the keys for the arrays--
    $array['key']

    You could define a constant, but you haven't done so and there is no need.
    (define('name',$value), if you want...)

    3. = is NOT the same as ==.
    $a=2 will always return true. That sets the value. Or, rather, it will return true if there is no error setting the value.
    2=3 will get an error, because you can't redefine a constant.
    2==2 will return TRUE*, and 2==3 will return FALSE*.
    *However, these are general results. If you use == (or != [not]), then you will get a result equivalent to 0, '' [empty string], FALSE or null on failure and TRUE, 1, [a string], etc. on success.
    Using === or !== will give you a precise answer, where it will be only one of the return types, like 0 or [xor] FALSE.
    Now, don't worry much about this for now. == will usually do the job.

    4. Using "$array['key']" is generally invalid and you'll need to escape the parsing. Use it like "string".$array['key']."string";

    And, yes, take a look at a tutorial to get started.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    4. Using "$array['key']" is generally invalid and you'll need to escape the parsing. Use it like "string".$array['key']."string";
    "{$array['key']}" is perfectly acceptable.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Not as it was in the above text, though.
    I prefer ending the quotes and doing it outside rather than messing with brackets. More confusing to me if I'm using brackets.
    Personal preference, though, yes.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •