•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 328,783 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,327 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 479 | Replies: 11
![]() |
•
•
Join Date: Dec 2007
Posts: 41
Reputation:
Rep Power: 1
Solved Threads: 0
Hello everyone,
I seem to be having a problem inserting some information into a MySQL table. Below is a copy of the MySQL table code I used and also the PHP code. I was wondering if anyone can help me find out why it wont insert the information.
What I am trying to do is make it so members can go and choose an option to join one of a selection of islands which will be subdivded into towns and then the town subdivided into villages. Each of the island/town and village levels will have a staff rank to allow certain members to have access rights to those pages.
But basically as you can see I want to set the default island/town/village levels and ranks to 0 intially. Then when the member goes to the island -age they will choose an island of say 4 options (which would update the island field to between 1-4 to depending on selecting an option. Then they choose a town of say between 1-4 and then again it updates the town field of between 1-4. And again for the village.
However, for some reason this code isnt working so far and its stopped me in my tracks. lol
I am using the $userid and $game tags which are apart of the include global.inc.php page I believe. I need this to identify the user and their individual details.
Can anyone help or see any obvious mistakes?
Here is the MySQL code:
And this is the PHP island1090.pro.php page which should once the link on island1090.php is clicked insert a row. But currently it doesnt do it.
Any help is much appreciated.
Thank you
Justin
I seem to be having a problem inserting some information into a MySQL table. Below is a copy of the MySQL table code I used and also the PHP code. I was wondering if anyone can help me find out why it wont insert the information.
What I am trying to do is make it so members can go and choose an option to join one of a selection of islands which will be subdivded into towns and then the town subdivided into villages. Each of the island/town and village levels will have a staff rank to allow certain members to have access rights to those pages.
But basically as you can see I want to set the default island/town/village levels and ranks to 0 intially. Then when the member goes to the island -age they will choose an island of say 4 options (which would update the island field to between 1-4 to depending on selecting an option. Then they choose a town of say between 1-4 and then again it updates the town field of between 1-4. And again for the village.
However, for some reason this code isnt working so far and its stopped me in my tracks. lol
I am using the $userid and $game tags which are apart of the include global.inc.php page I believe. I need this to identify the user and their individual details.
Can anyone help or see any obvious mistakes?
Here is the MySQL code:
CREATE TABLE `island2` (
`id` int(10) unsigned NOT NULL auto_increment,
`user` int(11) NOT NULL default '0',
`island` int(11) NOT NULL default '0',
`town` int(11) NOT NULL default '0',
`village` int(11) NOT NULL default '0',
`islandrank` int(11) NOT NULL default '0',
`townrank` int(11) NOT NULL default '0',
`villagerank` int(11) NOT NULL default '0',
`game` int(11) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=6359 ;
And this is the PHP island1090.pro.php page which should once the link on island1090.php is clicked insert a row. But currently it doesnt do it.
<?php
/*
Move to Island 1090 (island1090.pro.php)
*/
ob_start();
$rank_check = 1;
include "global.inc.php";
$check = fetch("SELECT * FROM island2 WHERE user = '$userid' AND game = '$game'");
if ($check[id])
{
die(header(error("isaland1090.php?game=$game","You already have a House.")));
}
mysql_query("INSERT INTO island2 (id,user,island,town,village,islandrank,townrank,villagerank,game) VALUES ('',$userid','1','1','1','0','0','0','$game')");
header(error("island1090.php?game=$game","You have just settled into *****Island name here*******."));
?>
Any help is much appreciated.
Thank you
Justin
Hi Justin
I see you have the command ob_start() at the top of your php. Do you have the ob_end_flush() command before the page end?
What ob_start() does is to hold all the php output in its Output Buffer (ob) until it receives the ob_end_flush() command, whereupon it sends all the output together. So, if you don't have the ob_end_flush(), php is going to wait a long time before sending the output to the server! ;-)
I hope that helps.
Rory
I see you have the command ob_start() at the top of your php. Do you have the ob_end_flush() command before the page end?
What ob_start() does is to hold all the php output in its Output Buffer (ob) until it receives the ob_end_flush() command, whereupon it sends all the output together. So, if you don't have the ob_end_flush(), php is going to wait a long time before sending the output to the server! ;-)
I hope that helps.
Rory
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,468
Reputation:
Rep Power: 6
Solved Threads: 159
Print out your query, execute it in phpmyadmin/ mysql console and see if it works. You can also give "die" to check if your query is working or not.
ie.,
ie.,
php Syntax (Toggle Plain Text)
$query = mysql_query("your query") or die(mysql_error())";
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Dec 2007
Posts: 41
Reputation:
Rep Power: 1
Solved Threads: 0
Hiya thanks for the replies.,
I have tried the ob_end and that didnt work and dont exactly know how to print the query :>/
Im sorry but im only a beginner. I know how to run a SQL query but not print or do the die. :>/
Also I actually dont know why the ob_start is there as I took a similar script from my website and just changed the details to this table.
Im not sure I could write it from scratch quite yet. But what does the Ob_start and end mean/do?
Thanks
Justin
I have tried the ob_end and that didnt work and dont exactly know how to print the query :>/
Im sorry but im only a beginner. I know how to run a SQL query but not print or do the die. :>/
Also I actually dont know why the ob_start is there as I took a similar script from my website and just changed the details to this table.
Im not sure I could write it from scratch quite yet. But what does the Ob_start and end mean/do?
Thanks
Justin
•
•
Join Date: Aug 2005
Location: somewhere in time
Posts: 67
Reputation:
Rep Power: 3
Solved Threads: 1
You are trying to insert an id value of ' ' when you have that column set up as auto_increment. Don't insert an id value. Let MySQL set the id value.
Try this:
mysql_query("INSERT INTO island2 (user,island,town,village,islandrank,townrank,villagerank,game) VALUES ('$userid','1','1','1','0','0','0','$game')");
Try this:
mysql_query("INSERT INTO island2 (user,island,town,village,islandrank,townrank,villagerank,game) VALUES ('$userid','1','1','1','0','0','0','$game')");
Last edited by TopDogger : Mar 27th, 2008 at 7:46 pm.
•
•
Join Date: Mar 2008
Posts: 151
Reputation:
Rep Power: 1
Solved Threads: 19
•
•
•
•
Hiya thanks for the replies.,
But what does the Ob_start and end mean/do?
It was explained, but we will try again.
ob_start(); buffers the output to the browser (stops it) until ob_end_flush() is called. If you don't have ob_end_flush() then the output of code after ob_start will not be sent to the browser.
Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
•
•
Join Date: Mar 2008
Posts: 151
Reputation:
Rep Power: 1
Solved Threads: 19
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 2,468
Reputation:
Rep Power: 6
Solved Threads: 159
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
DaniWeb Marketplace (Sponsored Links)
Similar Threads
- help with mysql bindings (Python)
- Problem with $_POST (PHP)
- Problem adding registration data to mysql database (JSP)
- MySQL INSERT not working. Why? (MySQL)
Other Threads in the PHP Forum
- Previous Thread: geographical location from IP
- Next Thread: Any one out there guys ! help!!!



Linear Mode