Jump to content

[SOLVED] Database won't accept more than one item!


Recommended Posts

Here is the code for my interface:

<?php
session_start();
?>

<html>
<head>
<title>Multimedia Library - New Item Entry</title>
</head>

<body>
<h1>Multimedia Library - New Item Entry</h1>

<?php
//create short variable names


$UPC=$_POST['UPC'];
$title=$_POST['Title'];
$MajorAttribute=$_POST['MajorAttribute'];
$SecondaryAttribute=$_POST['SecondaryAttribute'];
$itemtype = $_SESSION['itemtype'];

if(!$UPC || !$title || !$MajorAttribute || !$SecondaryAttribute || !$itemtype)
{

echo 'You have not entered all the required details. <br />'
     	     .'Please go back and try again.';
exit;
}

$UPC=addslashes($UPC);
$title=addslashes($title);
$MajorAttribute=addslashes($MajorAttribute);
$SecondaryAttribute=addslashes($SecondaryAttribute);
$itemtype=addslashes($itemtype);

@ $db = mysql_pconnect('school', 'library', 'alpha321');

if(!$db)
{
echo 'Error: Could not connect to database. Please try later.';
exit;
}

mysql_select_db('cisse');

$query = "insert into Library_Asset values 
 ('".$UPC."','".$title."','".$MajorAttribute."','".$SecondaryAttribute."','".$itemtype."')";

echo '<br />';
echo $query;
echo '<br />';

$result = mysql_query($query);

if($result)
{
  	echo mysql_affected_rows().' item(s) inserted into database.<br /><br />';
echo 'You entered: <br />';
echo $UPC;
echo '<br />';
echo $title;
echo '<br />';
echo $MajorAttribute;
echo '<br />';
echo $SecondaryAttribute;
echo '<br />into the Library';
echo '<br /><br />';
}
?>
<INPUT TYPE = BUTTON Value = "Add Another Item" onClick="window.location.href='http://www.kr3m3r.com/newitem.html'"> 

</body>
</html>

 

and here is the query which set up the database:

SQL query: 
CREATE TABLE `Library_Asset` ( 
`UPC` INT( 13 ) UNSIGNED NOT NULL ,
`Title` CHAR( 100 ) NOT NULL ,
`MajorAttribute` CHAR( 100 ) NOT NULL ,
`SecondaryAttribute` CHAR( 100 ) NOT NULL ,
PRIMARY KEY ( `UPC` ) 
) ;

 

I can add a number of items with UPC values of 123 or 234 or 001234 but for some reason when I attempted to enter a few items to test the database, it will only add the first item I add.  Two of the test cases were:

0024543151906

iRobot

Alex Proyas

Will Smith

 

and

0042284347921

Live at the Apollo 1962

James Brown

PolyGram Records

 

which ever one I entered first would be added to the table with no problem (I looked at it through the command line interface) but when I'd go to add the other item, it would fail.  (I tried deleting each item from the database, and then starting with the other, and only the first one entered would be added to the table, the second one would not be added to the table).

 

Any help in reasolving this issue would be greatly appreciated.

-Robb

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.