473,668 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help Inserting/deleting from a database

36 New Member
whats good

I am working on a php script. It takes in user input from a text field and then queries the database for it. If the input is found in the database then script performs a delete query to get that input out of the database. If it does not exist in the db then script inserts it. The problem I am having is concerns the variable that is used to store the users input from the text field. If I input something it inserts it into the database however when I try to insert something else right after the previously inserted input gets deleted in favor of the new input. This script is designed to only be able to delete what it has inserted. So data entered into the same db thru sql commands, other scripts etc. cant be touched. Can someone give me an idea on what I can do correct this bug?


Thanks

Heres some code pieces (the script is too big to post the whole thing):

Expand|Select|Wrap|Line Numbers
  1. //create text field
  2. echo("<input type=text name=opt_qty value='".$_SESSION['opt_qty_vals']."' onBlur='submit();'  class='qty_input'> ");
  3. //variable to store user input
  4. $user_input_strike = $_REQUEST['opt_qty'];
  5.  
  6.  
  7.  
  8. //Counts number of times input appears in db depending on specified details.
  9. $query_count = "SELECT COUNT(RAW_VOLS.STRIKE) FROM SMIRK_USR.RAW_VOLS RAW_VOLS WHERE (RAW_VOLS.STRIKE = $user_input_strike) AND (RAW_VOLS.ASOF_DATE=".$_SESSION['aod_val'].") AND (RAW_VOLS.SRC=".$_SESSION['src_val'].") AND (RAW_VOLS.SHARE_NAME=".$_SESSION['undl_val'].") AND (RAW_VOLS.CALL_PUT='".$_SESSION['opt_cp_vals']."') AND (RAW_VOLS.EXPIRE_DATE=".$_SESSION['opt_exd_vals'].")";
  10.  
  11. //code to retrieve actual result of the query aka the count
  12. $parsed1 = ociparse($db_conn, $query_count);
  13. $succ1 = ociexecute($parsed1);
  14. //store count in array
  15. $result = oci_fetch_array($parsed1);
  16. $count_result = $result[0];
  17.  
  18. //If count returns zero insert into DB.
  19. if ($count_result < 1)
  20. {
  21.     $insert_query = "insert into SMIRK_USR.RAW_VOLS (ASOF_DATE, SHARE_NAME, EXPIRE_DATE, CALL_PUT, STRIKE, OPEN_INT, SRC, PROCESSED) values($AOD_value, $UNDL_value, $expire_date_value, '$call_put_value',  $user_input_strike, $open_interest, $Source_value, '$processed_column')";
  22.     $parsed_insert = ociparse($db_conn, $insert_query);
  23.     $succ_insert = ociexecute($parsed_insert);
  24. }
  25.  
  26. //else if count is greater then zero and the input has been inserted by this script
  27. //delete the input.  
  28. elseif (($count_result > 0) && ($rset_results_element0 < 0))
  29. {
  30.     $delete_query = "DELETE FROM SMIRK_USR.RAW_VOLS WHERE ( (ASOF_DATE = $AOD_value) AND (SHARE_NAME = $UNDL_value) AND (EXPIRE_DATE = $expire_date_value) AND (CALL_PUT = '$call_put_value') AND (STRIKE = $user_input_strike) AND (OPEN_INT = $open_interest) AND (SRC = $Source_value) )";
  31.     $parsed_delete = ociparse($db_conn, $delete_query);
  32.     $succ_delete = ociexecute($parsed_delete);
  33. }
  34.  
  35. //else do nothing.  
  36. else
  37. {
  38.     //echo("Do nothing");
  39. }
  40.  
  41.  
.
Aug 16 '07 #1
11 1662
pbmods
5,821 Recognized Expert Expert
Heya, orfiyus.

Actually, we usually like it better when people don't post their entire scripts. It shows that:
  1. You actually tried to fix the problem yourself first before asking for help, and
  2. You're knowledgeable enough about your own code to know where the problem should be.

In regards to your problem, does your table have a primary key? Try SELECTing that when you first check to see if the entry exists, then use it to DELETE the existing row if necessary.
Aug 16 '07 #2
orfiyus
36 New Member
Itd probly help if I further explained what this script does. It queries the db and outputs a list of numbers. Then it comes out with the input field. When the user inputs a number that isnt currently in the database the page refreshes and the new number is added to the list. The problem I am having is that when I try to input another number that doesnt exist the page refreshes and the first input number is gone and replaced with the second input number. I think its a problem with either the variable I am using to store the user input or its a problem with my logic for the Inserting/deleting part. I tried using unset() to destroy the variable after its done being used but this didnt work. I dont know what the pk is because I dont have a db schema and I dont have direct access to the database anyway. I can only do things to the db through php. Any one else have any suggestions?

Thanks for reading though all of this.
Aug 17 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, orfiyus.

Try running a DESCRIBE query on the table to determine its structure:
Expand|Select|Wrap|Line Numbers
  1. $_res = mysql_query('DESCRIBE `SMIRK_USR`.`RAW_VOLS`);
  2. echo '<table>';
  3. while($row = mysql_fetch_row($_res))
  4. {
  5.     echo '<tr>';
  6.     foreach($row as $val)
  7.     {
  8.         echo "<td>$val</td>";
  9.     }
  10.     echo '</tr>';
  11. }
  12. echo '</table>';
  13.  
Aug 17 '07 #4
orfiyus
36 New Member
I am using a oracle database so I basically I converted it to the best of my ability. The result I get for the output says its null. Which is weird because I actually see numbers on the screen and i am able to work with my insert and delete code portions.

Here is wut I said for the describe
Expand|Select|Wrap|Line Numbers
  1. echo("<table>");
  2. //describe query
  3. $query_describe = "DESCRIBE SMIRK_USR.RAW_VOLS";
  4. //parse the sql code
  5. $Describe_parse = ociparse($db_conn, $query_describe);
  6. //execute it just incase
  7. $Describe_execute = ociexecute($Describe_parse);
  8. //store the results of the execute in array
  9. $describe_array = oci_fetch_array($Describe_parse);
  10.  
  11. echo("<br><br>");
  12. //var_dump it because its just easier 
  13. var_dump($Describe_array);
  14.  
  15. echo("</table>");
  16.  
  17.  
Aug 17 '07 #5
pbmods
5,821 Recognized Expert Expert
Heya, orfiyus.

Ah. Well then. I think in Oracle, the proper syntax is 'DESC `TableName`' instead of MySQL's 'DESCRIBE `TableName`'.
Aug 17 '07 #6
orfiyus
36 New Member
I changed it but I still get null outputted to the screen.
Aug 17 '07 #7
pbmods
5,821 Recognized Expert Expert
Heya, orfiyus.

I'm going to go ahead and move this thread to the Oracle forum, where our resident Experts will be better able to help you out.
Aug 17 '07 #8
orfiyus
36 New Member
Allright Thanks for trying man

Im gonna reevaluate the logic cuz I think the problem is in there
Aug 17 '07 #9
orfiyus
36 New Member
Mangaged to fix the insert part. But now the delete has the same problem as before.

Here a code sample maybe someone can see what is wrong with it. Maybe its logic or syntax cant figure it out. I tried using unset on the variable which stores the text field input but the whole script just went blank whenever I did that. Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1.  
  2. //else if the query for the count is 1 or greater and the
  3. //option number is less then 0
  4. //Delete the number out of the db with appropriate parameters.
  5. elseif (($count_result > 0) && ($rset_results_element0 < 0))
  6. {
  7.  
  8.         $open_interest = -1;
  9.         $delete_query = "DELETE FROM SMIRK_USR.RAW_VOLS WHERE ( (ASOF_DATE = $AOD_value) AND (SHARE_NAME = $UNDL_value) AND (EXPIRE_DATE = $expire_date_value) AND (CALL_PUT = '$call_put_value') AND (STRIKE = $user_input_strike) AND (OPEN_INT = $open_interest) AND (SRC = $Source_value) )";
  10.         $parsed_delete = ociparse($db_conn, $delete_query);
  11.         $succ_delete = ociexecute($parsed_delete);
  12.         var_dump($succ_delete);
  13.  
  14.  
  15.  
  16.  
  17.  
Aug 17 '07 #10

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

Similar topics

10
2622
by: Raghavendra Mahuli | last post by:
i need to store a lot of integers(say 10,000) in a datastructure. The constraints are: 1. It should be fast. 2. It should be orderded or sorted. 3.Insterting and deleting should be fast. 4. The no. of elements can change at runtime and hence it should be dynamic. Right now i am using SortedVector , but it is very slow. So, can u pls suggest a suitable Datastructure.
3
6898
by: Joachim Klassen | last post by:
Hi all, first apologies if this question looks the same as another one I recently posted - its a different thing but for the same szenario:-). We are having performance problems when inserting/deleting rows from a large table. My scenario: Table (lets call it FACT1) with 1000 million rows distributed on 12
1
4877
by: Arda Han | last post by:
Hi friends, I need a sample application for inserting,updating,deleting database rows. In this example I want learn creating MDI applications. Inserting,Deleting,Editing database rows on runtime. If you have sample application or if you have free time please send me a sample application.
2
6063
by: Clark Stevens | last post by:
Hi. This should be so easy, but I don't get it. Let say I have RichTextbox1 and I want to insert some text at the current insertion point, or at the beginning of selected text (if there is any). How is this done? Also, how do I delete the current selection? Thanks.
0
2605
by: rokuingh | last post by:
ok, so i've been working on this one for quite a while, and the code is very big so i'm just going to give the relevant parts. this is a program that builds polymers (chemical structures of repeated monomers) which are represented as doubly pointed noncomplete binary trees. There are three different types of monomers (hence the three different constructer calling functions) the first one is the "leaves" of the tree, the second adds length...
1
2581
by: yuchang | last post by:
Hi, Using the FormView control is very efficient. But I want to do some action,like showing a success message or redirect to another page, after inserting, updating and deleting. How do I get these message?
1
1879
by: Nemisis | last post by:
hi guys, Currently converting an old classic asp system to a OOP asp.net application. We are building the new application using a 3 tier arcitecture and i was wondering about the following. I have a parent class, that when inserted, inserts a few child classes into the database, based on other classes. In the old system, this is wrote as one big SQL script, with many inserts and updates because the system was not wrote as OOP.
0
1018
by: Kushwaha | last post by:
Hi, Any buddy help me to inserting multiple rows, Editing them, or deleting them in a any type of grid. I don't want to use any type of text box, combo box.
4
1906
memoman
by: memoman | last post by:
Can any body help me in that program ??? mail me if anybody could reach any -helpfull- thing Write a C++ program that namely insert, delete, and search in a fixed record length file (containing a person’s name and age). Associated with the record file will be a file that stores a binary search tree index that allows for a quick search through the index. The required operations will be provided using an input file that will be specified...
0
8462
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
8893
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
8586
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
8658
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
7401
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...
1
6209
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
5681
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
4380
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2026
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.