techclave
Jan 16 2007, 05:48 AM
Hello ,. I am trying to install a game script on my site. I am new to creating mysql databases and adding tables to them. I kind of tried and went through most of the procedures without any errors. But i am stuck up in one place, where i am trying to add games to my site through an admin control panel. Whenever i try to add a game , i get the error QUOTE Warning: mysql_insert_id() [function.mysql-insert-id]: A link to the server could not be established in /home/techclav/public_html/games/admincp/admin.class.php on line 163 I tried googling t know about this error,. but i am not able to fix it. I would be grateful if one of the php geeks out here , helps me to fix it. Here is my admin.class.php file CODE <?php
require("../system.class.php");
$sys = new GamesSystem(1);
class GamesAdmin {
var $output_message; function GamesAdmin(){ $this->output_message = ''; if(isset($_GET['cmd'])){ if(isset($_GET['cmd']) && $_GET['cmd'] == 'nc' || $_GET['cmd'] == 'ng' || $_GET['cmd'] == 'ulswf' || $_GET['cmd'] == 'ulimg'){ if(isset($_GET['cmd']) && isset($_POST['input'])){ $exec = $this->add($_POST['input']); $t = 0; $f = 0; for($i=0;$i<count($exec);$i++){ if($exec[$i] != true){ $f++; } else { $t++; } } switch($_GET['cmd']){ case 'nc': $this->output_message .= '<strong>Adding Category: </strong>'; break; case 'ng': $this->output_message .= '<strong>Adding Game: </strong>'; break; } if($f == 0){ $this->output_message .= 'The action executed successfully.'; } elseif($f != 0 && $t > 0){ $this->output_message .= 'The action cased an error.'; } else { $this->output_message .= 'The action failed... Please retry.'; } } if(isset($_FILES['upload'])){ if($_GET['cmd'] == 'ulswf'){ $ft = 'SWF'; } else { $ft = 'Image'; } $type = substr($_GET['cmd'], 2); $r = $this->doUpload($type); if($r == 'done'){ $this->output_message .= '<strong>Uploading '.$ft.' File: </strong> The action exectued successfully.'; } elseif($r == 'failed'){ $this->output_message .= '<strong>Uploading '.$ft.' File: </strong> The action failed... Please retry.'; } else { $this->output_message .= '<strong>Uploading '.$ft.' File: </strong> Upload Failed... Please ensure you specified the correct file type.'; } } } else { switch($_GET['cmd']){ case 'cdel': $del_subs = "DELETE FROM games WHERE gInCategory = '".$_GET['id']."'"; if($this->del($_GET['id'],'categories','cId') && $this->cempty($_GET['id'])){ $this->output_message .= '<strong>Delete Category: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Delete Category: </strong>The action failed... Please retry.'; } break; case 'delg': if($this->del($_GET['id']) && $this->del($_GET['id'],'playstats','pgId')){ $this->output_message .= '<strong>Delete Game: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Delete Game: </strong>The action failed... Please retry.'; } break; case 'upg': if($this->push($_GET['id'],'-1')){ $this->output_message .= '<strong>Push Game Up: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Push Game Up: </strong>The action failed... Please retry.'; } break; case 'cup': if($this->push($_GET['id'],'-1','categories','cOrder','cId')){ $this->output_message .= '<strong>Push Category Up: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Push Category Up: </strong>The action failed... Please retry.'; } break; case 'cdown': if($this->push($_GET['id'],'+1','categories','cOrder','cId')){ $this->output_message .= '<strong>Push Category Down: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Push Category Down: </strong>The action failed... Please retry.'; } break; case 'downg': if($this->push($_GET['id'],'+1')){ $this->output_message .= '<strong>Push Game Down: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Push Game Down: </strong>The action failed... Please retry.'; } break; case 'cempty': if($this->cempty($_GET['id'])){ $this->output_message .= '<strong>Empty Category: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Empty Category: </strong>The action failed... Please retry.'; } break; case 'edit-done': if($this->editc($_POST['cId'], $_POST)){ $this->output_message .= '<strong>Edit Category: </strong>The action executed successfully.'; } else { $this->output_message .= '<strong>Edit Category: </strong>The action failed... Please retry.'; } break; } } } } function add($input){ if(isset($input['ignore'])){ $ignore = explode(',', $input['ignore']); } else { $ignore = array('submit'); } $return = array(); foreach($input as $table => $data){ $query = "INSERT INTO ".$table." ("; $values = ""; $fields = ""; foreach($data as $field => $value){ $value = str_replace('\'', "'", $value); $value = str_replace('<sql_insert_id>', mysql_insert_id(), $value); if(preg_match("/\{/", $value)){ eval("\$value = \"".stripslashes($value)."\";"); } $fields .= $field.","; $values .= '\''.$value.'\','; } $query .= substr_replace($fields,"",-1).") VALUES (".substr_replace($values,"",-1).")"; if(@mysql_query($query)){ $return[] = true; } else { $return[] = false; } } return $return; } function doUpload($type = 'swf'){ global $sys; $ext = strtolower(substr($_FILES['upload']['name'], -3)); if(($type == 'swf' && $ext != 'swf') || ($type == 'img' && ($ext != 'jpg' && $ext != 'gif' && $ext != 'png' && $ext != 'bmp'))){ return 'wft'; } else { if($type == 'swf'){ $newfilename = "../".$sys->swfdir.'/'.$_FILES['upload']['name']; } else { $newfilename = "../".$sys->imgdir.'/'.$_FILES['upload']['name']; } if(move_uploaded_file($_FILES['upload']['tmp_name'], $newfilename)){ return 'done'; } else { return 'failed'; } } } function editload($row){ $get = "SELECT * FROM categories WHERE cId = '".$row."'"; $info = @mysql_query($get); $data = @mysql_fetch_assoc($info); return $data; } function del($id,$tb='games',$field='gId'){ $query = "DELETE FROM ".$tb." WHERE ".$field." = '".$id."'"; if(@mysql_query($query)){ return true; } else { return false; } } function editc($id, $d){ $query = "UPDATE categories SET cName = '".$d['cName']."', cOrder = '".$d['cOrder']."', cVisible = '".$d['cVisible']."' WHERE cId = '".$id."'"; if(@mysql_query($query)){ return true; } else { return false; } } function push($id,$amt,$tb='games',$field1='gOrder',$field2='gId'){ $query = "UPDATE ".$tb." SET ".$field1." = (".$field1.$amt.") WHERE ".$field2." = '".$id."'"; if(@mysql_query($query)){ return true; } else { return false; } } function cempty($id){ $query = "DELETE FROM games WHERE gInCategory = '".$id."'"; $query2 = "DELETE FROM playstats WHERE pcId = '".$id."'"; if(@mysql_query($query) && @mysql_query($query2)){ return true; } else { return false; } }
}
?>
Reply
peroim
Jan 17 2007, 07:55 PM
Is it just me or is there no mysql_connect ?  Maybe PHP is just complaining he doesn't have connection to a mysql-database.
Reply
galexcd
Jan 17 2007, 09:26 PM
I think he has the connection in /system.class.php, which is required in the beginning of the code. As far as I can tell, it looks like thats where the problem is, you mind showing us the code of system.class.php?
Reply
daler
Jan 17 2007, 10:36 PM
Don't forget to close any open "mysql_connect()"s with mysql_close(); too many open connections can cause problems.
Reply
techclave
Jan 31 2007, 12:19 PM
Thank you guys, for posting your suggestions. Actually , there had been a small mistake with my mysql password. I had forgot to add the suffix to my mysql database password, which i had to do. Anyways, i got it working now !!!
Reply
Similar Topics
Keywords :
- Create Table - Mysql Code - Help
(1)
Mysql Error
(3) ok i need some more help from the wonderful coders here at Trap. I'm almost done with my CMS
script, but i'm having a problem with the installer.php file, when it trys to inseret the user
data into the database i keep getting the following error: CODE mySQL Error: You have an
error in your SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near ';INSERT INTO `members` (`id`, `name`,
`username`, `password`, `email`, `title`) ' at lin....
Html Form!
Using MySQL?! (4) Hey, I need your help again! I need some good working tutorial how I can update my SQL through
HTML form. I did use some tutorials online found with the help of google; but they do not work
properly; I mean there are still small mistakes. I need to have a good tutorial to follow. It
should be based on security and more things. It has to be done in proper way.......
Best Php And Mysql Editor For Noobs
anyone any php or mysql editor that is good for noob (6) hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know
if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness
....
Php And Mysql Programming
anyone knows a code for mysql and php (2) hi everyone! I am making a program using php and mysql...I am a noob on this so i need your
help guys...I want to make a simple program that will some values and then store them on a database
and then retrieve them...uhmm let me give an example out put of what i need. This is the example
say..: Enter First Name: Enter Last Name:
Enter Age: Enter Address: ..those
are the data needed for input values...my question now is how can I make a database....
Best Sites For Learning Php-mysql
(4) Hi I was reminded of this earlier by a post in a topic, meant to post it but forgot and the topic on
php books reminded me. Well anyway there is tyhschools for learning php (unless someone else knows
a better 1) but I wan't to know what is the best site for using php with mysql (using
phpmyadmin) also whats the difference between postgresql and mysql? though I must admit the
postgresql version of phpmyadmin whatever it's called looks better (visually)!....
Tools Needed!
PHP & MySQL (9) Hello, everyone! I need some tools for those two things to test PHP scripts coming together with
database on my laptop, instead checking them on a web-server which takes time.....
Php Objects: Catchable Fatal Error
There is a weird problem with objects in php 5.2.2 (4) in php 4.4.7 my code seems to be ok but in later version 5.2.2 i get this error Catchable fatal
error: Object of class mission_rank could not be converted to string in
/Applications/xampp/xamppfiles/htdocs/nexus/includes/forms/cn_reload.php on line 41 cn_reload.php
include('../class/userClass.php'); session_start(); $app_user =&
$_SESSION ; if ($app_user->character != false) { $race_letter =
array('H','E','T','M','G'); $cn_id = 0; foreach
($app_user->character as....
Php + Mysql Question!
While inserting data into MySQL, how can I know if the data I'm in (4) Basically, I want to know if the Data I'm inserting through a Form is already there or not. Sort
of a Username registration page. I have this, but it doesn't appear to work... CODE
$result = mysql_query("SELECT * FROM users WHERE
username='$username'"); if($result == 1) { echo
'<h1>ERROR!</h1>The username you have chosen already exists!'; }
....
Php Without Server
(6) I have just recently bought a laptop and would like to use PHP for local reasons on it, but I am not
allowed to setu p a local webserver because it would slow down our already crappy internet. Is there
a way for me to run local PHP without using Apache or any other webserver for purely local uses.....
Mysql Won't Update
(4) Ok, so I'm making some arcade administration software so I don't have to add games the hard
way, well anyway, one of the features I have is that on the homepage is a featured author and as
such I just have it so it updates one line in the mySQL. Well, the page with the form passes on the
varibles fine and the updating page recieves them because I echoed everything, then I build the
query and I even echo the query and it comes out exactly how I want it to, but for some reason, the
database itself won't update even though all the varibles are there. Here's....
[php/mysql]id Trouble [resolved]
(3) session_start(); include "database.php"; if (!$_SESSION || $_SESSION { // User
not logged in, redirect to login page Header("Location: main.php"); } $result =
mysql_query("select * from users order by id asc"); while($r=mysql_fetch_array($result))
{ $username=$r ; $info=$r ; $msn=$r ; $email=$r ;
$id=$r ; $password=$r ; $userlevel=$r ; echo "
user ID User Level U....
[mysql/php]need Som Basic Help
(13) QUOTE session_start(); include "database.php"; include "edit.inc.php"; if (!$_SESSION
) { // User not logged in, redirect to login page Header("Location: main.php"); }
if(isset($_POST )){ $email = $_POST ; $msn = $_POST ; $info =
$_POST ; $updateemail = "UPDATE users SET email = '$email', msn =
'$msn', info = '$info' WHERE username = '$username'";
mysql_query($updateemail) or die("culd not edit your info"); echo "info updated"; } //
Display log....
[mysql]get Id Of Loged In User?
(7) how to get the id number of the loged in user? my db is id. username. password. i have tryed a
few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
border="0" alt="ohmy.gif" />....
T_string Error Please Assist
(5) I have unexpected t_strings in 3 lines they are CODE <?php // $Header$ //this
script may only be included - so its better to die if called directly. if
(strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !==
false) { header("location: index.php"); exit; } /* A basic library to
handle a cache of some Tiki Objects, usage is simple and feel free to improve it */ class Cachelib
{ var $folder; function Cachelib() { global $tikidomain;
$th....
The Artists Tutorials :mysql Basic Commands
The Artists is an online programming unit and gfx designing clan. (0) Let's Talk about basic mysql commands used in php. I will now show you a list of the most common
MySQL FUNCTIONS : QUOTE mysql_connect(MySQL server name,username,password) - opens a connection
to a MySQL server. mysql_select_db(database name,connection id) - selects a database residing on
the MySQL server. The database name parameter referes to an active database on the MySQL server that
was opened with the mysql_connect function. The connection identifier is a reference to the current
MySQL connection. mysql_query(sql query) - sends a query to the currently ac....
Problem With A Mysql Join
Problem with a mysql join (2) Hello I am trying to write a script whereby I can pull an image out of one database table and
display it in relation to its category_id in another table. I am using a my_sql join function that
is joining the tables correctly, however it only shows the one same image from the top field of
those combined rows on every single page. I need it display the image according to its category_id
for that particular page. I am thinking I need to set variables to represent those specific rows but
I'm not sure how to do that. Here is my code CODE { $result = mysql_que....
Getting Php 5 To Work With Mysql
getting PHP 5 to work with MySQL (0) Just thought this would be of extreme help to those who are planning to migrate to php5 and still
continue using MySQL same way as before:.... to get mysql work with the php 5 copy
/dll/libmySQL.dll to the directory where php 5 resides and copy the /extensions/php_mysql.dll to the
directory where php.exe resides.(if you can't find the two above files probably you are using an
old release of php 5.you should check for latest at :http://snaps.php.net/) in additon uncomment
extension line in php.ini and add the following code to a gnereal database file(dbcon.php) in m....
Php Pages Permission On Apache Server
PHP pages permission on Apache Server (1) Hello, I want to know what permissions for PHP pages should be given on Apache web server so that
PHP pages can be executed. If PHP pages are in a folder, what permissions should be given for that
folder? ....
How To Insert Post Information Without A Form
How to insert post information without a form (1) I am relatively new with web design so I don't even know exactly what to ask here, but this
can't be as hard as I am making it. I am a merchant and I want to pass just a few simple
strings to the credit card processor: my merchant ID and pin, as well as a price and a few other
simple variables. I want the merchant ID and pin to be invisible to the user. ....
Php And Mysql Applications
(3) Ok I have started useing PHP and MySQL recently and I am wondering how I go about createing an
application. I looked for tutorials and guids at w3schools.com but couldnt find what i was looking
for. All I really need is a list of a few steps to take to get a general idea on were to start when
makeing an application. I would appreciate any help you may have to offer.....
Php, Mysql, Apache
(4) ok, i am hosting a smf (simple machines forum) and in order to do so, i need apache, mysql and php
installed. so i got apachefriends xampp. it works, but idk where to go from there. am i ready to
just host and stuff. or do i need to do a couple more things. basically what i need is a guide on
how to set up a php website. or just confirmation that all i have to do is load the files onto the
website, then im ready to go. thank you....
Some Mysql Basics
(4) Greetings this tutorial will show you some mysql basics.. MySQL is one of the most used database. a
simple config file at the top add this CODE <?php ?> after <?php add
$username= "root"; // Username that has access to your database $password=
""; //Password that has access to your database $host = "localhost"; // The
host where the database is (mostly this is localhost) $db = "databasename"; //
The name of the database where you want to work with //connect to the database mysql_connect(....
Php Search Engine Script For Mysql Database
(11) A search engine is provided to facilitate the user with undemanding and clear-cut search options.
The search facility includes simple search, search by title, search by word/phrase, ect… Thus, the
user is at a safe distance from the risk of selecting files/folders ambiguously. In addition, a
history of recent searches can be preserved for future perusal. Now
day’s visitors have a large option for his needs on internet and so visitors are not vesting their
time by following the dead links on your site. So a search engine is essential for your....
Creating Profiles In Php/mysql ?
(7) i've started to learn php..im familiar to basics of php and mysql now.Now for example i want
that some user can register to my website , and after that he can Login and log out , and he can see
his profile.is there any tutorial about this ? or any helping url .. or any helping answer please
/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
How To Use A Link To Call Function In Php?
(8) The title says it all, really. How do you call a function using in PHP? I'm doing a project
and I stumbled upon this problem. I don't want to use query string in the href part like
since that would mess up the other part of my code. Can anyone pleae help me? I've pasted the
code below. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Thanksh.
CODE <?php function display($x){ //coding goes here. } ?>
<html> <body> <p align="center"> <a href="what g....
Can You Add Images Into A Mysql Database?
Using Php? (20) I'm learning php in class right now, but I'm still not that good at it, what I'm
wondering is when I write the php so that it can connect with a database, can I at the same time
have it that it is able to display back images that I choose. Like, I want a search feature, where
you can search for a keyword, and it will bring back a list of all the possible entries with that
keyword, but each of these entries will have a photo associated with it. Now, do I put these image
files directly into the database, or do I write the code to link them from my files to th....
Parse: Error Unexpected T_lnumber
php parse error when running script (4) Hi. I've just created a php script. The main object of the script is to delete some old files
and replace it with a new file with some new content, effectively moving the contents from one file
to another. These are the first 50 lines of the file: /* Calculate For The "A" Group - The
Latest Games ID */ $a_B = 002; while(file_exists("a_" . $a_B . ".dat")) {
$a_B++; } $new_page_contents = " " . $_POST . " " . $_POST . "
include \"/home/cmatcme/public_html/footer.php\"; ?> "; $a_stream = fopen(&....
Increment A Mysql Column
how to increment a MySQL column one unit (6) Hi, I have a column in a MySQL table which contains a counter of the views of the object described
by this table. I would like to increment this value by one everytime the object is viewed. Obviously
came into my mind the possibility of retrieving the value of this field, store it in a variable
increment this value by one and perform an UPDATE query again with this new value. My question is if
there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
understand the issue.....
Problem On Mysql "order By"
(5) Can someone please help...? I have a problem with using "ORDER BY" in mysql... CODE SELECT *
FROM `foo` WHERE b='abc' ORDER BY 'number' ASC i want to sort the table out by
the value in "number" which is a number.. but it came out to be sort by like this way...
1->10->2->20 it only sort out the front digit.... but what i want is it will sort by how great the
number is like this... 1->2->3........->10....->20 sorry my english isn't good enough...to
describe my problem properly... hope you can understand and help me on this.....thx....
Looking for Warning:, Mysql_insert_id(), Error, ...
|
|
Searching Video's for Warning:, Mysql_insert_id(), Error, ...
|
advertisement
|
|