473,703 Members | 2,351 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Blank Row added to database when existing row found

155 New Member
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_processin g.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.ph p and the image_process.p hp:
[PHP]// image_upload.ph p

include("includ es/dbconnect.php") ;
$query = "SELECT * FROM $cat";
$result = mysql_query($qu ery) 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><b r>
";

} else {

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

while($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {

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

echo "

<option value='$cat_nam e'>$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><b r><br>
";

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

[PHP]// image_process.p hp

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

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


include("includ es/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($qu ery) or die('Error, query failed: ' . mysql_error());

if (mysql_num_rows ($result) == 1)

{

// Make the query

$cat_name = mysql_real_esca pe_string($_POS T['cat_name']);
$title = mysql_real_esca pe_string($_POS T['title']);
$desc = mysql_real_esca pe_string($_POS T['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($qu ery);

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

}

else

{

$cat_name = mysql_real_esca pe_string($_POS T['cat_name']);
$cat_desc = mysql_real_esca pe_string($_POS T['cat_desc']);


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

$cat_name = mysql_real_esca pe_string($_POS T['cat_name']);
$title = mysql_real_esca pe_string($_POS T['title']);
$desc = mysql_real_esca pe_string($_POS T['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($qu ery);

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


mysql_close();
}
[/PHP]
Jun 18 '07 #1
2 2056
pbmods
5,821 Recognized Expert Expert
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 New Member
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
2622
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 "document.getElementById('tabid').style.display='none';" in the onclick event and setting the encapsulating table's ID to 'tabid'. I was wondering if this or some other similar approach that could possibly be planted globally in my pages in the onsubmit validation
1
1508
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? I have not created a setup before, so great if I can get details. Magnus
3
1799
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 extern desktop I can see the database and do everything. Now I want to create a login with visual web developer 2005 express. But when I try to login with sql server authentication I don't see any database. When I try windows authentication, I have...
0
1337
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 from existing Access database? Also let me know how to deploy it once we have convered the .mdb to .adp file? thanks in advance, Senthil
12
3500
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 modifications the entry which is being displayed is then stored in the database causing duplicates. My hope is to only allow additions and or modifications if they select the proper command button. If they just close the form I would like nothing stored...
3
2821
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 trying to disable automatic query feature in ObjectDataSource, such that it query the database only when the user click on Search button. Is there anyway to prevent ObjectDataSource query the database when the page
10
1579
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 mysql to point my working database when it is invoked instead of the installed program folder where all lib, include, bin, etc are living. Can anybody help me on this issue? Thanks!
1
4058
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 c:\windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll then ran iisreset regsvr replyed with the message: --------------------------- RegSvr32 --------------------------- c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll...
0
1629
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 file As FileInfo = New FileInfo(Path.GetFullPath("TextFile1.txt")) Dim backupScript As String = file.OpenText.ReadToEnd() Dim strCommand As String = backupScript
0
8669
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9251
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4432
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2450
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2069
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.