943,640 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3027
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 27th, 2008
0

Problem with INSERT command into MySQL

Expand Post »
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:

PHP Syntax (Toggle Plain Text)
  1.  
  2. CREATE TABLE `island2` (
  3. `id` int(10) unsigned NOT NULL auto_increment,
  4. `user` int(11) NOT NULL default '0',
  5. `island` int(11) NOT NULL default '0',
  6. `town` int(11) NOT NULL default '0',
  7. `village` int(11) NOT NULL default '0',
  8. `islandrank` int(11) NOT NULL default '0',
  9. `townrank` int(11) NOT NULL default '0',
  10. `villagerank` int(11) NOT NULL default '0',
  11. `game` int(11) NOT NULL default '0',
  12. PRIMARY KEY (`id`)
  13. ) 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 Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. /*
  4.  
  5. Move to Island 1090 (island1090.pro.php)
  6.  
  7. */
  8. ob_start();
  9. $rank_check = 1;
  10. include "global.inc.php";
  11.  
  12.  
  13. $check = fetch("SELECT * FROM island2 WHERE user = '$userid' AND game = '$game'");
  14. if ($check[id])
  15. {
  16. die(header(error("isaland1090.php?game=$game","You already have a House.")));
  17. }
  18.  
  19.  
  20. mysql_query("INSERT INTO island2 (id,user,island,town,village,islandrank,townrank,villagerank,game) VALUES ('',$userid','1','1','1','0','0','0','$game')");
  21. header(error("island1090.php?game=$game","You have just settled into *****Island name here*******."));
  22.  
  23. ?>


Any help is much appreciated.


Thank you

Justin
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 27th, 2008
1

Re: Problem with INSERT command into MySQL

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
Reputation Points: 12
Solved Threads: 8
Junior Poster in Training
RoryGren is offline Offline
60 posts
since Oct 2007
Mar 27th, 2008
1

Re: Problem with INSERT command into MySQL

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.,
php Syntax (Toggle Plain Text)
  1. $query = mysql_query("your query") or die(mysql_error())";
  2.  
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 27th, 2008
0

Re: Problem with INSERT command into MySQL

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
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 27th, 2008
1

Re: Problem with INSERT command into MySQL

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')");
Last edited by TopDogger; Mar 27th, 2008 at 8:46 pm.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
TopDogger is offline Offline
87 posts
since Aug 2005
Mar 27th, 2008
0

Re: Problem with INSERT command into MySQL

Click to Expand / Collapse  Quote originally posted by justted ...
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
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 27th, 2008
0

Re: Problem with INSERT command into MySQL

Click to Expand / Collapse  Quote originally posted by TopDogger ...
You are trying to insert an id value of ' ' when you have that column set up as auto_increment. ;

What IS this nasty script? I answered the same to very similar looking code just the other day


Matti Ressler
Suomedia
Reputation Points: 15
Solved Threads: 19
Junior Poster
Suomedia is offline Offline
154 posts
since Mar 2008
Mar 27th, 2008
0

Re: Problem with INSERT command into MySQL

Thank you everyone so much. That has worked. And thanks for the explanation. :O)


Justin
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007
Mar 28th, 2008
0

Re: Problem with INSERT command into MySQL

Click to Expand / Collapse  Quote originally posted by Suomedia ...
What IS this nasty script? I answered the same to very similar looking code just the other day


Matti Ressler
Suomedia
Deja vu man
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Mar 28th, 2008
0

Re: Problem with INSERT command into MySQL

I paid for the script off this guy who advertises that he gives support and backup to customers. However, this is not true and he ignores any tech support requests so I have had to learn what I can by editing the script.

Why is it really that bad? :o/

Justin
Reputation Points: 10
Solved Threads: 2
Junior Poster
justted is offline Offline
140 posts
since Dec 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: geographical location from IP
Next Thread in PHP Forum Timeline: Any one out there guys ! help!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC