Rizzuti 0 Newbie Poster

Hi,

I'm trying to check if the user that im deleting exist in the database before deleting them, but it does not recognise the id (delID) the second time that i enter the id (even if it is right).

Any suggestion

delete(){
clear
echo "-------------"
echo "DELETE RECORDS"
echo "-------------"
read -p "Please enter staff id that you wish to delete: " delID

indelID=$(grep $delID ~/appraisal/work.db | cut -d":" -f1)
surname=$(grep $delID ~/appraisal/work.db | cut -d":" -f2)
name=$(grep $delID ~/appraisal/work.db | cut -d":" -f3)

while [[ "$(echo $delID | grep -c '^[0-9][0-9][0-9]$')" = 0 || $delID = $inlID ]]
do
read -p "The staff ID entered is incorrect, please try again: " delID
done
echo "Would you like to delete $name $surname from the database? (press y or n)"
read ans

if [[ $ans = y* || $ans = Y* ]]
then
sed -i "/$delID/d" ~/appraisal/work.db
echo "record deleted!"
else [$ans != n ]
menu
fi
read -p "Press return access the main menu " main
menu
}

Thanks

Rizzuti 0 Newbie Poster

yes! brilliant, it works!
I should have thought about it!
Thank you so much.

Rizzuti 0 Newbie Poster

Hello there, I've got a search box that finds the item that I look for but it doesn't display the id number when i put the mouse cursor on top on the item. instead of showing the id number it shows the variable ($id). Any idea why this is not working?

Here is the code that I use in the while loop:

while ($rows = mysql_fetch_assoc($rsd)){
$id = $rows['itemID'];
?>
	<div class="each_rec"><a href="item_Details.php?itemID=$id" target="_blank"><?php echo $rows['itemName'];?></a></div>
<?php
}
if($total==0){ echo '<div class="no-rec">No Record Found !</div>';}?>

when I put the cursor over the link it display this:

http://localhost/item_Details.php?itemID=$id

instead of

http://localhost/item_Details.php?itemID=7

Thanks

Rizzuti 0 Newbie Poster

Yes I use a multipart/form-data, the form is redirected to the upload.php and the only place I save the images is in the database. Because I'm trying to display images and also text from two different tables, therefore i do that by using their IDs.

upload.php

if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0)
{
$itemName = $_POST ['itemName'];
$CID = $_POST ['CID'];
$item_Description = $_POST ['item_Description'];
$price = $_POST ['price'];
$contactName = $_POST ['contactName'];
$phone = $_POST ['phone'];
$email = $_POST ['email'];
$website = $_POST ['website'];

$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$pix = fread($fp, filesize($tmpName));
$pix = addslashes($pix);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$sqlItem = "INSERT INTO items (itemName, categoryID, item_Description, price, contactName, phone, email, website, submitDate)".
		"VALUES ('$itemName', '$CID', '$item_Description', '$price', '$contactName', '$phone', '$email', '$website', CURDATE())";


if (@mysql_query ($sqlItem)) {
	  echo('<p>Thank you for your posting. If you wish your item or other items go to Classifieds</p>');
	  } 
	else {
	  echo('<p>Error adding submitted ad: ' .mysql_errno().'-'.
            mysql_error() . '</p>');
	  }
	}
    
	  echo('<p><a href="postad.php"> Post another ad!</a></p>');
	  echo ('<p><a href="Classifieds.php"> Classifieds</a></p>');
	  echo ('<p><a href="index.php"> Home</a></p>'
		);
$lastID = mysql_insert_id();

$sqlImg = "INSERT INTO images (itemID, categoryID, name, size, type, pix) "." VALUES ('$lastID', '$CID', '$fileName', '$fileSize', '$fileType', '$pix')";

mysql_query($sqlImg) or die('<p>Error, query failed ' .mysql_errno().'-'.mysql_error() .'</p>');

echo "<br>File $fileName uploaded<br>";

I have inserted an image manually but it does the same thing!
Also I added a header

header("Content-type: ".$row['type']."");

and the browser just display this:
"item_Details.php?itemID=2", which …

Rizzuti 0 Newbie Poster

Hello I'm trying to display images from my database using blob but the browser diplays them in a unusual way.

This is what I get!!!
<82<.231 1!!11111111111111111111111111111111111111111111111111������������� ������� ���}�!1AQa"q2���#B��R��$3br�

What is it that i'm doing wrong? I tried adding a header(contect-type:image.jpeg) but is not working for me :(

Here is the code:

