Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Insert, Delete, Update And Query Data Via DBX


can someone guide me how to connect to mysql using DBX and whats the syntax on inserting, delete, update and query data.




View Complete Forum Thread with Replies

Related Forum Messages:
OOP Page: Where To Put Update, Insert, Delete
I have a page that shows info from MySQL. It is for an online education
site. It uses different classes arranged in a hierarchy. Each lesson is
roughly laid out like this:

Lesson
|-Intro
|
|-Section
| |-Procedure
| |-text, video, images
|
|-Section
| |-Procedure
| |-text, video, images
|
|-Summary

I have all the classes working properly for displaying info from the
database. Now I am building the admin site.

Where should I put the update/insert/delete code? Would those go inside the
classes? Should I use the lesson object when doing the maintenance? Or,
should I just have a separate page that handles the database stuff and only
use the objects to display the data from the database?

View Replies !
Php/mysql Insert, Update, Delete All-in-one
I have a check box form in an admin area, that links various related tables into one.

These check box results are stored in an array, and then looped, there are in fact four groups of arrays, but the array length could become large (i.e. dozens - not hundreds)

The issue I have is that from the one form multiple things need to occur.

- If a box is checked and the record doesn't exist a new record needs to be inserted.
- If a box is checked and the record does exist, it should be ignored (as it already exists).
- If the box is unchecked and the record exists, it should be deleted.
- If the box is unchecked and the record doesn't exist it should be ignored (the record doesn't exists).

I'm looking for the logic and process (rather than being hand fed code ) Can this be done with 1 (or more likely 2) sql statements. Or do I have to loop thru the arrays, checking the existance and then applying a specific sql statement depending upon checked status and the records existance. Someone mentioned using IF() in the sql statement, but I am not familiar with that one.

View Replies !
Update, Delete And Insert Values
i am looking for a code example for how to update and insert values into an existing xml doc. i know how to read from it but i couldn't find any materials about how update, delete and insert values to xml. i want to use simplexml.

View Replies !
Simplify Insert-update-delete From Database
I'm looking for some functions or objects allowing to
select-insert-update-delete from any table in a mysql database without the
need to create a new query every time. Example:

