...

View Full Version : Problem with mysql and tables in a php user script



plasmagames
05-21-2008, 03:52 AM
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

<?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

<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>

bdl
05-21-2008, 04:55 AM
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() (http://www.php.net/mysql_query)



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.

plasmagames
05-21-2008, 05:32 PM
thanks

plasmagames
05-24-2008, 12:48 AM
I says no database selected

plasmagames
05-24-2008, 12:50 AM
you can look yourself @ Click Here (http://plasmasteelgames.zxq.net/config.php)

rafiki
05-24-2008, 02:12 AM
mysql_select_db(databasename);
Example from PHP.NET
$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());
}
?>

plasmagames
05-24-2008, 05:37 PM
know how can i work that into my code

abduraooft
05-24-2008, 06:30 PM
$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.

runnerjp
05-24-2008, 10:14 PM
<?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($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']);

?>

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!

plasmagames
05-27-2008, 05:40 PM
now i get this

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

plasmagames
05-27-2008, 05:41 PM
if you didn't change it in the code that you posted then change it

_Aerospace_Eng_
05-27-2008, 06:37 PM
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.

$logged = mysql_query("SELECT * FROM users WHERE username = '$u1' AND password = '$p1'") or die(mysql_error());

plasmagames
06-01-2008, 04:24 AM
I got this system pre-made but the coder is working on a better version though



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum