473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Blank Row added to database when existing row found

155 100+
I'm creating (trying to create) a picture gallery for my website.

The script is not working. I've been working on it now for about 80 hours with no success. My php skills aren't very good.

This picture gallery uses 2 mysql tables: acwrtcats and acwrtpics

The table acwrtcats has 2 fields: cat_name and cat_desc. The cat_name is the name of a category that pictures will be filed under, and cat_desc is a brief description of the category.

My picture information is stored in the table acwrtpics. This contains the fields: id, cat_name, title, desc, image_name, thumb_w, thumb_h.

When the image upload page is called an IF statement is used to determine if the table is empty or has categories. If no entries are found a form with a standard text input field is displayed to allow me to type in a name for a new category.

If there are entries found, a form with a drop-down list is presented and populated with the catgories found in the acwrtcats table, and a standard text input field is displayed under the drop-down list. I can either select an existing category for my image to be filed using the drop-down list or create a new category to be entered into the acwrtcats table via the text input field.

Below all this is the fields pertaining to the acwrtpics table.

When submitted it goes to the image_processing.php page where a thumbnail is created and the original image and newly created thumbnail image is placed into separate folders on the server. This page also processes the information for table insertion.

This is where I'm running into trouble. Much of this script isn't working and I don't know how to fix it.

The script is suppose to check whether or not the category name I chose on the upload page already existed in the acwrtcats table. If the name already exist then don't add it again, skip over this part and go straight to adding the picture information into the acwrtpics table.

If the category name (cat_name) does not exist in the acwrtcats table - add it.

This part is not working. If the name exists it advances the table by one. No cat_name or cat_desc is being added - just a blank row is being created. I was hoping that it would just leave this table alone if the name existed and if not add the information and the proceed to entering the information into the acwrtpics table.

The images are being created and uploaded into their respective folders and the image information is being added to the acwrtpics table - all except the row =cat_name.

The name of the category comes to this page via [PHP]$cat_name = $_GET['cat_name'];[/PHP].

Any help with this would be very much appreciated.

Here are the codes from the image_upload.php and the image_process.php:
[PHP]// image_upload.php

include("includes/dbconnect.php");
$query = "SELECT * FROM $cat";
$result = mysql_query($query) or die('Error, query failed');

if (mysql_num_rows($result) == 0) {

echo "
Add a new Category:<br>
<input type='text' size='55' name='cat_name'><br>
Category Description:<br>
<textarea name='cat_desc' rows='2' cols='55' wrap=virtual></textarea><br><br>
";

} else {

echo "
Select a Category for your Picture:<br>
<select name='cat_name'>
<option value'' selected='selected'></option>
";

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

$id = $row['id'];
$cat_name = stripslashes($row['cat_name']);

echo "

<option value='$cat_name'>$cat_name</option>
";

}
}

echo "
</select><br><br>

Or Add a new Category:<br>
<input type='text' size='55' name='cat_name'><br>
Category Description:<br>
<textarea name='cat_desc' rows='2' cols='55' wrap=virtual></textarea><br><br><br>
";

---- image upload form here ----[/PHP]

[PHP]// image_process.php

---- Image handling script here ----

/*
* Here is where information is inserted into databases:
*/


include("includes/dbconnect.php");

$cat_name = $_GET['cat_name'];

// Make sure Category doesn't already exist, if it does skip down to second section
$query = "SELECT cat_name FROM $cat WHERE cat_name = '$cat_name'";
$result = mysql_query($query) or die('Error, query failed: ' . mysql_error());

if (mysql_num_rows($result) == 1)