selectdatas(array('field1','field2','fieldn'),arra y('table1','tablen'),array('left
join,idy','inner join, idx'))

then the function build the query, execute it and then return an object with
the query result.

I must build a database driven site that is 90% of the time spent on
building queries. If I may avoid build them manually it will help me a lot
and let me gain some days of programming.

View Replies !
Update Query - Retireving The Last Insert Id
I have to update my the filename field after I insert info into it for purpose of retireving the last insert id. I am using pdo as my db connection and everything else. The questionis that why will the code below not even execute. do i have to use bindParam or use exec or something along those lines PHP Code:

// Retrieve the ID from the last insert
            $new_id = $db->lastInsertId();
            $filetype = $photos_uploaded['type'][$counter];
            $extention = $known_photo_types[$filetype];
            $filename = $new_id.".".$extention;

            //mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );
            $select = $db->prepare("UPDATE gallery_photos SET photo_filename='".$filename."' WHERE photo_id='".$new_id."'");
            $select->execute();

View Replies !
Update And Insert Data Into The Db.
I need to figure out the best way to update and insert data into the db. I have 3 tables

room[id, room_num, building, numcomps]
software[id, title, version]
softroom[rid, sid, date]

The site is meant to print out software for a room, example: Code:

View Replies !
Present An Array Of Data, And The Corresponding Primary Key And Let The Code Work Out Whether To INSERT Or UPDATE It.
There's lots of DB abstraction layers out there, but a quick look around
them hasn't turned up anything which seems to met my requirements. Before I
go off and write one I thought I'd ask here if anyone knows of such a
beast...

I want some code where I present an array of data, and the corresponding
primary key and let the code work out whether to INSERT or UPDATE it, I
also want to be able to present the data from a QBF or QBE then be able to
step through the result set. However I don't want to have to configure the
DBMS structure - after all most of it is already in the DBMS (OK so not the
relationships in a MySQL db). It'd be really cool if I could throw SQL
directly at it *too*.

View Replies !
Update Query - Data Is Not Really Updating In Table.
MYSQL version is 4.0.2 When i am trying to update my table with this Mysql is saying query is OK. But the data is not really updating in table.

UPDATE personal set address_1='myaddress', address_2='address2',
city='Hyderabadnew', state='Andhra Pradesh', zip = ?', country='US', day_phone=?', eve_phone='', fax_phone='', business='' where uid=Ɖ'.

View Replies !
Update Table While Insert Data To Another Table
it seem like mine coding din work.
[php]<?

include("checkin.html");
$conn=mysql_connect('localhost','root','') or die ('Could not connect to server');
$today = date("Y.m.d");
mysql_select_db('hms', $conn);

$ok = mysql_query("INSERT INTO check_in(ID,room_no,datein)values ('$ID','$room','$today')", $conn);

if( $ok ){

$up = mysql_query("UPDATE studtable SET checked = 'checkin' where [ID] = '%ID');

if(mysql_affected_rows( $up ) == 1)
{
echo'Checked IN!'
}else { echo'No such student to check in' }}
else { echo'Check In FAILED, please check again'}?>[php]

View Replies !
Mysql Delete - $query = Mysql_query("DELETE
how would i do the following ?

$query = mysql_query("DELETE notes, datestamp, abs_value, ID FROM absence_mgt  WHERE datestamp='$date' AND ID='$vtc_login' ") or die(mysql_error());
im just getting "Unknown table 'notes' in MULTI DELETE" ?

View Replies !
Update Query - Way To Update All Records That Meet Only A Part Of Field
I know that if you use the following code..

UPDATE
table
SET
field = ""
WHERE
field1 = ""

than it will change `field` in all records that meet the criteria of field1. What I need to know is there a way to update all records that meet only a part of field1

ie...

UPDATE
table
SET
field = "yummy"
WHERE
field1 = "apples|oranges"

if field one contains apples|oranges|grapes

it would still pick up that record.

View Replies !
Update Without Delete
If i get a user to fill in a form that will update acurrent record, the user may leave a field blank, if field is not manditory, when you do an update, the blank field will over write the current data if there was any, is there a way round this?

View Replies !
SQL Insert And Delete?
Anyone know if there's a way to call a query but remove whatever you grabbed from the database, or would I have to do a query to retrieve what i needed, then follow it up with a delete on the same query results?

View Replies !
INSERT And DELETE
I have a dynamic website that prints the info in the database out with checkboxes next to it. When a user checks the boxes and press the submit button, the record should be deleted from the database and then they should be stored in another database that assigns a different primary key ( not in that order). Also I would like for the user to be redirected back to the same page and for the records that were deleted, not to show up.

View Replies !
Insert Into Table - $query = "INSERT INTO Tbl
I have a small problem which I've been working on for a while. PHP Code:

$query = "INSERT INTO tbl(username,ip,link) VALUES("Brin' . $result['id'] . '","$REMOTE_ADDR","http://www.domain.com/sub/start.php?username=Brin"' . $result['id'] . ' )";
mysql_query($query);

Any ideas?

View Replies !
Insert Into New Table And Delete From Old
I've got 2 tables of users: 'pending' and 'approved'.

The first table (pending) is a 'holding' table for unapproved users and when the user is approved I can click on a checkbox by their name and copy them over to the approved users table (INSERT INTO approved...)

This all works fine but I'd also like to delete them from the 'pending' table at the same time. How would I do this? Something like (INSERT INTO approved, DELETE FROM pending)?

I'd do a bit of trial and error but since it's on a live site, I don't want to muck it up and not be able to fix it! Code:

View Replies !
Database Update/edit And Delete
i have spent the last few days trying to create a simple script to add/edit and delete entries in a mysql database with php. i have 1 database with 40 tables, each table has 3 fields (id, header and body)

i created an input page with input fields for header and body. the table to store the information in is selected from a drop down menu. all this works fine.

for some reason i cannot get the edit and delete page top work at all. would someone mind taking a look at the code and let me know what i am doing wrong? Code:

View Replies !
Basic Delete/update Script
i am trying to do is delete a user off the database, via the admin menu. when the user is deleted the database is updated: this also be done using a HTML form, where when the admin type in a name and the user is located, the form then ask's if the admin would like to delete the user.

View Replies !
Execute An Update Query Based On The Results Of A Select Query
I'm trying to execute an update query based on the results of a select query... This doesn't work - any ideas? This is the code I'm trying to get to run (it updates all products which are set to arrive by a certain date if that date has arrived or passed - and there are products that should and should not be updated in the db this is being tested with...): Code:

View Replies !
How To Do Insert,delete,edit Using Ajax
i want to add,delete,edit using ajax.

View Replies !
Update Query - How Do You Update A Value In The Database In A Certain Row?
I am trying to make a little thing that allows you to edit something that you have previously submitted to be in the database. How do you update a value in the database in a certain row?  Right now when I run my script, it submits the updated info into into every row in the database.  How do I just make it so it inserts it into row x? (x being some random number that I will have passed to it).

View Replies !
Insert/update
I came accross a little piece of code today that I thought was quite
cute, but I'm not sure if it's any better than my usual method. The
code ultimately needs to see if a unique identifier exists in a
database, then either insert or update accordingly.

The way I've always done it is:

SELECT * FROM blah where.....

if (there's a row) then
UPDATE.....
else
INSERT

but the nifty bit of code did it like this.

UPDATE....
if (mysql_affected_rows == 0) then
INSERT

View Replies !
INSERT OR UPDATE?
I am writing an app in PHP that uses a PostGres database.
One thing i have noticed is that what should/could be a single line of
SQL code takes about 6 lines of PHP. This seem wasteful and redundant
to me.

Here is a sample of what I'm talking about ($db is a PDO already
defined and created).

$query[1] = "UPDATE my.table, SET somefield = '$someval' WHERE
somecondition";
$query[2] = "INSERT INTO my.table (somefield) VALUES ('$someval')";
if(!$db->query($query[1])){
$db->query($query[2]);
}

What I'm curious to know is if there is some way to simplify this,
either buy some PHP builtin or extension, or possibly something in SQL
I am missing. It seems to me that "UPDATE OR INSERT", should be valid,
but I can't seem to find anything relevant at all about it.

Anyways I hope you don't mind, but I'm crossposting this to
pgsql.general and comp.lang.php to see if I can get some information on
the subject.

View Replies !
Can Insert But Not Update?
I'm having a problem getting the value to update for the total amount of avatars a person has when they unlock a new one. I've been sitting here looking at the code for the last hour and for the life of me I can't figure out what I'm doing wrong. Code:

View Replies !
INSERT Vs UPDATE
There:

-On page 1 of a registration form I have an INSERT quiery to input the data in the DB.
-On page 2 I have an UPDATE for additional fields
-On page 3 I also have an UPDATE statement for remaining fields

On page 4 it's the confirm page to make sure the data is right for the user. It's basically a SELECT quiery if the user were to go back to page 1 and make some changes, would that basically create an issue since there is an "INSERT" quiery and not an "UPDATE" quiery? Because basically, once the user clicks on "next" to go to page 2, the user ID is already created and for those fields, the INSERT quiery inputs the data.

View Replies !
Insert And Then Update
I have the following code but it doesn't work.

<?php
$query = "INSERT INTO transportationcharges (TransportationUnit)
VALUES ('$TransportationUnit')";
$updateSQL = $conn->GetUpdateSQL($query, $TransportationUnit);
$conn->Execute($updateSQL);

?>

View Replies !
Insert Into / Update
I have a page with several text boxes and one text area. For some reason when I submit the information the first time using an insert into statement everything works fine. If I try to edit the info and submit it again with an update statement I get a syntax error. Not really sure what the problem is. Code:

View Replies !
Insert And Update
I have to pass info from table A to table B, I need for each record I passed (insert) into table b, to update the relevant record in table A. Is there any way to do this only with sql i.e. mybee insert and update in the same sentence. imaginary example:

insert into table_b (field_a,field_b)
select field_a, (update table_a
set field_b="processed"
where field_a=out.field_a)
from table_a out,

View Replies !
Insert Or Update
When inserting or updating, is there a join for these functions or are joins just used for extracting data, and multiple insert or update code used for putting selected data into their respective tables.

View Replies !
Insert/update
i'm trying to do a many to many insert/update and cannot find any information on how this is done in php? I have done this in asp before but am not familiar enough with php to get a working version. here is the asp code that i have used in the past for an insert. Code:

<%
set customersRS = Server.CreateObject("ADODB.Recordset")
customersRS.ActiveConnection = MM_connLMYC_STRING
customersRS.Source = "SELECT top 1 * FROM customerRegister order by customerID desc"
customersRS.CursorType = 0
customersRS.CursorLocation = 2
customersRS.LockType = 3
customersRS.Open()
customersRS_numRows = 0
%>
<%
If Request("selected") Then
customersRS.addnew
customersRS("Name")=Request("customerName")....

View Replies !
PHP Update Query Mysql: Query Succussful?
I can't seem to successfully test an update query. Below is a piece of code that updates a statistics table. If row today doesn;t exist, a new day must be created. But this doesn't work...

thank you for your reply.

$today= date("Y-m-d");

$qq="update totals_r set hits_r=(hits_r+1), lang_$lang=(lang_$lang+1), cat_$cat=(cat_$cat+1), rating_$rating=(rating_$rating+1), bussite_$bussite=(bussite_$bussite+1) where date='$today'";

$result_6 = mysql_query ("$qq");

if (!$result_6){ /// IF !ROW_TODAY ==> CREATE NEW DAY

$qq_2="insert into totals_r (hits_r, lang_$lang, cat_$cat, rating_$rating, bussite_$bussite, date) values(&#391;',&#391;',&#391;',&#391;',&#391;','$today')";

$result_6_2 = mysql_query ("$qq_2");

if (!$result_6_2){
$err_msg_sql_6= mysql_error();
$err_loc_6="$PHP_SELF"." // Query6: update totals_r";
}
}

View Replies !
Update Query - Cant Execute Query Error.
I am having a problem with the update script. I making a group update and i keep on getting "cant execute query" error. I am wondering if its my SQL statement. PHP Code:

View Replies !
Multi Table Insert Delete Select Function Needed.
I am going nuts here and I know with all the functions out there, there must be an easier way to do this. Maybe someone can point me to the right tutorial or even show me how to do this.

I have a $main_id and many $sub_id tables and like to “SELECT to view” INSERT and DELETE those. UPDATE must not be but would be nice.
Here is how it looks:

View Replies !
Insert On Duplicate Key Update
I have the following code: PHP Code:

View Replies !
Should I Use INSERT? UPDATE? REPLACE?
I have a table that looks like this: MyTable (id,date,field1,field2)

At the top of my script I insert a date into my table and initialize $top_id with my_insert_id. Then down towards the end I want to write to field1 and field2 their values, and I am using this: PHP Code:

View Replies !
Multiple Insert Or Update
I have this form and i want to do a multiple insert using checkboxes. The values are fetched from a tbl1 and will be inserted into another table tbl2. I want to get only those fields where checkbox next to it is selected Code:

View Replies !
SELECT, INSERT, UPDATE
On this project I have got 2 items a mobile and simcard, these are in one table as two records and have a unique equid each. the simcard is also in another table called siminfo and has a parentid (which is the same equid as the mobile) to create the link. In the equipment table there is also userid

I already have code that transfers these items individually, but i want to be able to transfer them both when i transfer the sim card. I currently have the followin but its not working for some reason. the variable $equid does work i have tested it. This code is not picking up the simparentid though Code:

View Replies !
Insert To One Table, Update To Another
I'm trying to do two queries at once utilizing data from a form. I'm creating a new row in one table, and I need to reflect the ID number and other supplementary data to an existing record in another table. Is there a way to string two queries together so they execute at the same time? Here's what I've been trying so far: Code:

View Replies !
Synchronizing Via INSERT/UPDATE
I've been googling for an answer but am not even sure how to phrase my search on this question. Here's the situation: I have a real estate database with 2 tables. The first is a listing of all houses for sale in the market, updated daily on an automatic basis (via cron.) .

The other is a listing of just the homes available through a certain agency. I am trying to do an update of the second database that does 2 things, A. Inserts new homes from Table1 into Table2 and B. Updates the existing information from Table2 with current information from Table1 (price changes, etc.) . I have accomplished part A using the following code: PHP Code:

$query = "INSERT IGNORE INTO table2 SELECT * FROM table1 WHERE table1.category='XXXXX'";

I'm having trouble coming up with proper code for the second part. There is additional information added to the rows in Table2 so I know I need to use update to change just the new information but I'm not certain how to use the right variables. Ok, for my actual question without the background, here it is: How do I perform an UPDATE of multiple records, matching a certain criteria, but not all records?

View Replies !
Update Based On Last Insert ID
Im trying to update a table based on the last id that was created in part 1 of a form. Code:

View Replies !
UPDATE And INSERT In Mysql
Im trying to do this: if a column exists then update it, if it does not exist insert it. This is my code (and its not working):

if(!($q = mysql_query($sql_update))){
   mysql_query($sql_insert);

not working... Noticed that mysql_query($sql_update) returns 1 even if the column does not exist... should it not return false in that case?

View Replies !
Update If An Insert Has Been Made
I am strugglin to create a conditional update. Code:

View Replies !
Insert Or Update Dilemna
I have a large database that is updated daily. I am trying to pass a subset of data from one table to another within the database. It's a real estate site and I am trying to create a smaller table to work with houses from a certain office from within all the data. PHP Code:

$query = "INSERT INTO table2 SELECT * FROM table1 WHERE officeid = 'xxx'";

But what I want to do is set it so that my script evaluates each record, checks whether it exists in table2, if it does, it updates it, if it doesn't, it inserts it. Is there a way to do this with if ... else or am I just thinking wishfully. I would be delighted to read up on this if someone could help me figure out the right Google query, I've tried but to no avail.

View Replies !
Records For Update Or Insert
I am trying to add a signup for an e-Newsletter and I want to check to see if they already signed up to prevent duplicates. I found this link talking about it and I am using bpat1434's technique and it tells me the record was updated, when it wasn't even inserted into the database yet? I used a unique email address to test the insert and it passes PHP Code:

if(!$result)

and continues to the update.

View Replies !
Modifying Insert To Update
Here is my code for the insert at the moment: PHP Code:

<?php
include("connect.php");
session_start();
require_once('common_functions.php');
$_SESSION['form1_data'] = $_POST;

// build main query from form 1
    $sql = "INSERT INTO quality_info SET quality_id =  NULL ";
    foreach ($_SESSION['form1_data'] as $col =>$val ){
        if($col <> 'submit'){
        $sql .=", $col = '$val' ";
        }
    }
..........

View Replies !
MySQL: Insert...select - Update?
I was reading about insert select
http://dev.mysql.com/doc/mysql/en/insert-select.html

Thought this may be a better way to perform a query I'm doing. The differenc is that I need td select from one field, and then update another field in the same record (it is a backup/undo field).

Is there a way to do this in one query? It's a large chunk of data (longtext) so I thought this would be faster than the alternative...

View Replies !
Dynamic Update/insert Statement?
I'm hoping to build a dynamic sql statement for inserts and updates based on FORM values. I've done this in ASP but not sure about PHP syntax. Right now I just output the form entry results, but here's what I'm thinking for an update: PHP Code:

View Replies !
When To Update Or Insert Based On Checkboxes
I'm building a script that involves a step-by-step registration process. It is step-by-step because a user can go back and forth and edit everything he/she has entered. One of these steps (Step 2) contains some checkboxes that pertain to sections (called extras) that users may want to add to their profiles (such as Hobbies, Awards, Favorite Movies etc.).

After several steps the user is then taken to pages for them to fill up according to the extras he/she had checked earlier. My main concern lies wherein the user chooses to go back to that page and checks/unchecks some of the checkboxes (all of which are called 'extras'). There are two buttons on that page, 'Back' and 'Continue'. If Back is pressed, we are taken to Step 1, and if Continue is pressed, we go to Step 3.

Currently, when the Continue button is pressed, the script deletes everything based on some conditions and inserts whatever is checked into a Mysql table, which I think is not a very good way to do it. I'm trying to figure out a way so that the script recognizes 1. what was checked just recently, 2. what was checked and is still checked and 3.

what was checked and now unchecked. This way, I can instruct the script to INSERT only the newly checked ones, UPDATE the still checked ones and DELETE the unchecked ones.

View Replies !
Combine INSERT And UPDATE MySQL?
Is there a way to combine INSERT and UPDATE MySQL? I want to say "INSERT the data if the username doens't exist, or update the existing data if the username already exists"

INSERT INTO scores VALUES ('".$uname."',
'".$score."')

[if username doens't exist already]

combined with

UPDATE scores SET score='".$score."' WHERE uname='".$uname."'

View Replies !
INSERT, UPDATE Into A Memory Table?
Just created a MySQL table in the memory (memory storage engine) but im having problems adding information to it...

First of all it is complaining every time i try to auto increment the primery key.... then it is not adding anything when I use a standard insert into the table (it has no auto inc. now....).

View Replies !
Can Not Update A Field Where The It's Id Equals An Id Recieved From The Last Insert.
I have searched all of php.net and googled my problem but could not find an example or any help at all. the problem that I am having is that I can not update a field where the it's id equals an id recieved from the last insert. I don't know why it is not working. It seems like php just skips over the statement since the error checking does not catch any errors.

View Replies !
Delete Query
Here’s what I’m trying to do:

- Output the last 60 results in my db - works
- Delete a record – does not work

Can anyone see why my delete query won’t work?

It seems to have two problems:

1)   It does not delete a record
2)   The header re-direct says can’t modify header information Code:

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved