[MySQL] Trouble inserting into table

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

[MySQL] Trouble inserting into table

Post by Perry »

I am working on an admin panel where items can be created and inserted into the database that way I will not have to manually insert them through phpmyadmin and eventually I can have player moderators to design items. Anyway I am having trouble with a little bit of it and I can't understand why.

This is what I have.

This is add.php (without all the setup code and stuff to make it smaller)

Code: Select all

<?php

$tag = $_GET['tag'];

if($tag == "shop")
{
echo "<br>
<form method ='post' action='verify.php?tag=shop'>
Shop type: <input type='text' name='name' size='32'><br>
Value: <input type='text' name='value' size '12'><br>
Level: <input type='text' name='level' size '3'><br>
Image: <input type='text' name='image' size '32'><br>
<center>
<input type='submit' value='Create Shop'><br>
<A href='index.php'>Back to panel.</a>
</center>";
}

if($tag == "harvest")
{
echo "<br>
<form method ='post' action='verify.php?tag=harvest'>
Name: <input type='text' name='name' size='32'><br>
Type: <input type='text' name='type' size='32'><br>
Modifier: <input type='text' name='mod' size='32'><br>
Modifier Adds: <input type='text' name='modadd' size='3'><br>
Value: <input type='text' name='value' size '12'><br>
Location: <input type='text' name='location' size='32'><br>
Level: <input type='text' name='level' size '3'><br>
Description: <input type='text' name='descrip' size '160'><br>
<center>
<input type='submit' value='Create Harvest'><br>
<A href='index.php'>Back to panel.</a>
</center>";
}

if($tag == "hunt")
{
echo "<br>
<form method ='post' action='verify.php?tag=hunt'>
Name: <input type='text' name='name' size='32'><br>
Animal: <input type='text' name='animal' size='32'><br>
Type: <input type='text' name='type' size='32'><br>
Modifier: <input type='text' name='mod' size='32'><br>
Modifier Adds: <input type='text' name='modadd' size='3'><br>
Value: <input type='text' name='value' size '12'><br>
Location: <input type='text' name='location' size='32'><br>
Level: <input type='text' name='level' size '3'><br>
Description: <input type='text' name='descrip' size '160'><br>
<center>
<input type='submit' value='Create Animal'><br>
<A href='index.php'>Back to panel.</a>
</center>";
}

if($tag == "mineral")
{
echo "<br>
<form method ='post' action='verify.php?tag=mineral'>
Name: <input type='text' name='name' size='32'><br>
Type: <input type='text' name='type' size='32'><br>
Modifier: <input type='text' name='mod' size='32'><br>
Modifier Adds: <input type='text' name='modadd' size='3'><br>
Value: <input type='text' name='value' size '12'><br>
Location: <input type='text' name='location' size='32'><br>
Level: <input type='text' name='level' size '3'><br>
Description: <input type='text' name='descrip' size '160'><br>
<center>
<input type='submit' value='Create Mineral'><br>
<A href='index.php'>Back to panel.</a>
</center>";
}
?>
This is verify.php (also without setup code)

Code: Select all

<?php
$tag = $_GET['tag'];

if($tag == "shop")
{
    $name=$_POST['name'];
    $value=$_POST['value'];
    $level=$_POST['level'];
    $image=$_POST['image'];

    $SQL = "INSERT into build_shops(name, price, level, image) VALUES('$name','$value','$level','$image')";
         mysql_query($SQL) or die("could not create shop");
}
if($tag == "harvest")
{
    $name=$_POST['name'];
    $type=$_POST['type'];
    $mod=$_POST['mod'];
    $modadd=$_POST['modadd'];
    $value=$_POST['value'];
    $location=$_POST['location'];
    $level=$_POST['level'];
    $descrip=$_POST['descrip'];

    $SQL = "INSERT into harvests(name, type, mod) VALUES('$name','$type','$mod')";
         mysql_query($SQL) or die("could not create harvest");
}
if($tag == "hunt")
{
    $name=$_POST['name'];
    $animal=$_POST['animal'];
    $type=$_POST['type'];
    $mod=$_POST['mod'];
    $modadd=$_POST['modadd'];
    $value=$_POST['value'];
    $location=$_POST['location'];
    $level=$_POST['level'];
    $descrip=$_POST['descrip'];

    $SQL = "INSERT into hunting(name, animal, type, mod, modadd, value, location, level, descrip) VALUES('$name','$animal','$type','$mod','$modadd','$value','$location','$level','$descrip')";
         mysql_query($SQL) or die("could not create animal");
}
if($tag == "mineral")
{
    $name=$_POST['name'];
    $type=$_POST['type'];
    $mod=$_POST['mod'];
    $modadd=$_POST['modadd'];
    $value=$_POST['value'];
    $location=$_POST['location'];
    $level=$_POST['level'];
    $descrip=$_POST['descrip'];

    $SQL = "INSERT into minerals(name, type, mod, modadd, value, location, level, descrip) VALUES('$name','$type','$mod','$modadd','$value','$location','$level','$descrip')";
         mysql_query($SQL) or die("could not create mineral");
}

echo "Successfully created.<br>";
echo "<A href='index.php'>Back to panel.</a>";

?>
Making a shop works great. Everything else returns the or die error. I removed most of harvest's insert and found out that it doesn't give any trouble until it gets to adding the mod. I have tried changing the name of it, thinking it might be used be mySql and give me trouble. That didn't help.

harvest is setup with these fields: item_id, name, type, mod, modadd, value, location, level, and descrip.
minerals is exactly the same. So is hunting except it has an additional animal field.

I have checked and rechecked everything I can think of. Does anyone else see anything I am missing? Thanks for your time.
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: [MySQL] Trouble inserting into table

Post by hallsofvallhalla »

can we see a screen of your DB
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

Re: [MySQL] Trouble inserting into table

Post by Perry »

Sure. This is the harvests table. If you need to see other tables let me know, but they are all just like this. Image
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: [MySQL] Trouble inserting into table

Post by Xaleph »

I`m not sure, but MOD is short for modulo, which probably is a reserved key word in MySQL. Funny, since I saw the list yesterday. I`ll look in to it for you :)
User avatar
Perry
Posts: 409
Joined: Tue Jun 23, 2009 4:26 pm

Re: [MySQL] Trouble inserting into table

Post by Perry »

That was it. I had thought that was it so I changed it, but forgot to rename the field in the database. :oops: Sorry about that. Thanks for the help though :D
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: [MySQL] Trouble inserting into table

Post by hallsofvallhalla »

hehe see I knew posting that topic would help, i usually put modd.
Post Reply

Return to “Beginner Help and Support”