Jump to content

Submittion help


xoligy

Recommended Posts

Hey all long time since ive been here as i quit coding but now im back lol.

 

Anyway im trying to make a page where im able to add new items to a game db (im creating it all dont ask why) and im running into issues already. Anyway the code is below and here are my issues:

 

1. When i post the form only numerical data can be entered into the name field, yet in the db its varchar. I dunno whats up there  :shrug:

2. When i added $limited to the equasion nothing would get entered into the database, as you can see its working on a dropdown box (its 1,2 at the moment but should be blackmarket, favor

3. I will be adding cost soon as the above are figured out lol infact there will be two costs (game payments and favor point payments)

4. Yes i suck!

 

Db info: $type > item  varchar(30)  utf8_general_ci

 

Thanks in advance for any help :D

Ps. Please feel free to say if things could be improved, or of any good tutorials i lost all my decent ones :(

 

<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: login.php");
}
include('db.php');
include('proc.php');
if (!function_exists("cln")) {
   function cln( $value ){
    if( get_magic_quotes_gpc() ){
           $value = stripslashes( $value );
         }
         //check if this function exists
         if( function_exists( "mysql_real_escape_string" ) ) 
         {
           $value = mysql_real_escape_string(trim(strip_tags(htmlspecialchars(( $value )))));
         }
         //for PHP version < 4.3.0 use addslashes
         else
         {
           $value = addslashes( $value );
         } 
         return $value;
     }
}
if($addweapon){  
$name = cln($name);  
$att = cln($att);
$def = cln($def);
$type = cln($type);
$limited = cln($limited);
$cost = cln($cost);
$result = mysql_query("insert into $type (item, att, def, limited) values ($name, $att, $def, $limited)");
echo $result;
echo $limited;

$melcount = mysql_fetch_row(mysql_query("select count(*) from melee"));
$expcount = mysql_fetch_row(mysql_query("select count(*) from explosives"));
$guncount = mysql_fetch_row(mysql_query("select count(*) from guns"));
$armcount = mysql_fetch_row(mysql_query("select count(*) from armour"));
$vehcount = mysql_fetch_row(mysql_query("select count(*) from vehicles"));
$hencount = mysql_fetch_row(mysql_query("select count(*) from henchmen"));
$favcount = mysql_fetch_row(mysql_query("select count(*) from favor"));
//$blkcount = mysql_fetch_row(mysql_query("select count(*) from melee where limited>0"));
}
?>
<table>
<tr>
<td colspan='2'>Add new items m2 items here:<td>
</tr>
<tr>
<form name="form" method="post" action="<?=$_SERVER[php_SELF]?>">
<td>Item name:</td><td><input type="text" name="name" size="15"></td>
</tr>
<tr>
<td>Attack:</td><td><input type="text" name="att" size="5"></td>
</tr>
<tr>
<td>Defence:</td><td><input type="text" name="def" size="5"></td>
</tr>
<tr>
<td>Item type:</td>
<td>
<select name="type">
              <option value="melee">Melee</option>
              <option value="explosives">Explosives</option>
              <option value="guns">Guns</option>
              <option value="armour">Armour</option>
              <option value="vehicles">Vehicles</option>
              <option value="henchmen">Henchmen</option>
          </select>
</td>
</tr>
<tr>
<td>Limited item:</td>
<td>
<select name="limited">
              <option value="">None</option>
              <option value="1">Favor</option>
              <option value="2">Blackmarket</option>
          </select>
</td>
</tr>
<tr>
<td>Cost:</td><td><input type="text" name="cost" size="5"></td>
</tr>
<tr>
<td><input type="submit" name="addweapon" value="Submit"></td>
</form> 
</tr>
<tr>
<td>Total Melee:</td><td><?=$melcount[0]?></td>
</tr>
<tr>
<td>Total Explosives:</td><td><?=$expcount[0]?></td>
</tr>
<tr>
<td>Total Guns:</td><td><?=$guncount[0]?></td>
</tr>
<tr>
<td>Total Armour:</td><td><?=$armcount[0]?></td>
</tr>
<tr>
<td>Total Vehicles:</td><td><?=$vehcount[0]?></td>
</tr>
<tr>
<td>Total Henchmen:</td><td><?=$hencount[0]?></td>
</tr>
<tr>
<td>Total FP Items:</td><td><?=$favcount[0]?></td>
</tr>
<tr>
<td>Total Blackmarket:</td><td><?=$blkcount[0]?></td>
</tr>
</table>
<?include 'left.php';?>

Link to comment
https://forums.phpfreaks.com/topic/192887-submittion-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.