+ Reply to Thread
Results 1 to 6 of 6

Thread: need help with mysql data base

  1. #1
    gamewars is offline x10Hosting Member gamewars is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    16

    need help with mysql data base

    my web site is http://gamewars.x10hosting.com/ click xbox button and post wars button and enter in any old info and you will see what is going wrong. Basically im getting an error and im not entering my data base name i guess correctly. plz help

  2. #2
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: need help with mysql data base

    You have to post all your PHP code related to the error (omitting the SQL user/pass) for us to help you

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: need help with mysql data base

    Not so much all the related code as a minimal test case, along with other pertinent and relevant information, such as the behavior you expect and the behavior you get, including error messages. Don't make us do extra work.

    Remember to search the forums and the web at large before posting. If you're dealing with an error message, it makes searching particularly easy.
    Last edited by misson; 08-10-2009 at 03:07 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    gamewars is offline x10Hosting Member gamewars is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    16

    Re: need help with mysql data base

    i have searched all over the internet but this problem is not going to be solved by searching the internet i dont know how to enter my database name username and password on my php code but heres the code




    <?php
    $con = mysql_connect("gamewars_xbox360postedwars","gamewa rs_gamewars","xxxxxx");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("my_db", $con);

    $sql="INSERT INTO Persons (Game, Gamertag, Time and Date, Number of rounds, Number of players)
    VALUES
    ('$_POST[firstname]','$_POST[lastname]','$_POST[quantity]','$_POST[items]','$_POST[players]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?>
    Last edited by gamewars; 08-10-2009 at 04:27 PM.

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: need help with mysql data base

    Code:
    $con = mysql_connect( 'localhost', 'gamewars_gamewars' , 'yoursecretpasswd');
     
    mysql_select_db("my_db");

    The first term is the location of the mysql server. In your case, it is probably 'localhost'.
    If you posted your real password, please change it.

    Finally, look at the mysqli interface
    Last edited by descalzo; 08-10-2009 at 02:12 PM.
    Nothing is always absolutely so.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: need help with mysql data base

    Whatever ancient tutorials keep screwing up people's code with terrible examples need to be hunted down and shot.

    You neglected to post the error. Here it is, for people searching for this error in the future:
    Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'gamewars_xbox360postedwars' (4) in /home/gamewars/public_html/postwarsxbox360.php on line 2
    Could not connect: Can't connect to MySQL server on 'gamewars_xbox360postedwars' (4)
    You really shouldn't make us wait for the connection to time out to get the error when you could have easily posted it yourself.

    The server name (the first argument to mysql_connect) should be "localhost". "gamewars_xbox360postedwars" looks like the DB name. Rather than looking at the documentation for mysql_connect, instead use PDO (PHP Data Objects). The mysql driver was been succeeded by mysqli, which has been succeeded in turn by PDO.

    Your script is also vulnerable to SQL injection ([2], [3]). Prepared statements (available with PDO and mysqli) mean you don't need to worry about sanitizing.

    If you have spaces in a column name, you need to enclose it in backquotes ("`"), otherwise the query will fail with an SQL syntax error.

    Don't use die in production code.

    Move the DB connection code to another script to isolate the user credentials and prevent typos from causing problems.

    PHP Code:
    # localDB.php defines local_db_connect
    include_once('localDB.php')

    # the following should be abstracted away into classes
    $fields=array_intersect(
      array(
    'firstname' => 'Game''lastname' => 'Gamertag'
            
    'quantity' => 'Time and Date'
            
    'items' => 'Number of rounds''players' => 'Number of players'),
      
    $_POST
    );

    # define 'validate()' elsewhere and fill out function call here.
    $errors validate($_POST, ...);

    if (
    count($errors)) {
        foreach (
    $errors as $name => $msg) {
            
    # reprint the form, with error messages inlined.
        
    }
    } else {
       
    # this code in particular should be refactored into classes
        
    try {
            
    $db local_db_connect('pdo', array('db' => 'gamewars_xbox360postedwars'));
            
    $db->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);

            
    # Note: the following four lines could be done in one, but have been separated 
            # for readability.
            
    $columnClause '`' implode('`, `'$fields) . '`';
            
    $valueClause ':' implode(', :'array_keys($fields)) ;
            
    $query "INSERT INTO Players ($columnClause) VALUES ($valueClause)"
            
    $stmt $db->prepare($query);

            
    $stmt->execute($_POST);

        } catch (
    PDOException $pdoe) {
            
    # error reporting should be abstracted away into a function or class
            
    $errorMsg __FILE__ '@' __LINE__ ':' $pdoe->getMessage();
            
    error_log($errorMsg);
            
    # note: $siteAdmin and $from need to be set somewhere, a strong argument for a class.
            
    mail($siteAdmin$from"Script error on $_SERVER[SERVER_NAME]",$errorMsg);
            echo 
    "Internal error. It's been logged, ";
        }

    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. Replies: 14
    Last Post: 09-29-2008, 07:07 PM
  3. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  4. MySQL data base stuff....
    By BrandonC in forum Free Hosting
    Replies: 1
    Last Post: 12-10-2007, 12:28 AM
  5. Replies: 2
    Last Post: 11-20-2007, 11:15 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
x10hosting free hosting for the masses
dedicated servers