SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 56

Thread: Script problems

  1. #1
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Script problems

    ok im trying to run a mailing list : this is my table :

    create table list(
    id int(11) not null auto_increment,
    first varchar(20) not null,
    last varchar(20) not null,
    email varchar(20) not null,
    key id (id)
    ) type=myisam;

    this is my script for inserting into.. i got a form with 3 text boxed called first,last, and email actioned to open this page :

    <?
    $username="******";
    $password="******";
    $database="******";

    mysql_connect(localhost,$username,$password);
    mysql_select_db($database) or die( "Unable to select database");

    $query = "INSERT INTO list VALUES ('$first','$last','$email')";
    mysql_query($query);

    mysql_close();
    ?>

    then this is my display page :

    <html>
    <?
    $username="*********";
    $password="********";
    $database="*********";

    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $query="SELECT ID, First, Last, email FROM list where status = 1";
    $result=mysql_query($query);
    while($row = mysql_fetch_array($result))
    echo $row["ID"], $row["first"], $row["last"], $row["email"], "<br>\n";

    mysql_close();

    ?>
    <body>
    </body>
    </html>


    when i open display.php it tells me :

    Warning: Supplied argument is not a valid MySQL result resource in /users/iwebland.com/scars/display.php on line 12


    somebody help me, there is obviously something wrong here
    Last edited by Weblife; Jul 31, 2002 at 08:52.

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dude, MySQL and PHP are case sensitive. You have to mkae sure the fields in your query are EXACTLY what they are in your db or the query will fail resulting in an invalid mysql resource.

    Also, in your connection, make sure you put localhost in quotes.

    Aaron
    Aaron Brazell
    Technosailor



  3. #3
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thx alot il try that

  4. #4
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i did what u said and it stil gives me same error...

    please note it says Line 12...... help me out

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    according to your code, line 12 is ?> which I don't reckon is really the case. How bout you tell me what line 12 is...

    Sketch
    Aaron Brazell
    Technosailor



  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cambs, UK
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably not the answer but dont you need some brackets or a ;/: endwhile; in there?
    Jo

  7. #7
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is in your while(); statement. It misses the curly braces -- { } these boys .

  8. #8
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mark if your while only contains one line then you don't need braces. (same applies for for and if/else)

    PHP Code:
    while(bla is true)
       
    bla bla
    is fine.

    The problem is your echo statement, try:

    PHP Code:
    echo $row["ID"].","$row["first"].","$row["last"].","$row["email"].", <br>\n"
    Last edited by kix; Jul 31, 2002 at 06:18.

  9. #9
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Weblife, while most peeps here are lovely and fluffy, you never know who's reading. I have removed your mysql connection details for your security - would suggest that in future you edit them out before posting
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  10. #10
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    H, you in particular are lovely and fluffy...



    Sketch
    Aaron Brazell
    Technosailor



  11. #11
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by kix
    Mark if your while only contains one line then you don't need braces. (same applies for for and if/else)
    That's new, not my preferred method of coding but alas .

    H', thanks for removing!

    - Edit -

    Nanaman reminds me of Mr. Nod

  12. #12
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Sketch
    H, you in particular are lovely and fluffy...



    Sketch


    Any excuse to use the banana smiley
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  13. #13
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure...had to sneak it into the PHP forums...

    Sketch
    Aaron Brazell
    Technosailor



  14. #14
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Mark T.


    That's new, not my preferred method of coding but alas .
    can't say I much like it myself...

  15. #15
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys il try them all.. but seriously just gonna say that putting the mysql database and password in my post is one of the dumbest things ive ever done in my life



    il answer again when i find out if it works or not

  16. #16
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <html>
    <?
    $username="*****";
    $password="*****";
    $database="******";

    mysql_connect("localhost",$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");

    $query="SELECT ID, first, last, email FROM list where status = 1";
    $result=mysql_query($query);
    while($row = mysql_fetch_array($result))
    echo $row["ID"].",". $row["first"].",". $row["last"].",". $row["email"].", <br>\n";

    mysql_close();

    ?>
    <body>
    </body>
    </html>


    thats now my script, but it gives me the same damn error

  17. #17
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    WebLife,

    The error looks to fall on your WHILE line - which could mean that you do not have any records and therefore it fails at trying to process no records in a while loop.

    I would suggest checking that you do have some results in your tables which suit the condition status=1.

    Also add in this code, so that it won't process any further if no results are obtained. The mysql_error part is only there incase you have an error in your sql code and hopefully the error message will tell you exactly where.
    PHP Code:
    $query="SELECT ID, First, Last, email FROM list where status = 1";
    $result=mysql_query($query);
      if (!
    $result) {
        echo(
    "No results sorry" mysql_error());
        exit;
      }
    while(
    $row mysql_fetch_array($result))
    echo 
    $row["ID"], $row["first"], $row["last"], $row["email"], "<br>\n"
    Sarah
    Regular user

  18. #18
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks

    but if theres no results in the database, that makes no sence

    that would meen that there is something wrong with my script for adding files.. please check it over.. because ive entered many things in those text boxes as tests... please help

  19. #19
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i did what u said with display.php and when i open it now it says :

    No results sorryTable 'DB_nac51621.list' doesn't exist

    thats very troubleing.. i created the table list.. its in my mysql data

    and db_nac51621 is the mysql database that coolfreepages.com gave me

    help me out please

  20. #20
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anybody? please help

  21. #21
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check $database and make sure you have the correct value.
    Cause if you're selecting the wrong database, it'd give you that error.

    also, try this for your connection:
    PHP Code:
    mysql_connect("localhost",$username,$password) or die("Could not connect - " mysql_error());
    mysql_select_db($database) or die("Could not select database " $database " - " .mysql_error()); 
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  22. #22
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it says
    :

    No results sorryTable 'DB_nac51621.list' doesn't exist

    but it does exist.. its in my mysql data file...

    database name is mailing_list and the table is called list

    did i do anything wrong?

  23. #23
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i did a few things and now when i open display.php it tells me

    No results sorryUnknown column 'status' in 'where clause'

  24. #24
    SitePoint Zealot
    Join Date
    May 2002
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but i had went through the forms to add results to the database with tests many times, so if thers no results theres obviously something wrong with database

  25. #25
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Try this...

    PHP Code:
    $connection mysql_connect("localhost",$username,$password);
      
    $db = @mysql_select_db($database$connection) or die( "Unable to select database");

      
    $query "SELECT ID, first, last, email FROM list where status = 1";
      
    $result mysql_query($query$connection);
      while(
    $row mysql_fetch_array($result))
        echo 
    $row["ID"].","$row["first"].","$row["last"].","$row["email"].", <br>\n";
    mysql_close(); 
    John
    John


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
  •