{

// Make the query

$cat_name = mysql_real_escape_string($_POST['cat_name']);
$title = mysql_real_escape_string($_POST['title']);
$desc = mysql_real_escape_string($_POST['desc']);
$thumb_w = $t_width;
$thumb_h = $t_height;
$width = $width;
$height = $height;

$query = "INSERT INTO $table VALUES ('', '$cat_name', '$title', '$desc', '$image_name', '$thumb_w', '$thumb_h', '$width', '$height')";
$result = mysql_query($query);

echo "<h2 style='color: #090'>Success! New Category and Picture Added</h2>
<br>
<a href='index_c.php'>View Pics</a>
<br><br>
<a href='image_upload_d.php'>Add Another Pic</a>
";

}

else

{

$cat_name = mysql_real_escape_string($_POST['cat_name']);
$cat_desc = mysql_real_escape_string($_POST['cat_desc']);


$query = "INSERT INTO $cat VALUES ('$cat_name', '$cat_desc')";
mysql_query($query);

$cat_name = mysql_real_escape_string($_POST['cat_name']);
$title = mysql_real_escape_string($_POST['title']);
$desc = mysql_real_escape_string($_POST['desc']);
$thumb_w = $t_width;
$thumb_h = $t_height;
$width = $width;
$height = $height;

$query = "INSERT INTO $table VALUES ('', '$cat_name', '$title', '$desc', '$image_name', '$thumb_w', '$thumb_h', '$width', '$height')";
$result = mysql_query($query);

echo "<h2 style='color: #090'>Success! Picture Added</h2>
<br>
<a href='index_c.php'>View Pics</a>
<br><br>
<a href='image_upload_d.php'>Add Another Pic</a>
";


mysql_close();
}
[/PHP]
Jun 18 '07 #1
2 2039
pbmods
5,821 Expert 4TB
Changed thread title to actually describe the problem (did you know that thread titles that contain phrases such as 'please help' and 'quick problem' actually get FEWER responses?).

Heya, DavidPr.

Try using a REPLACE statement instead of INSERT.
Jun 18 '07 #2
bonski
53
ei davidpr,

just an idea.. i think db design is quite essential also... designing your db table on how they are related...

acwrtcats
cat_id
cat_name
cat_desc

acwrtpics
image_id
cat_id
title
desc
image_name
thumb_w
thumb_h
i think for the table acwrtcats you should have a unique id also.. which is also found in table acwrtpics, and that is cat_id, just like you had (cat_name).. but your using string.. sometimes string aren't good to use... better use id(int) so that you'll have unique ids...^__^
Jun 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: charlie_M | last post by:
Is there a way to blank the screen in a FORM's onsubmit=... to blank the screen for the user?? I asked this before and got a way to blank a table by id with ...
1
by: Magnus | last post by:
I have created an application with VB in Visual Studio .Net. The application use a SQL server as database. Can anyone explain how I include the database when i make a setup for my application?...
3
by: lieven.becue | last post by:
Situation: at work we have a windows 2003 server with MS sql server 2005 express. With my pc at work, I can see my own database I created. At home. I can connect with VPN to the network. With...
0
by: sensreview | last post by:
Hi, I am new to MS Access. I have managed to create a simple Access database for my team. I want the database to be used as client /server. Can you suggest creating a Access project database...
12
by: Birky | last post by:
How can I stop a form from updating the database when a user closes the form? I have a form which is used for referencing, additions, and modifications but every time the form is closed with no...
3
by: Max2006 | last post by:
Hi, I have a search result GridView bound to an ObjectDataSource. Once I open the asp.net page, the ObjectDataSource automatically refreshes the GridView which is the default behavior. I am...
10
by: loisk | last post by:
Hi, After our server 'wiped out' adversity by someone, we re-installed all the necessary mysql files. I am trying to separate my working database folder from the mysql program folder, and I want...
1
by: tj 6 | last post by:
a blank page displays when navigating to .aspx on the local machine we are using xp pro with IIS i've run c:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i followed by resvr 32...
0
by: KishorDhembare | last post by:
Hi Everybady I Want To Create New Database When My Application Starts First Time My Application Developed In Vb.net I Get The Error When I Run Command which I Have Command Is Like. Dim...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.