<?php
//database info in misc.inc
include("misc.inc");
//Get item ID
$id = $_GET["itemID"];
$db = 0;
//Connect to database
$db = mysql_connect($db_host . ":" . $db_port, $db_user, $db_pwd);
if ($db == 0) {die("Cannot connect, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

mysql_query("USE " . $db_db);
if (mysql_errno() != 0) {die("Cannot USE database, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};
//fetch data from database
$query1 = "SELECT * FROM images, items WHERE (images.itemID='$id' && items.itemID='$id')";
$result = mysql_query($query1);
while ($row = mysql_fetch_array ($result))
{
echo"<table>";
echo"<tr>";
echo"<td colspan='2'>
  <h2 style='font-size: large;'> ".$row['itemName']."</h2></td>\n";
 echo "</tr>";
 echo "<tr>";
echo"<td><img border='0' align='right' src='../images/{$row['pix']} alt='item Image' style='margin-left: 5px;'></td>\n";
echo"<tr>";
echo"<td colspan='2'>
   <div>     
         <b>Price: </b>&pound;" .number_format ($row['price'],2). "<br />
         <b>Posted On: </b>" .$row['submitDate']. "<br />\n
         </div><br>
<b>Description: </b><p>" .$row['item_Description']. "<p><br />
 <div ;='' style=clear: both;>
  <h4 style='font-size: medium;'>Contact details:</h4>
<b>Name: </b>" .$row['contactName']. "<br />
<b>E-mail: </b>".$row['email']." <br /><br />  
</div></td>\n";
echo"</tr>\n";
}
echo "</table><br/>";
?>

Thanks a lot

Rizzuti 0 Newbie Poster

Sorry i haven't get back any earlier, it working now!!!

<?php
 
include("misc.inc");

$db = 0;
$db = mysql_connect($db_host . ":" . $db_port, $db_user, $db_pwd);
if ($db == 0) {die("Cannot connect, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

mysql_query("USE " . $db_db);
if (mysql_errno() != 0) {die("Cannot USE database, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

if (@$_POST['goBack'] == "Cancel")
{
	header("Location: index.php");
}

if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0)
{
$itemName = $_POST ['itemName'];
$CID = $_POST ['CID'];
$item_Description = $_POST ['item_Description'];
$price = $_POST ['price'];
$contactName = $_POST ['contactName'];
$phone = $_POST ['phone'];
$email = $_POST ['email'];
$website =$_POST ['website'];

$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$pix = fread($fp, filesize($tmpName));
$pix = addslashes($pix);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
$sql = mysql_query("INSERT INTO items (itemName, categoryID, item_Description, price, contactName, phone, email, website, submitDate)".
		"VALUES ('$itemName', '$CID', '$item_Description', '$price', '$contactName', '$phone', '$email', '$website', CURDATE())");


if (@mysql_query ($sql)) {
	  echo('<p>Thank you for your posting. If you wish your item or other items go to Classifieds</p>');
	  } 
	else {
	  echo('<p>Error adding submitted ad: ' .mysql_errno().'-'.
            mysql_error() . '</p>');
	  }
	}
    
	  echo('<p><a href="postad.php"> Post another ad!</a></p>');
	  echo ('<p><a href="Classifieds.php"> Classifieds</a></p>');
	  echo ('<p><a href="index.php"> Home</a></p>'
		);

$lastID = mysql_insert_id();

$sql1 = "INSERT INTO images (itemID, categoryID, name, size, type, pix) 
"." VALUES ('$lastID', '$CID', '$fileName', '$fileSize', '$fileType', '$pix')";

mysql_query($sql1) or die('<p>Error, query failed ' .mysql_errno().'-'.mysql_error() .'</p>');

echo "<br>File $fileName uploaded<br>";
?>

I removed itemID and imageID from the queries …

Rizzuti 0 Newbie Poster
<input type="hidden" name="itemID" value="<?=$itemID?>"/><br /><br />

I removed the foreign key from the image table (`images_ibfk_1`) and it is not giving me this error anymore. However, the itemID in the items table and the itemID in images table doesn't much. I wonder if there is a way of moving the itemID from items to images without linking these two tables.

Rizzuti 0 Newbie Poster

I added the value $itemID but it's still giving me the same error. So I think there is something wrong with the relationship between the tables!!!

Anyway, I'll carry on looking. thanks for your help

Rizzuti 0 Newbie Poster

This is the upload.php, which I editted last...I'm really sorry i dont want to waste your time, but i've got some many scripts that sometime i get confused... i'm new in php and therefore i've been editing them for a long time due to so many errors!!

I really appreciate your help smantscheff, I'll make sure the script i post are the right ones!!!

upload.php

<?php
 
include("misc.inc");

$db = 0;
$db = mysql_connect($db_host . ":" . $db_port, $db_user, $db_pwd);
if ($db == 0) {die("Cannot connect, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

mysql_query("USE " . $db_db);
if (mysql_errno() != 0) {die("Cannot USE database, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

if (@$_POST['goBack'] == "Cancel")
{
	header("Location: index.php");
}

if(isset($_POST['submit']) && $_FILES['userfile']['size'] > 0)
{
$itemID = $_POST ['itemID'];
$imageID =$_POST ['imageID'];	
$itemName = $_POST ['itemName'];
$CID = $_POST ['CID'];
$item_Description = $_POST ['item_Description'];
$price = $_POST ['price'];
$contactName = $_POST ['contactName'];
$phone = $_POST ['phone'];
$email = $_POST ['email'];
$website =$_POST ['website'];

$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$pix = fread($fp, filesize($tmpName));
$pix = addslashes($pix);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

$sql = "INSERT INTO items SET
		itemID = '$itemID',
		itemName = '$itemName',
		categoryID = '$CID',
		item_Description = '$item_Description',
		price = '$price',
		contactName = '$contactName',
		phone = '$phone',
		email = '$email',
		website ='$website',
		submitDate = CURDATE()";

if (@mysql_query ($sql)) {
	  echo('<p>Thank you for your posting. If you wish your item or other …
Rizzuti 0 Newbie Poster

apologises! let start again,
Here is the error:

Error, query failed 1452-Cannot add or update a child row: a foreign key constraint fails (`mn000532_almacen`.`images`, CONSTRAINT `images_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE)

Here are the table:

CREATE TABLE `categories` (
 `CategoryID` int(5) NOT NULL DEFAULT '0',
 `cat_Description` varchar(50) NOT NULL,
 PRIMARY KEY (`CategoryID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `items` (
 `itemID` int(5) NOT NULL AUTO_INCREMENT,
 `categoryID` int(5) NOT NULL,
 `itemName` char(25) NOT NULL,
 `item_Description` varchar(255) DEFAULT NULL,
 `price` char(10) DEFAULT NULL,
 `contactName` varchar(50) DEFAULT NULL,
 `phone` char(15) DEFAULT NULL,
 `email` varchar(50) DEFAULT NULL,
 `website` char(25) NOT NULL,
 `submitDate` date NOT NULL,
 `expireDate` date NOT NULL,
 PRIMARY KEY (`itemID`,`categoryID`),
 KEY `submitDate` (`submitDate`),
 KEY `categoryID` (`categoryID`),
 CONSTRAINT `items_ibfk_1` FOREIGN KEY (`categoryID`) REFERENCES `categories` (`CategoryID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE `images` (
 `imageID` int(5) NOT NULL AUTO_INCREMENT,
 `itemID` int(5) NOT NULL,
 `name` varchar(30) NOT NULL,
 `size` int(11) NOT NULL,
 `type` varchar(30) NOT NULL,
 `pix` mediumblob NOT NULL,
 PRIMARY KEY (`imageID`),
 KEY `itemID` (`itemID`),
 CONSTRAINT `images_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Here are the script i use to upload the images and text
form: postad.php

<form action = "upload.php" method = "POST" enctype="multipart/form-data">
<select name="CID" size="1">
<option selected value="">Select Category</option>
<?php
while ($cat = mysql_fetch_array($cats)) {
$CID = $cat['categoryID'];
$catDescription = htmlspecialchars($cat['cat_Description']);
echo("<option value='$CID'>$catDescription</option>\n");
}
?>
</select><br /> <br />
<p>
<b>Title of ad: </b><input type="text" name="itemName" id="itemName"/><br /><br />
<b>Description: </b><br />
<textarea …
Rizzuti 0 Newbie Poster

Hello! I’ve got three tables that I want to link together. When I try to upload images and text throught a form, the web browser show this error message:

Error, query failed 1452-Cannot add or update a child row: a foreign key constraint fails (`mn000532_almacen`.`images`, CONSTRAINT `images_ibfk_1` FOREIGN KEY (`itemID`) REFERENCES `items` (`itemID`) ON DELETE CASCADE)

The itemID field is used in my php script($_GET["itemID"]) to retrieve the all the info about a certain item therefore it needs to be the same in all tables.

CREATE TABLE categories (
categoryID INT(5) NOT NULL,
cat_Description VARCHAR(50),
PRIMARY KEY (itemID)
)TYPE = INNODB;

CREATE TABLE items (
itemID INT(5) NOT NULL AUTO_INCREMENT,
categoryID INT(5) NOT NULL,
itemName CHAR(25) NOT NULL,
item_Description VARCHAR(255),
price CHAR(10),
contactName VARCHAR(50),
phone CHAR(15),
email VARCHAR(50),
website CHAR (25),
submitDate DATE NOT NULL,
expireDate DATE NOT NULL,
PRIMARY KEY(itemID,categoryID),
INDEX (submitDate),
FOREIGN KEY (categoryID) REFERENCES categories (categoryID)
ON DELETE CASCADE
)TYPE = INNODB;

CREATE TABLE images (
imagesID INT (5) NOT NULL AUTO_INCREMENT,
itemID INT (5) NOT NULL,
name VARCHAR (30) NOT NULL,
size INT (11) NOT NULL,
type VARCHAR (30) NOT NULL,
pix MEDIUMBLOB NOT NULL,
PRIMARY KEY(imagesID),
FOREIGN KEY (itemID) REFERENCES items (itemID)
ON DELETE CASCADE
)TYPE = INNODB;

Thank you

Hernan

Rizzuti 0 Newbie Poster

Well spotted geertc!!

thank you very much.

Hernan

Rizzuti 0 Newbie Poster

Hello!!

I'm trying to upload images and text onto my database but i have a bit of a problem...

Error, query failed 1136-Column count doesn't match value count at row 1

I dont know if the problem is the script or the actuall database, I google it but I couldn't get anywhere on this one!
Sorry if the code is a bit long!
Here is the database structure

CREATE TABLE categories (
categoryID INT(5) NOT NULL,
cat_Description VARCHAR(50),
PRIMARY KEY (itemID)
)TYPE = INNODB;

CREATE TABLE items (
itemID INT(5) NOT NULL AUTO_INCREMENT,
categoryID INT(5) NOT NULL,
itemName CHAR(25) NOT NULL,
item_Description VARCHAR(255),
price CHAR(10),
contactName VARCHAR(50),
phone CHAR(15),
email VARCHAR(50),
website CHAR (25),
submitDate DATE NOT NULL,
expireDate DATE NOT NULL,
PRIMARY KEY(itemID,categoryID),
INDEX (submitDate),
FOREIGN KEY (categoryID) REFERENCES categories (categoryID)
ON DELETE CASCADE
)TYPE = INNODB;

CREATE TABLE images (
imagesID INT (5) NOT NULL AUTO_INCREMENT,
itemID INT (5) NOT NULL,
name VARCHAR (30) NOT NULL,
size INT (11) NOT NULL,
type VARCHAR (30) NOT NULL,
pix MEDIUMBLOB NOT NULL,
PRIMARY KEY(imagesID),
FOREIGN KEY (itemID) REFERENCES items (itemID)
ON DELETE CASCADE
)TYPE = INNODB;

And here are the scripts one is the form to upload images and the text (postad.php) and the other one is the php and sql script to upload the details onto the database.

postad.php

<form action = "upload.php" method = "POST" enctype="multipart/form-data">
<select name="CID" size="1">
<option selected value="">Select Category</option>
<?php
while ($cat = mysql_fetch_array($cats)) {
$CID = $cat['categoryID'];
$catDescription = …
Rizzuti 0 Newbie Poster

Excellent. it works like this:
$query1 = "SELECT * FROM images, items WHERE (images.itemID=$id && items.itemID=$id)";
without the exit;

Thank you very much you both guys!

Rizzuti 0 Newbie Poster

I was wondering if you guys can help me with this! I'm trying to display data on the items_Deltails.php page from classifieds1.php page using $_GET. I'm able display all data from items table without any problem, however when i try to display the field pix from the images table it comes up with this message "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\web\htdocs\Item_Details.php on line 35".

I've two different tables one clled items (itemID, categoryID, item_Description, itemName, price, contactNAme, phone and email) and the other one called images (itemID, categoryID and pix).
I'm sure the there is something from with the mysql command "SELECT * FROM" in item_Details.php

Here is the code for classifieds1.php

<?php
echo "<h1>List of all items</h1>";
//database info in misc.inc
include("misc.inc");
$table = "items";
$db = 0;
$db = mysql_connect($db_host . ":" . $db_port, $db_user, $db_pwd);
if ($db == 0) {die("Cannot connect, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

mysql_query("USE " . $db_db);
if (mysql_errno() != 0) {die("Cannot USE database, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

$query1 = "SELECT * FROM items WHERE categoryID='3'";
$result = mysql_query($query1);
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);

echo"<table id=mytable cellspacing=0 summary=Items from almacen database>
<caption>Books, CDs and DVDs: </caption>";
echo "<TR bgcolor=\"lightblue\"><TH>Item Name</TH><TH>Price</TH><TH>Posted On</TH></TR>\n"; 
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set …