0

I have striped my insert statement and rebuilt it thinking that would solve the problem, it has not. The statement will not add any data at all, can any one see why its not working?

index.php

<form method="post" action="insert.php">

    Name Of Band:</br>
    <input type="text" name="Name" /><br />

    Show Name:</br>
    <input type="text" name="show" /><br />

    Venue:</br>
    <input type="text" name="Venue" /><br />

    Category:</br>
    <input type="text" name="Category" /><br />

    Price:</br>
    <input type="text" name="price" /><br />

    Stock:</br>
    <input type="text" name="Stock" /><br />

    Infomation:</br>
    <input type="text" name="infomation" /><br />

    <input type="submit" value="Add Band"/>

</form>

insert.php

     <?php
require 'core/init.php';
$Name = $_REQUEST["Name"];
$show = $_REQUEST["show"];
$Venue = $_REQUEST["Venue"];
$Category = $_REQUEST["Category"];
$price = $_REQUEST["price"];
$Stock = $_REQUEST["Stock"];
$infomation = $_REQUEST["infomation"];


$query = "INSERT INTO `bands` (`Name`, `show`, `Venue`, `Category`, `price`, `Stock`, `infomation`) VALUES ('$Name', '$show', '$Venue', '$Category', '$price', '$Stock', '$infomation')";

mysql_query ($query, $linkme)
    or die ("could not add to database");
    header("location:admin.php");
?>

schema

     DROP TABLE IF EXISTS `bands`;
CREATE TABLE IF NOT EXISTS `bands` (
  `Band_id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(20) NOT NULL,
  `show` varchar(22) NOT NULL,
  `Venue` varchar(20) NOT NULL,
  `Category` varchar(20) NOT NULL,
  `price` int(11) NOT NULL,
  `Stock` int(11) NOT NULL,
  `infomation` varchar(20) NOT NULL,
  PRIMARY KEY (`Band_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

nothing wrong with connection as many insert update and delete query use it.

Beep
  • 2,737
  • 7
  • 36
  • 85

1 Answers1

3

Your query is fine.

Your table has multiple fields that are declared not null, such as stock and information and so on. These have no default values, so your insert is failing.

You have several choices:

  • Change the columns to allow NULL
  • Provide values for them in the insert
  • Provide default values
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786