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 16
  1. #1
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    I can't figure out the problem. The code below is called when I submit a form with the variables listed in that code.
    PHP Code:
    <?php
    if($submit//If submit is hit
    {
    $sqlhost "localhost";
    $sqllogin "*****";
    $sqlpass "******";
    $sqldb "******";

    $db mysql_connect($sqlhost$sqllogin$sqlpass) or die("OOps!");
    mysql_select_db($sqldb$db);

    $sql 'INSERT INTO `wplanet_freestuff` ( `id` , `resource_name` , `resource_url` , `description` ,
    `type` , `added` , `ammount` , `ads_for_service` , `banner_size` , `ratio` , `user_email` ,
    `demo_button` , `demo_url` ) VALUES ( \'\', \'$resource_name\', \'$resource_url\',
    \'$description\', \'$type\', \'NOW()\', \'$ammount\', \'$ads_for_service\',
    \'$banner_size\', \'$ratio\',
    \'$user_email\', \'$demo_button\', \'$demo_url\' ); '

    $result mysql_query($sql) or die("Failed");
    print 
    "OK,done";
    }
    ?>
    I get Failed msg,
    Database connection and details are correct.
    Can you point out the error ???
    When I put the $sql query on phpmyadmin, it works
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Echo the query and copy/paste it here (also please don't have it span so much).
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    The first quote before INSERT INTO needs to be a 2x quote ( " ) Like so:
    PHP Code:
    <?php
    if($submit//If submit is hit
    {
    $sqlhost "localhost";
    $sqllogin "*****";
    $sqlpass "******";
    $sqldb "******";

    $db mysql_connect($sqlhost$sqllogin$sqlpass) or die("OOps!");
    mysql_select_db($sqldb$db);

    $sql "INSERT INTO 'wplanet_freestuff' ( 'id' , 'resource_name' , 'resource_url' , 'description' ,
    'type' , 'added' , 'ammount' , 'ads_for_service' , 'banner_size' , 'ratio' , 'user_email' ,
    'demo_button' , 'demo_url' ) VALUES ( '', '
    $resource_name', '$resource_url',
    '
    $description', '$type', 'NOW()', '$ammount', '$ads_for_service',
    '
    $banner_size', '$ratio',
    '
    $user_email', '$demo_button', '$demo_url' ); "
    $result mysql_query($sql) or die("Failed");
    print 
    "OK,done";
    }
    ?>

    And it looks like for wplanet_freestuff table you have used ` (the button to the left of the "1" key) instead of the single quote. Try copy/paste the above code and see if that helps.
    - Brian

  5. #4
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    PS: Sorry about the stretch filb
    - Brian

  6. #5
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    I tried it, but no result
    Now I get a blank screen.
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  7. #6
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    Check your database, see if the test info is in there.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  8. #7
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    I think I figured it out!

    This line in your original code:
    [minicode]$result = mysql_query($sql)[/minicode]
    should be changed to:
    [minicode]$result = mysql_query($sql, $db)[/minicode]

    Try that out, hope it works.
    - Brian

  9. #8
    Senior Member Seldimi's Avatar
    Join Date
    Dec 2002
    Location
    Kozani, Greece
    Posts
    488
    Member #
    409
    Hmm, why we need $db as the value for $sql is the database name ? (Didn't try, just asking ...)
    - Webmaster's Planet . Greek Vortal For Webmasters ...
    - MyPortFolio - View My Creations

  10. #9
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    I checked how you access your db against how I access mine.
    Your SQL looks okay, I was just thrown off by the color change at first ( I didn't realize that it was because of the php variables ), the only thing I saw that was different was the mysql_query line.

    From PHP.net:
    resource mysql_query ( string query [, resource link_identifier])


    mysql_query() sends a query to the currently active database on the server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is assumed. If no link is open, the function tries to establish a link as if mysql_connect() was called with no arguments, and use it. The result of the query is buffered.
    It says that you don't need the link_identifier but I would try and see if it works anyway.
    - Brian

  11. #10
    Senior Member Brak's Avatar
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    3,413
    Member #
    1217
    Liked
    2 times
    Your problem inlies in the "`" some versions of mysql don't support it or something... I don't know exactly why/how, but that's just how it is. Try getting rid of them, you don't need them anyway because your column names don't have spaces.
    Kyle Neath: Rockstar extraordinare
    The blog | The poetry site | The Spore site


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 04:51 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com