0

Hi all, I cant get this at all.

Ihave a form with a series of radio button, all which represent a category of animal. I have given each radio button a value which is the same as the mysql table it represents.

For example:

<input type="radio" name="delete" value="tortoises">Tortoises<br />

When this radio button is checked, the contents of the table named 'tortoises' should be displayed.

I dont want to have to write code for each category if possible.

Here is my form with all the radio buttons.

removestock.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stocklist update</title>
<link href="../css/gallery_submit.css" rel="stylesheet" type="text/css" />
<link href="../css/removestock.css" rel="stylesheet" type="text/css" />
<link href="../css/template.css" rel="stylesheet" type="text/css" />
<body>

   <div class="span4">
      <p>Remove Livestock</p>
   </div>
<form class="form" action="remove.php" method="post" enctype="multipart/form-data" name="stockupdate_form" id="stockupdate_form" style="margin-bottom:0px;">
<h1 style="margin-bottom: 0px">Chose a category, only one can be chosen at a time:</h1>
<label><span class="span2">Amphibians</span></label><br />
<label><b>Snakes</b></label><br />
<input type="radio" name="delete" value="boids">Boids<br />
<input type="radio" name="delete" value="colubrids">Colubrids<br />
<input type="radio" name="delete" value="other_snakes">Other<br />
<label><b>Lizards</b></label><br />
<input type="radio" name="delete" value="monitors">Monitors/Tegus<br />
<input type="radio" name="delete" val ue="agmids">Agmids<br />
<input type="radio" name="delete" value="geckos">Geckos<br />
<input type="radio" name="delete" value="other_lizards">Other<br />
<label><b>Chelonia</b></label><br />
<input type="radio" name="delete" value="tortoises">Tortoises<br />
<input type="radio" name="delete" value="turtles">Turtles<br />
<label><b>Amphibians</b></label><br />
<input type="radio" name="delete" value="frogs">Frogs/Toads<br />
<input type="radio" name="delete" value="other_amphibs">Other<br />
<label><b>Inverts</b></label><br />
<input type="radio" name="delete" value="arachnids">Arachnids<br />
<input type="radio" name="delete" value="other_inverts">Other<br />

<input type="submit" name="next" value="Next" />     

<input name="submitted_form" type="hidden" id="submitted_form" value="stockupdate_form" />
</form>



</body>


</html>

This is the file that lists the contents of the table.

remove.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stocklist update</title>
<link href="../css/gallery_submit.css" rel="stylesheet" type="text/css" />
<link href="../css/template.css" rel="stylesheet" type="text/css" />
<body>
   <div class="span4">
      <p>Remove Livestock</p>
   </div>

<?php
      include 'connect.php';

      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
         if (isset($_POST['next'])) 
         {
            $selected_radio = $_POST['delete'];
    ?>
       <form class='form' action='remove2.php' method='post' enctype='multipart/form-data' name='stockupdate_form' id='stockupdate_form' style='margin-bottom:0px;'>;
          <?php
            if ($selected_radio == 'boids') 
            {
                $data = mysql_query("SELECT * FROM boids  ORDER BY id DESC")
                       or die(mysql_error());

                       while($info = mysql_fetch_array( $data )) 
                       { 
                          echo "<span class='span2'>";
                          echo $info['species'];
                          echo ' : ';
                          echo $info['year'];
                          echo ' : ';
                          echo $info['sex'];
                          echo ' : ';
                          echo '&pound';
                          echo $info['price'];
                          echo "<input type='checkbox' name='check[{$info['id']}]' />";
                          echo '<br />';
                          echo "</span>";

                       }
            }

         }
      }
      ?>
   <input type='submit' name='remove' value='Remove' />
   </form>

</body>
</html>

As you can see doing it this way will result in A LOT of code by the time I would do it for each category!

Can anyone help?

Thanks for looking.....................

3
Contributors
33
Replies
34
Views
4 Years
Discussion Span
Last Post by GlenRogers
Featured Replies
  • after `price` put comma before number (1,2.. etc) Read More

  • 1
    diafol 3,669   4 Years Ago

    Not obvious to me, but post routine looks a bit too complex: if (isset($_POST['submit'])){ print_r($_POST); //have a look $aspecies = mysql_real_escape_string($_POST['aspecies']); $ayear = mysql_real_escape_string($_POST['ayear']); $asex = mysql_real_escape_string($_POST['asex']); $aprice = mysql_real_escape_string($_POST['price']); $subcat = intval($_POST['subcat']); $r = mysql_query("INSERT INTO animals (animal_id, species, year, sex, price, subcat_id) VALUES ('', '$aspecies', '$ayear', '$asex', '$aprice', … Read More

0

I don't understand why you've got two forms - unless you've got loads of data maybe.
A js select dropdown and an interactive table should allow you to manage this quite easily. Here's an example (starter) with jQuery.

<select id="categories">
    <optgroup label="Snakes">
        <option value="1">Boids</option>
        <option value="2">Colubrids</option>
    </optgroup>
    <optgroup label="Aliens">
        <option value="7">Paul</option>
        <option value="26">ET</option>
    </optgroup>
</select>
<div id="interactive_table">
</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script>
    $('#categories').change(function(){
        num = $(this).val();
        $('#interactive_table').html('The value is ' + num);
        //do some ajax to get the table you need 
        //pass the 'num' value to an ajax object and get the response
        //then you do something like this: $('#interactive_table').html(data);
    });
</script>

That's just an example. The code above should work as is - just paste it in a blank html and browse. I'm assuming that you have the SQL tables, something like this:

animal_category
cat_id | cat_label

animal_subcategory
subcat_id | cat_id | subcat_label

animals
animal_id | species | year | sex | price | subcat_id

That way you can populate the dropdown easily with php. However, as I suspect, you have a table for each subcat, perhaps you'd do well to combine them into one.

You could make the select a list of headings (cats) and links (subcats) in a sidebar, where the link click would run the interactive table. ANyway, feel free to ignore this. Rambling slightly.

Edited by diafol

0
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stocklist update</title>
<link href="../css/gallery_submit.css" rel="stylesheet" type="text/css" />
<link href="../css/template.css" rel="stylesheet" type="text/css" />
<body>
   <div class="span4">
      <p>Remove Livestock</p>
   </div>

<?php
      include 'connect.php';

      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
         if (isset($_POST['next'])) 
         {
            $selected_radio = $_POST['delete'];
    ?>
       <form class='form' action='remove2.php' method='post' enctype='multipart/form-data' name='stockupdate_form' id='stockupdate_form' style='margin-bottom:0px;'>;
          <?php
         //   if ($selected_radio == 'boids') 
            {
                $data = mysql_query("SELECT * FROM $selected_radio  ORDER BY id DESC")
                       or die(mysql_error());

                       while($info = mysql_fetch_array( $data )) 
                       { 
                          echo "<span class='span2'>";
                          echo $info['species'];
                          echo ' : ';
                          echo $info['year'];
                          echo ' : ';
                          echo $info['sex'];
                          echo ' : ';
                          echo '£';
                          echo $info['price'];
                          echo "<input type='checkbox' name='check[{$info['id']}]' />";
                          echo '<br />';
                          echo "</span>";

                       }
            }

         }
      }
      ?>
   <input type='submit' name='remove' value='Remove' />
   </form>

</body>
</html>
0

Diafol, as I know very little about js that confused me a little. The furthest I have went with JQuery is to use the Cycle plugin! I really will have to learn some soon! Thanks for trying to show me anothert way though.

Urtrivedi, thanks for that, it works like a charm now!

One more thing I'm needing help with though. I have a remove2.php file that removes any of the checked animals from the mysql table. How can I do this without naming the table though? Which table depends on which radio button was pressed(which tables contents are displayed).

Here is my remove2.php file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stocklist update</title>
<link href="../css/gallery_submit.css" rel="stylesheet" type="text/css" />
<link href="../css/available.css" rel="stylesheet" type="text/css" />
<link href="../css/template.css" rel="stylesheet" type="text/css" />
<body>


<?php
   include 'connect.php';

   if(isset($_POST['check']))
   {
      $chk = (array) $_POST['check'];
      $p = implode(',',array_keys($chk)); 
      $sql = mysql_query("DELETE FROM boids WHERE id IN ($p)");
      echo "<span class='span1'>";
      echo 'Items have been removed';
      echo "</span>";
      echo "<br />";
      echo "<a href='removestock.php'>Back</a>";
   }
   else
   {
      echo "<span class='span1'>";
      echo 'No checkboxes selected';
      echo "<br />";
      echo 'Go back and select animals to remove from list';
      echo "</span>";
      echo "<br />";
      echo "<a href='removestock.php'>Back</a>";
   }

?>
</body>
</html>

Thanks foor looking................

0

Diafol, as I know very little about js that confused me a little.

Sorry about that. Just thought I'd pop that in as your php/sql looks quite convoluted.

I have some SQL which will should create this 'one table' of animals I was talking about, which can be filtered by a subcategory_id (type of animal) if you're interested. If so, give the field list of your various animals tables.

0

I have tables
'boids'
'coloubrids'
'other_snakes'

'agmids'
'geckos'
'monitors'
'other_lizards'

'tortoises'
'turtles'

'frogs'
'other_amphibs'

'arachnids'
'other_inverts'

The fields for all of them are

'id' int(11) ai primary
'species' varchar(200)
'year' varchar(100)
'sex'varchar(20)
'price' varchar(100)

So if I was to have them all in one table would it make it simpler to remove an entry from my remove2.php file?

0

This would make it considerably easier, yes. It'll take me about 5 mins, will be back, unless somebody gets to it first :)

0

OK. Let's assume you want the following structure:

categories (e.g. snakes, inverts, lizards, amphibians, testudines)
subcategories (e.g. your previous table names: boids, coloubrids etc)
animals (all individual stock animals)

I strongly suggest you make a backup copy of your DB before doing any of the following, so if you don't like it or it doesn't work, you can roll back safely.

1) CREATE three new tables: animals, subcategories, categories.

Copy the following into your SQL window, you can run them one at a time, run them all in one go (if your window supports it) or place them into a textfile with the '.sql' extension import them that way.

CREATE TABLE `animals` (
  `animal_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `species` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
  `year` int(4) DEFAULT NULL,
  `sex` varchar(1) COLLATE utf8_unicode_ci DEFAULT NULL,
  `price` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
  `subcat_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`animal_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/*Data for the table `animals` */

/*Table structure for table `categories` */

CREATE TABLE `categories` (
  `cat_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `category_label` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`cat_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/*Data for the table `categories` */

insert  into `categories`(`cat_id`,`category_label`) values (1,'Snakes'),(2,'Lizards'),(3,'Testudines'),(4,'Amphibians'),(5,'Invertebrates');

/*Table structure for table `subcategories` */

CREATE TABLE `subcategories` (
  `subcat_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cat_id` int(11) DEFAULT NULL,
  `subcategory_label` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`subcat_id`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/*Data for the table `subcategories` */

insert  into `subcategories`(`subcat_id`,`cat_id`,`subcategory_label`) values (1,1,'Boids'),(2,1,'Coloubrids'),(3,1,'Other Snakes'),(4,2,'Agmids'),(5,2,'Geckos'),(6,2,'Monitors'),(7,2,'Other Lizards'),(8,3,'Tortoises'),(9,3,'Turtles'),(10,4,'Frogs'),(11,4,'Other Amphibians'),(12,5,'Arachnids'),(13,5,'Other Invertebrates');

3) Here's the 'merging' query:

INSERT INTO animals (`species`,`year`,`sex`,`price`,`subcat_id`) 
(SELECT `species`,`year`,`sex`,`price` 1 AS `subcat_id` FROM `boids`) 
    UNION ALL 
(SELECT `species`,`year`,`sex`,`price` 2 AS `subcat_id` FROM `coloubrids`) 
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 3 AS `subcat_id` FROM `other_snakes`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 4 AS `subcat_id` FROM `agmids`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 5 AS `subcat_id` FROM `geckos`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 6 AS `subcat_id` FROM `monitors`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 7 AS `subcat_id` FROM `other_lizards`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 8 AS `subcat_id` FROM `tortoises`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 9 AS `subcat_id` FROM `turtles`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 10 AS `subcat_id` FROM `frogs`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 11 AS `subcat_id` FROM `other_amphibs`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 12 AS `subcat_id` FROM `arachnids`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price` 13 AS `subcat_id` FROM `other_inverts`)

I've changed some of the field properties, e.g. sex to single char (M or B - I assume), year to a 4 figure integer, I left price as I don't know whether this is a float or if you've got other info in there too.

Please note I'm not trying to hijack your project! Just suggesting a better way to store your data. :)

0

Sorry for not getting to this last night, my 14 week old daughter didn't want to sleep and kept me occupied!

So I now have the 3 tables you done for me, I changed sex back to varchar as it could either be 'male' 'female' 'unsexed' 'pair' etc, I also changed year back to varchar as it could be the year of birth/hatching '2010' or maybe 'unknown' or even '2010 approx'.

The joining query you posted has me somewhat bewildered though. I am unsure where to use this.
I am sorry for hassling you, but could you explain tto me where to put this query?

Thank you...................

0

Once you've created (and changed) the 3 tables to your liking, you then paste the 'joining query' into the SQL window in your favourite GUI (phpmyadmin or other) and RUN.

0

I'm getting this error when I paste the query.

1064 - 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 '1 AS subcat_id FROM boids) UNION ALL (SELECT species,year,sex,' at line 2

0

Thanks, but it turns out that I actually dont have much of a clue. Now i'm getting this error.

Table 'reptile.boids' doesn't exist

0

As utrivedi states (comma after the price - like this):

INSERT INTO animals (`species`,`year`,`sex`,`price`,`subcat_id`) 
(SELECT `species`,`year`,`sex`,`price`, 1 AS `subcat_id` FROM `boids`) 
    UNION ALL 
(SELECT `species`,`year`,`sex`,`price`, 2 AS `subcat_id` FROM `coloubrids`) 
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 3 AS `subcat_id` FROM `other_snakes`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 4 AS `subcat_id` FROM `agmids`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 5 AS `subcat_id` FROM `geckos`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 6 AS `subcat_id` FROM `monitors`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 7 AS `subcat_id` FROM `other_lizards`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 8 AS `subcat_id` FROM `tortoises`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 9 AS `subcat_id` FROM `turtles`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 10 AS `subcat_id` FROM `frogs`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 11 AS `subcat_id` FROM `other_amphibs`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 12 AS `subcat_id` FROM `arachnids`)
    UNION ALL
(SELECT `species`,`year`,`sex`,`price`, 13 AS `subcat_id` FROM `other_inverts`)

Edited by diafol

0

You said that you had all these tables in your db, that's why I used their names in the 'combining query'. So do you have a 'boids' table or not?

0

Hi, sorry for the delay in replying, my wifes away for a few days and im a one man parenting machine!

So I put your 3 tables in the wrong db, the query would works as my 'boids' etc tables are in another db, I have corrected that now.

I am unsure how to add animals now though. This is what I tried in .

