Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Some help with some php mysql communication.

  1. #1
    Sheepoholics's Avatar
    Sheepoholics is offline x10 Sophmore
    Join Date
    Dec 2005
    Location
    Beaumont AB
    Posts
    133

    Some help with some php mysql communication.

    Okay so I'm trying to make a online store using php mysql and flash but I can't seem to get tit to work.



    Code:
    Warning:  mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /backup/home/mitchell/public_html/products.php on line 12
    This is the code in its entirty

    PHP Code:
    <?php

    $link 
    mysql_connect("localhost","*****_*****","*****");
    mysql_select_db("mitchell_test");

    $query 'SELECT * FROM products';
    $results mysql_query($query);

    echo 
    "<?xml version=\"2.0\"?>\n";
    echo 
    "<products>\n";

    while(
    $line mysql_fetch_assoc($results)) {
        echo 
    "<item>" $line["product"] . "</item>\n";
    }

    echo 
    "</products>\n";

    mysql_close($link);

    ?>
    Asterixs are the username and password for the database.

    Basically what the code should do is display the names of all the rows in the table. But All I get is the error.
    this is just the begining steps to my project from here the php will create some xml which the flash file will read.
    Last edited by Sheepoholics; 03-30-2006 at 03:43 AM.

  2. #2
    Jake's Avatar
    Jake is offline Developer
    Join Date
    Apr 2005
    Location
    Winona, MN
    Posts
    2,092

    Re: Some help with some php mysql communication.

    just use mysql_fetch_array() ;)
    Jake Omann | Developer
    █ 888-X10-9668 - jake[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  3. #3
    Sheepoholics's Avatar
    Sheepoholics is offline x10 Sophmore
    Join Date
    Dec 2005
    Location
    Beaumont AB
    Posts
    133

    Re: Some help with some php mysql communication.

    Now I get the same error except with Mysql_fetch_array() instead of mysql_fetch_assoc()
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /backup/home/mitchell/public_html/products.php on line 12
    I'm really confused.

  4. #4
    Jake's Avatar
    Jake is offline Developer
    Join Date
    Apr 2005
    Location
    Winona, MN
    Posts
    2,092

    Re: Some help with some php mysql communication.

    try:

    Code:
    $results = mysql_query("SELECT * FROM `products`);
    
    echo "<?xml version=\"2.0\"?>\n";
    echo "<products>\n";
    
    while($line = mysql_fetch_array($results)) {
        echo "<item>" . $line['product'] . "</item>\n";
    }
    
    echo "</products>\n";
    Jake Omann | Developer
    █ 888-X10-9668 - jake[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  5. #5
    Sheepoholics's Avatar
    Sheepoholics is offline x10 Sophmore
    Join Date
    Dec 2005
    Location
    Beaumont AB
    Posts
    133

    Re: Some help with some php mysql communication.

    Now it thinks that the "?" is a parse error. It's telling me:

    Code:
    Parse error:  syntax error, unexpected '?' in /backup/home/mitchell/public_html/products.php on line 8
    Last edited by Sheepoholics; 03-30-2006 at 04:05 AM.

  6. #6
    clareto is offline x10 Sophmore
    Join Date
    Oct 2005
    Posts
    125

    Re: Some help with some php mysql communication.

    dont output the line that declares the document as xml with an "echo". Do it outside the php

    Code:
     
    <?php
     
    ... (code to initialize the db) 
    // next line starts the output 
    ?>
     
    <?xml version= ... ?>
     
    <?
     
    ... (php code that makes the xml schema)
     
     
    ?>

  7. #7
    Jake's Avatar
    Jake is offline Developer
    Join Date
    Apr 2005
    Location
    Winona, MN
    Posts
    2,092

    Re: Some help with some php mysql communication.

    yes that works well too. i normally try to minimize echo statements but when its 3am your kinda tired

    and use <br> instead of \n
    Last edited by Jake; 03-30-2006 at 11:29 AM.
    Jake Omann | Developer
    █ 888-X10-9668 - jake[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  8. #8
    Bryon is offline Administrator
    Join Date
    Apr 2005
    Posts
    7,724

    Re: Some help with some php mysql communication.

    Just for future reference, if your getting an error from a MySQL "result" function, try using "or die(mysql_error())" after your mysql_query(). You might have something wrong in your actual query, which causes nothing to be returned from the MySQL server, which could possibly be the cause of the error from mysql_fetch_array().

    PHP Code:
    ...
    $blah mysql_query("QUERY HERE") or die(mysql_error());
    ... 
    (If you didn't know.)


    Also you are getting that error because you forgot the "ending quote" in your MySQL query:

    PHP Code:
    // Should Be:
    $results mysql_query("SELECT * FROM `products`");

    // Was:
    $results mysql_query("SELECT * FROM `products`); 
    ;)

  9. #9
    Jake's Avatar
    Jake is offline Developer
    Join Date
    Apr 2005
    Location
    Winona, MN
    Posts
    2,092

    Re: Some help with some php mysql communication.

    woops 3am mistake
    Jake Omann | Developer
    █ 888-X10-9668 - jake[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  10. #10
    Sheepoholics's Avatar
    Sheepoholics is offline x10 Sophmore
    Join Date
    Dec 2005
    Location
    Beaumont AB
    Posts
    133

    Re: Some help with some php mysql communication.

    Alright I got it all figured out. Just some little things needed fixing First off I needed to be selecting from a table that had and INT row. So after I fixed that and used or die(mysql_error()); (thanks for that Bryon) it was much easier to find the problem. And thanks to jake for all of the 3am help.

Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 45
    Last Post: 02-09-2013, 09:45 PM
  2. tons of PHP Resources
    By Chris S in forum Scripts, 3rd Party Apps, and Programming
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  3. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 PM
  4. Have a problem with my forum
    By tikloos in forum Scripts, 3rd Party Apps, and Programming
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM
  5. Php And Mysql Forum Rephrased!
    By maddude in forum Scripts, 3rd Party Apps, and Programming
    Replies: 7
    Last Post: 04-05-2005, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers