Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with mysql and tables in a php user script

    K people I just join about 5 minutes ago wandering if someone on this forum could help me after googling for about 10 minutes i found this forum.

    My problem is if you go to my prototype layout of my website @ http://plasmasteelgames.zxq.net. you will see that in my navbar where it says "Welcome to Plasma Steel Games" and a login and register links it has two errors i have look at the code i don't know what to do to fix it and when you click on one of my link. let's say to register it opens the form up into the div object that the navbar is in and the navbar is gone. as you see the code for index.php the script uses the switch statement.

    here's the script for the mysql errors:

    config.php
    Code:
    <?php
    ob_start();
    //Allows us to use cookies on all of the pages
    
    /*
    iSuS - iScripting.net User System
    v1.0 made by Panzer
    http://www.iScripting.net
    Copyright must stay intact
    */
    
    //Get some additional functions
    include('functions.php');
    //*********************************************//
    //Length Of Time Cookie Lasts - 1 week default
    $cookieTime = time()+7*86400;
    //***********************************************//
    //Define The Salt
    define('SALT', 'k589fhj45g4r45f2f14df1sd1'); //Example k483hl2948hHe73
    
    //Path to index.php file , no following slash
    //Eg, if the index file were located at http://iscripting.net/isus/index.php - you would enter http://iscripting.net/isus
    $siteurl = "http://plasmasteelgames.zxq.net";
    
    //Your Website name, not the <title>
    $sitename = "Plasma Steel Games";
    
    //The default membergroup when someone registers.
    $defaultmembergroup = "user";
    
    //Database information
    $db_user = 'database_user;
    $db_pass = '';
    $db_host = 'hosting.zymic.com';
    $db_database = 'database;
    //**********************************************//
    
    //Connect to the database
    $connect = mysql_connect("$db_host","$db_user","$db_pass");
    
    if (!$connect ) echo 'There was an error connecting to the database';
    
    mysql_select_db("$db_database");
    
    
    // Get and authenticate their cookie information.
    $u1 = secure($_COOKIE['username']);
    $p1 = secure($_COOKIE['password']);
    
    //Check theyre logged in.
    $logged = mysql_query("SELECT * FROM users WHERE username = '$u1' AND password = '$p1'");
    
    $logged = mysql_fetch_array($logged, MYSQL_ASSOC);
    
    //Rename some of the $logged['variables'] with easier names.
    $uId = $logged['id'];
    $uName = $logged['username'];
    $uEmail = $logged['email'];
    $uMsn = $logged['msn'];
    $uIp = $logged['ip'];
    $uSignup = $logged['signup'];
    $uLevel = $logged['level'];
    $uGtalk = $logged['gtalk'];
    $uMsn = $logged['msn'];
    $uAim = $logged['aim'];
    $uLocation = $logged['location'];
    $uBio = $logged['bio'];
    $uGroup = $logged['gid'];
    $uMembergroup = $logged['membergroup'];
    
    //If the user isn't logged in, we'll set their name to guest and membergroup to guest as well so they don't screw anything up
    if (!$uName) {
    
    $uName = guest;
    $uMembergroup = guest;
    
    }
    //Get the permissions sorted out.
    $permquery1 = mysql_query("SELECT * FROM `permissions` WHERE mg_name = '$uMembergroup' ");
    $userCan = mysql_fetch_assoc($permquery1);
    
    $action = secure($_GET['action']);
    $sa = secure($_GET['sa']);
    $ssa = secure($_GET['ssa']);
    
    ?>
    and here's the code for the index page

    index.php
    Code:
    <html>
    <head>
    <title>Plasma Steel Games | Home</title>
    
    </head>
    <body BGcolor="#262626" text="#FFFFFF" LINK="#FF0000" VLINK="#FF0000" ALINK="#FF0000">
    
    <div id="header" align="center">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1000" height="202" id="LOGO_F" align="middle">
        <param name="allowScriptAccess" value="sameDomain" />
        <param name="allowFullScreen" value="false" />
        <param name="movie" value="http://plasmasteelgames.zxq.net/header/LOGO_F.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" />    <embed src="http://plasmasteelgames.zxq.net/header/LOGO_F.swf" quality="high" bgcolor="#000000" width="1000" height="202" name="LOGO_F" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
        </object>
    <br>
    </div>
    
    <div align="left">
    <b>Login</b>
    <br>
    <form method="post" action="index.php?action=login">
    
        <b>Username:</b><input type="text" name="username"><br />
    <br>
        <b>Password:</b><input type="password" name="password"><br />
       
        <input type="submit" name="login" value="Login">
    </form>
    </div>
    
    <br>
    <div id="navbar" align="left"
    <?php
    /*
    iSuS - iScripting.net User System
    v1.0 made by Panzer
    http://www.iScripting.net
    Copyright must stay intact
    */
    
    // Get the configuration file
    include ('config.php');
    
    //Set the navigation up, secure it's input.
    $nav = $_GET['action'];
    secure($nav);
    
    //Use a switch statement to go through the URLS.
    switch($nav)
    
        {
            case "login":
                include('login.php');
            break;
           
            case "logout":
                include ('logout.php');
                break;
               
            case "editprofile":
                include ('editprofile.php');
                break;   
               
            case "memberlist":
                include ('memberlist.php');
                break;
               
            case "register":
                include ('register.php');
                break;   
               
               
       
       
            default:
    echo "Welcome to $sitename $uName <br /><br />";
    if($uId) {
    echo "<b>Site Links</b><br /><br />";
    if($userCan['viewprofile'])
    echo "<a href='$siteurl/index.php?action=memberlist'>View Memberlist</a><br /><br /><br />";
    
    
    echo "<b>User Links</b><br />";
    
    echo "<a href='$siteurl/index.php?action=home'>Home</a><br />";
    echo "<a href='$siteurl/index.php?action=downloads'>Downloads</a><br />";
    echo "<a href='$siteurl/index.php?action=music'>Music</a><br />";
    echo "<a href='$siteurl/index.php?action=videos'>Videos</a><br />";
    echo "<a href='$siteurl/index.php?action=animations'>Animations</a><br />";
    echo "<a href='$siteurl/index.php?action=polls'>Polls</a><br />";
    echo "<a href='$siteurl/index.php?action=contact'>Contact Us</a><br />";
    
    echo "<a href='$siteurl/index.php?action=logout'>Logout</a><br />";
    
    if($userCan['editprofile'])
    echo "<a href='$siteurl/index.php?action=editprofile'>Edit Profile</a><br />";
    } else {
    
    echo "    <a href='$siteurl/index.php?action=login'>Login</a><br />
            <a href='$siteurl/index.php?action=register'>Register</a><br /> ";
    
                break;
        }
    }
    ?>
    </div>
    
    <br>
    <div id="counter" align="left">
    <a href="http://www.website-hit-counters.com/website-statistics.html" target="_blank">
    <img src="http://www.website-hit-counters.com/cgi-bin/image.pl?URL=55882-1649" alt="website statistics counter" border="0" >
    </a>
    <br>
    <font style="font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 9px; color: #330006; text-decoration: none;">
    <a href="http://www.website-hit-counters.com/website-statistics.html" target="_blank" style="font-family: Geneva, Arial, Helvetica, sans-serif;
    font-size: 9px; color: #555556; text-decoration: none;" title="web analytics">web analytics
    </a>
    </font>
    </div>
    </body>
    </html>
    Last edited by plasmagames; 05-21-2008 at 05:31 PM.

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Welcome to the forums.

    I strongly suggest you edit your post ASAP and remove the username, password and host data from your config.php script. You've essentially put your house keys on the mat and say 'please come into my house and do as you like'.

    Please look at the error codes output on the page; the relevant lines are shown, pointing the way to the function calls that are failing.

    The error itself tells you the two arguments are "not a valid MySQL result resource" - meaning the queries that those function calls rely on failed for some reason.

    I suggest you add this line after each one of the calls to mysql_query()

    PHP Code:
    echo '<p>' mysql_errno() .' : 'mysql_error() .'</p>'
    This will at least give you an idea as to why the queries are failing, then we can start from there.
    Last edited by bdl; 05-22-2008 at 06:13 AM. Reason: Bad bbcode.

  • #3
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks

  • #4
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I says no database selected

  • #5
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you can look yourself @ Click Here

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    mysql_select_db(databasename); 
    Example from PHP.NET
    PHP Code:
    $link mysql_connect('localhost''mysql_user''mysql_password');
    if (!
    $link) {
        die(
    'Not connected : ' mysql_error());
    }

    // make foo the current db
    $db_selected mysql_select_db('foo'$link);
    if (!
    $db_selected) {
        die (
    'Can\'t use foo : ' mysql_error());
    }
    ?> 

  • #7
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    know how can i work that into my code

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    $db_database = 'database;
    I says no database selected
    Make sure that you have a mysql databse in that host named database

    Oh.. wait ,there is a syntax error in the above code, missing one semicolon. Please follow http://www.codingforums.com/showthread.php?t=68462(on how to post php code in this forum) and edit your post accordingly.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    PHP Code:
    <?php
    ob_start
    ();
    //Allows us to use cookies on all of the pages

    /*
    iSuS - iScripting.net User System
    v1.0 made by Panzer
    http://www.iScripting.net
    Copyright must stay intact
    */

    //Get some additional functions
    include('functions.php');
    //*********************************************//
    //Length Of Time Cookie Lasts - 1 week default
    $cookieTime time()+7*86400;
    //***********************************************//
    //Define The Salt
    define('SALT''k589fhj45g4r45f2f14df1sd1'); //Example k483hl2948hHe73

    //Path to index.php file , no following slash
    //Eg, if the index file were located at http://iscripting.net/isus/index.php - you would enter http://iscripting.net/isus
    $siteurl "http://plasmasteelgames.zxq.net";

    //Your Website name, not the <title>
    $sitename "Plasma Steel Games";

    //The default membergroup when someone registers.
    $defaultmembergroup "user";

    //Database information
    $db_user 'database_user';
    $db_pass '';
    $db_host 'hosting.zymic.com';
    $db_database 'database';
    //**********************************************//

    //Connect to the database
    $link mysql_connect("$db_host","$db_user","$db_pass");
    if (!
    $link) {
        die(
    'Not connected : ' mysql_error());
    }





    // Get and authenticate their cookie information.
    $u1 secure($_COOKIE['username']);
    $p1 secure($_COOKIE['password']);

    //Check theyre logged in.
    $logged mysql_query("SELECT * FROM users WHERE username = '$u1' AND password = '$p1'");

    $logged mysql_fetch_array($loggedMYSQL_ASSOC);

    //Rename some of the $logged['variables'] with easier names.
    $uId $logged['id'];
    $uName $logged['username'];
    $uEmail $logged['email'];
    $uMsn $logged['msn'];
    $uIp $logged['ip'];
    $uSignup $logged['signup'];
    $uLevel $logged['level'];
    $uGtalk $logged['gtalk'];
    $uMsn $logged['msn'];
    $uAim $logged['aim'];
    $uLocation $logged['location'];
    $uBio $logged['bio'];
    $uGroup $logged['gid'];
    $uMembergroup $logged['membergroup'];

    //If the user isn't logged in, we'll set their name to guest and membergroup to guest as well so they don't screw anything up
    if (!$uName) {

    $uName guest;
    $uMembergroup guest;

    }
    //Get the permissions sorted out.
    $permquery1 mysql_query("SELECT * FROM `permissions` WHERE mg_name = '$uMembergroup' ");
    $userCan mysql_fetch_assoc($permquery1);

    $action secure($_GET['action']);
    $sa secure($_GET['sa']);
    $ssa secure($_GET['ssa']);

    ?>
    i edited this

    $db_user = 'database_user';
    $db_pass = '';
    $db_host = 'hosting.zymic.com';
    $db_database = 'database';

    and added this $link = mysql_connect("$db_host","$db_user","$db_pass");
    if (!$link) {
    die('Not connected : ' . mysql_error());
    }


    you missed ' of the end... might be just as you where deleting the names but you never know!

  • #10
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    now i get this
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/zxq.net/p/l/a/plasmasteelgames/htdocs/config.php on line 55
    
    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /www/zxq.net/p/l/a/plasmasteelgames/htdocs/config.php on line 82
    Welcome to Plasma Steel Games guest

  • #11
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you didn't change it in the code that you posted then change it

  • #12
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Both of your queries are failing. Also why would you store the username and password in a cookie? Cookies can be viewed by the user. Its better to use sessions as they stay on your server. As to your problem do some error checking.
    PHP Code:
    $logged mysql_query("SELECT * FROM users WHERE username = '$u1' AND password = '$p1'") or die(mysql_error()); 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #13
    New Coder
    Join Date
    May 2008
    Location
    Canada
    Posts
    82
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got this system pre-made but the coder is working on a better version though


  •  

    Posting Permissions

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