lizardstockupdate.php

 //if evetrything is ok continue with form post
   if ($aspecies && $ayear && $asex && $aprice)
   {
    //if form has been posted, add details to mysql
      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
         if (isset($_POST['submit'])) 
         {
            //check which radio button has been checked
            $selected_radio = $_POST['lizards'];

            if ($selected_radio == 'Monitors')
            {
               $subcat == 6;
               mysql_query("INSERT INTO animals (animal_id, species, year, sex, price, subcat_id)
                             VALUES ('', '$aspecies', '$ayear', '$asex', '$aprice', '$subcat')");
                mysql_query("INSERT INTO $selected_radio (id, species, year, sex, price)
                             VALUES ('', $aspecies', '$ayear', $asex', '$aprice'')");
            }

          }
       }
    }

This adds details to my 'animals' table but put in 0 to subcat_id instead of 6
It adds nothing to my 'monitors' table.

Am I way off on this?

0

OK so now I have the details adding to both tables, but animal-id in 'animals' and id in 'monitors' are different.
This is the code now

//if evetrything is ok continue with form post
   if ($aspecies && $ayear && $asex && $aprice)
   {
    //if form has been posted, add details to mysql
      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {
         if (isset($_POST['submit'])) 
         {
            //check which radio button has been checked
            $selected_radio = $_POST['lizards'];
            if ($selected_radio == 'monitors')
            {
              $subcat = 6; //I changed this to a single '=' and it worked

              mysql_query("INSERT INTO animals (animal_id, species, year, sex, price, subcat_id)
                             VALUES ('', '$aspecies', '$ayear', '$asex', '$aprice', '$subcat')");
              mysql_query("INSERT INTO monitors (id, species, year, sex, price)
                           VALUES ('', '$aspecies', '$ayear', '$asex', '$aprice')");

            }


          }
       }
    }

Am I on the right track?

Thanks for looking.............

0

No. You no longer need a monitors, other_lizards tables etc. If you've backed up your db, just delete them. ALL animals go into the animals table, regardless of their subcat. The subcat can be set in your add form, like a dropdown:

<?php
//connection details here

$op = '';
$r = mysql_query("SELECT subcat_id, subcat_label FROM subcategories ORDER BY cat_id");
if(mysql_num_rows($r)){
    $d = mysql_fetch_assoc($r)){
        $op .= "\n\t<option value='{$d['subcat_id']}'>{$d['subcat_label']}</option>";
    }
}
?>

<!--within the form-->
<select id="subcat">
    <?php echo $op;?>
</select>

You simply pick up the subcategory like this from the submitted form:

$subcat = intval($_POST['subcat']);

Just add this to your INSERT query in the relevant place.

0

Thanks for your patience.

When I run this code I get this error
Parse error: syntax error, unexpected ')' in C:\wamp\www\reptrial\cheloniastocklistupdate.php on line 10

If I take out the ')' I get this error
Parse error: syntax error, unexpected '{' in C:\wamp\www\reptrial\cheloniastocklistupdate.php on line 11

0

I have no idea what code is on this line. COuld you post it please and the line either side of it.

0
if(mysql_num_rows($r)){
    $d = mysql_fetch_assoc($r)){ //This is the line
        $op .= "\n\t<option value='{$d['subcat_id']}'>{$d['subcat_label']}</option>";
    }
}

Any ideas why?

0

try

while($d = mysql_fetch_assoc($r)){ //This is the line

Somehow 'while' got lost/ :(

Edited by diafol

0

I'm now getting this error
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\reptrial\cheloniastocklistupdate.php on line 36

$r = mysql_query("SELECT subcat_id, subcat_label FROM subcategories ORDER BY cat_id");
if(mysql_num_rows($r)){ //The error is on this line
   while ($d = mysql_fetch_assoc($r)){
        $op .= "\n\t<option value='{$d['subcat_id']}'>{$d['subcat_label']}</option>";
    }
}
0

Ahhhh, thats sorted now. It was a simple typo! My dropdown box is now populated with all the subcategories.............

0

Almost I think!

I have this

 if (isset($_POST['submit'])) 
         {  


$subcat = intval($_POST['subcat']);



               mysql_query("INSERT INTO animals (animal_id, species, year, sex, price, subcat_id)
                             VALUES ('', '$aspecies', '$ayear', '$asex', '$aprice', '$subcat')");

          }

Now I'm getting this error

Notice: Undefined index: subcat in C:\wamp\www\reptrial\cheloniastocklistupdate.php on line 72
The error is at the line

$subcat = intval($_POST['subcat']);

Do I have this in the wrong place??

0

Without seeing your form, it's difficult to say. In order for this to work, your dropdown/select should look like this:

<select name="subcat">
 ...
</select>
0

I know this is a lot for you to look at, but heres the form and php.

I cant figure it out as my select name is 'subcat'! Maybe I'm missing something?

<?php
   include 'connect.php';
   $op = '';
   $r = mysql_query("SELECT subcat_id, subcategory_label FROM subcategories ORDER BY subcat_id");
   if (mysql_num_rows($r)){
      while ($d = mysql_fetch_assoc($r)){
         $op .= "\n\t<option value='{$d['subcat_id']}'>{$d['subcategory_label']}</option>";
      }
   }



   //if form has been posted, add details to mysql
      if ($_SERVER['REQUEST_METHOD'] == 'POST')
      {


   if ($aspecies && $ayear && $asex && $aprice)
   {


         if (isset($_POST['submit'])) 
         {  
            $subcat = intval($_POST['subcat']);

               mysql_query("INSERT INTO animals (animal_id, species, year, sex, price, subcat_id)
                             VALUES ('', '$aspecies', '$ayear', '$asex', '$aprice', '$subcat')");

          }
       }
    }






?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Stocklist update</title>
<link href="gallery_submit.css" rel="stylesheet" type="text/css" />
<link href="template.css" rel="stylesheet" type="text/css" />
<body>

   <div class="span4">
      <p>Livestock Upload Form</p>
   </div>
<form class="form" action="cheloniastocklistupdate.php" method="post" enctype="multipart/form-data" name="stockupdate_form" id="stockupdate_form" style="margin-bottom:0px;">
<h1 style="margin-bottom: 0px">Fill in all the details:</h1>
<label><span class="span2">Tortoises/Turtles</span></label>
<p><input type=text name="aspecies"> <b>Species</b></p>
<p><input type=text name="ayear"> <b>Year</b></p>
<p><input type=text name="asex"> <b>Sex</b></p>
<p><input type=text name="aprice"> <b>Price</b></p>
<p><label><span class="span2">Choose category best suited to animal</span></label></p>
<select name="subcat">
    <?php echo $op;?>
</select>

<input type="submit" name="submit" value="Update stock" />
<input name="submitted_form" type="hidden" id="submitted_form" value="stockupdate_form" />
</form>

</body>
</html>
1

Not obvious to me, but post routine looks a bit too complex:

if (isset($_POST['submit'])){  
    print_r($_POST); //have a look
    $aspecies = mysql_real_escape_string($_POST['aspecies']);
    $ayear = mysql_real_escape_string($_POST['ayear']);
    $asex = mysql_real_escape_string($_POST['asex']);
    $aprice = mysql_real_escape_string($_POST['price']);
    $subcat = intval($_POST['subcat']);
    $r = mysql_query("INSERT INTO animals (animal_id, species, year, sex, price, subcat_id) VALUES ('', '$aspecies', '$ayear', '$asex', '$aprice', '$subcat')");
}else{
    echo "no post data"; //for testing
}

I don't think you need the $_REQUEST stuff.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.