473,662 Members | 2,413 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 2049
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
2619
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
1506
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
1797
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
1334
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
3499
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
2818
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
1576
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
4052
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
1626
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
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8856
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...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
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
8633
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...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.