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




How Do I Update Mysql


i have a mysql database table called email2 mysql> describe email2;

+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| email | varchar(20) | | | | |
+-------+-------------+------+-----+---------+----------------+

I want to update the database with a form. For example, i could edit the contents of the database using a form and save it to the database again. Is there way to do that? Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Using UPDATE In MySQL
I have an input form that passes data when submitted to a second form
to let the user know what they have just entered into the db.

My question comes with using 'update'. I'd like to query the database
by equipment number (equipno is unique) and query all fields from that
row, populating an original form 'look alike' whereby the user can add
detail to the original records as the db builds. I'm using 'date'
twice because I'd like to have the original date the record was added
plus the most recent update date.

Form 1 below, is original user input:

MySQL UPDATE
mysql_query("UPDATE news SET newstopic = '$newstopic', news = '$news', newswriter = '$newswriter' WHERE nID = '$nID'");

why isn't this working?

MYSQL UPDATE
i'm making a forum and am having a little trouble with updating a post.
I have an edit button, it gets the post and puts it into a text box, but once finished editing, it will not update the post! I made it echo the message before updating and its the right thing and it doesn't give any errors.

$postid=$_POST['postid'];
$post=$_POST['post'];
mysql_query("UPDATE posts SET post = '$post' WHERE postid = '$postid'") or die("Could not edit post.");

Is there anything wrong with the above is it something else in the code?

Best Way To Update A Mysql Record
I have a small app that a user can select an entry to be considered as "cancelled". This will change an entry in a mysql database.

Is there someway of making a button that as soon as its clicked, sends the appropriate update info to the database and reloads the page?

UPDATE Mysql TABLES With PHP
Ok, I know I can update my tables using phpmyadmin, but it becomes very difficult when I have a table with hundreds of rows all with different information. Now, what I want to do is be able to change the information that is in the table already. Meaning...if I have customer A, B and C all with different attributes, say one of them calls me and wants to change his shipping address. I know I could go to phpmyadmin, search this customer and edit his info. But it becomes really hard when I have 200 customers who change their info, not only their addresses but Contact info, etc.

Now what I am trying to do now is create a PHP script that will help with to accomplish that.

PHP MYSQL Update Issue
I normally do not ask for much help on php or mysql but this one has me stumped as to the actual cause of the issue.

I have a script that updates about 3000 records hourly well my main issue is this. The update starts and about 400 records into the update script, it stops . Sometimes it may go all the way and sometimes it does not.
Nothing changes in the scripting from one event to the next. As in sructured data wise.Is there a limit to the mysql_query update feature to PHP or MYSQL that wold cause this.

This is an example of my issue.

$tonytiger = mysql_query("select * from world");
while($goathurder = mysql_fetch_arrary($tonytiger))
{
$rickeet = mysql_query("select * from yukon where timeline='$goathurder[hunted]'");
$poco = mysql_fetch_array($rickeet);

$place = $goathurder[place] + $poco[place];
$yoogie = mysql_query("update location set place='$place' where hunted='$goathurder[hunted]'");
}

Now this query has been known to complete many times with 3000 records but its the time it does not that is my question.

PHP: MySQL UPDATE Query
I need to have a page where the user can update his info and/or delete his record. I haven't tested the DELETE query yet.

When I open the page it shows all the info stored in the database. When I change something and hit the update button I get the message that the record was successfully updated, but nothing really hapens.

If you want to see what's happening go to URL , click on the 'directory' link
The user ID is 'scooby', and password 'dooby'. If it does not work, try the following combination: user ID: 'sunny', password: 'trout' . Then click on the 'edit profile' link and try to change something and see what happens. I am attaching a php file of the 'edit profile' page, the one I am having trouble with so you can see the entire code.

Php Preview Before Update Mysql
I have an admin page with a form to submit outlet data in to the mysql database. all I want to do is have 3 buttons for the form 1 putting the outlet on hold which is ok the other update with is also ok, the one I am stuck on is Preview,

I need the the admin to be able to check over what has been updated but cannot work out how to display the the data witout updating the databse ...

UPDATE A Record In MYSQL DB With PHP
What is the best way to update a record in a MYSQL DB using a FORM and PHP
?
Where ID = $ID !

Any examples or URLS ?

Mysql UPDATE Syntax
what is wrong with this code? It generates no erros, but doesn't work either:

$query = "UPDATE $usertable SET dl=dl+1 WHERE id=$id";
$result = MYSQL_QUERY($query);

There is a unique id number for every row in my table. There is also a column called "dl" which holds the number of downloads certain files have gotten. I'm trying this code on my download page so that every time someone downloads a file (identified by its id number) the "dl" column for that file is incremented.

MySQL UPDATE Command
I use this to add a new row of data to a table:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$query = "insert into $parent values('$id','$author','$website','$fname','$width','$place','$title')";
$result = mysql_query($query) or die("crap");[/code]

The $id is an auto incrementing field so every row can be referenced with a unique number. Suppose I have the $id of the row I want to modify, and I have new values for $author, $website, $fname, $width, $place, and $title. What code do I use to modify the row (keeping the same $id)?

Mysql Update And Checkboxes
I'm building a music site with a mysql backend. It has a many to many
relational database.
I use this to match music genres with certain artists, to maintain the
possibility to add multiple genres to a singe artist.

Now i've searched google, but can't find a solution on how to update
rows with checkboxes.
If an artist gets his genre updated as follows:
from

- [_] classic
- [X] rock
- [_] ballad
- [X] 80's
- [_] 90's
- etc.

to

- [_] classic
- [_] rock
- [_] ballad
- [_] 80's
- [X] 90's
etc.

Update Several Rows In MYSQL
I have this table which displays multiple rows of information I think the max being about 100: PHP Code:

PHP/MySQL UPDATE Problem
//GET INSERTED CHUNK ID
$getid = mysql_query("SELECT id FROM chunks WHERE chunk = '$chunk'");
$idrow = mysql_fetch_array($getid, MYSQL_ASSOC);
$chunkid = $idrow["id"].",";

$eachtag = explode(",", $tags);
foreach($eachtag as $key=>$value) {
For some reason, this code:

$updated = $row["chunks"] . $chunkid;
mysql_query("UPDATE tagtochunk SET chunks = '$updated' WHERE tag =
'$value'");

only updates the field with $chunkid, leaving out row["chunks"]. I'm
guessing it may have something to do with scope within control
structures.... I'm at a loss.

$query = "SELECT chunks FROM tagtochunk WHERE tag = '$value'";
$result = mysql_query($query);

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

//CREATE NEW TAG ENTRY
mysql_query("INSERT INTO tagtochunk (tag, chunks) VALUES ('$value',
'$chunkid')");

} else {

//UPDATE CUR TAG WITH NEW CHUNKID
$updated = $row["chunks"].$chunkid;
mysql_query("UPDATE tagtochunk SET chunks = '$updated' WHERE tag =
'$value'");

}

}

mysql_close($con);
?>

Php, Mysql And Update Table
I have one mysql table and I need to update it by form. But what is the best way.
I think First I need atleast following php-files:

list.php --> list all data rows from my table included link to select certain row and
update.php --> ...when selected you will get form view where you can update field
updated.php --> update your database table.

MySQL 'update' Not Working..
I'm setting up a website on which you have to pay for membership. I allow the user to register with an 'elec' field in the database as '0'. The 'elec' field is '0' when they haven't paid and '1' when they have.

I've tested it and the login/register scripts work fine but i cant get it to change 'elec' to '1'. I use a separate script to buy elec, as shown below. Code:

Mysql Update Problem
I get the following error when trying to change image file associated with row.  The image is stored on the server and the link in mysql.

Error:
Error, query failed : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(name, size, type, path) WHERE id='7'VALUES ('album1.jpg', '38916', 'image/pjpeg' at line 1

code:

Update Mysql With $_SESSION
I would like to update the mysql database using a $_SESSION array. The array looks like this when using print_r

[VA001] => 8 [VA002] => 26 etc.........

What i would like the SQL to do is update table column = value of $_SESSION array where column = key of $_SESSION array.

Could someone show me how to write this and is there anythong that needs to be done to the array such as stripslashs or trim or anything like that.

MYSQL Entries Won't Update
I am trying to update some entries in a mysql database that will append the filename to the end of a thumbnail directory entry. So for example /images/thumb/ would become /images/thumb/12345.jpg.

I am stumped because the below code gives no php or mysql errors but the entries are not updated in the mysql db! Code:

Addslashes With Mysql Update
I have form output that needs to go into a database. If the form output contains ' and I use addslashes on it then I am getting an error because for some reason it is only adding a slash to the back slash so:

' becomes ' - correct and will work
' becomes ' - incorrect and errors

Am I doing something wrong or missing something here?

Multi Entries Update To Mysql
Could someone help me to figure out how to upgrade multi entries to Mysql by using PHP?

Say, I have a table on Mysql

id Priority
1 Okay
2 wait
3 later
4 asap
5 hold

Now I want to upgrade that table to:

id priority
1 hold
2 asap
3 okay
4 wait
5 later

Is it possible to upgrade multi entries with one submitt button? If yes, could you tell me how it could be done.

I knew I could do it by each entry (submitt button).

Update priority set priority='$priority' where id = '$id'

Mysql Update Problem, Not The Usual
I have a particular problem in which a mysql database is now updating.

I am creating a "cookieless and sessionless" shopping cart using mysql and php. Everything is working fine except for my update shopping cart section. Here is the scenario...

I have a shopping cart named scart.php that contains two links: one to a delete page that redirects back to scart.php and one to a delete page that cotains a form that is being populated by a database entry(the same record that is on scart.php). This form, when submitted, sends all of its contents to update2.php, where the update sql resides, as well as a redirect back to scart.php.

All is working well and free of errors, but the record is not updated when the redirect occurs. I have tried this without the redirect and still get nothing. Here is the code for update2.php:

<?
$db_name = "xxx";
$table_name = "xxx";
$connection = mysql_connect ("xxx.xxx.xxx.xxx", "xxxxxx", "xxxxxx")
or die("Couldn't connect.");
$db = mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$query = ("UPDATE $table_name WHERE id='$id'
SET rfname = '$rfname', rlname = '$rlname', raddress = '$raddress', rcity = '$rcity', rstate = '$rstate', rcountry = '$rcountry', rzip = '$rzip', greeting = '$greeting'");

mysql_query($query);
mysql_close($connection);
header("Location:scart.php")
?>

MySQL Index And UPDATE Table
"When you update a table with an index, you have to update the index as well"
What does this mean? For example, my table has four columns:

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...

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.

Using PHP For Mysql Command (update Partial)
I have a table with a structure column of "product_attributes" that I want to do a mass update to with certain criteria. Basically if within product_attributes there are some rows with the following: Code:

color_blue,color_pink,color_purple,color_black
color_blue,color_pink,color_purple,color_white
color_green,color_pink,color_purple,color_black
color_blue,color_pink,color_purple,color_yellow

Now I want to change all instances of color_purple to color_violet. So that it should now read: Code:

color_blue,color_pink,color_violet,color_black
color_blue,color_pink,color_violet,color_white
color_green,color_pink,color_violet,color_black
color_blue,color_pink,color_violet,color_yellow

How would I do this without disturbing any of the other information within that table? Only the one word in all rows with "color_purple" in it?

Can't Update Mysql Table Via Php Form
I have a form that updates an item pulled from a database, but after the form is posted, it does not update the mysql database with the new info, here's what I am using: Code:

Update MySQL Tables / Web Enviroment
I have some PHP and MySQL knowledge, I am trying to update some mysql tables but within a web enviroment , I know how to update them through phpMyAdmin.

Mysql Update/replace Syntax
To keep track of how many fruits my visitors buy, I use a mySQL database
(2 columns: "fruit" and "quantity")....so can we make these following
mySQL queries work somehow?

(visitor buys 5 apples):
replace into fruit_database set fruit = 'apple' , quantity = quantity +
5;

(visitor buys 7 apples):
replace into fruit_database set fruit = 'apple' , quantity = quantity +
7;

(visitor buys 1 grape):
replace into fruit_database set fruit = 'grape' , quantity = quantity +

How To Update MYSQL From Multi Row Form
I'm trying to update rows in MySQL using a dynamically generated form. PHP Code:

Update 2 MySQL Tables In One Form
I have a form with two fields in it. Each field updates its own table. I would like for the user to be able to enter data in either fields and the form update the appropriate tables. If one of the fields is empty then it doesn't update the table.

mcat - Updates mcatTable.mcatname
mtype - Updates mtypeTable.mtypename
PHP Code:

HTML Table Update Row PHP/MySQL
I have a dynamic HTML page with 4 columns of data, retrieved with PHP
from a MySQL database.
At the end of every row I have an UPDATE submit button, which activates
a php update script to update the database. I now encounter the problem
that in the update script I cannot trace back for which row the UPDATE
buttom was pressed.

I first had defined the UPDATE button as : <input name="update"
value="UPDATE" type="submit">. That doesn't work ...
If I change the definition to <input name="update" value=<? echo
"UPDATE".$nt['id']; ?type="submit">, then I can get the id number in
the update script, but the display is not that good, because you see
UPDATE1, UPDATE7,UPDATE4 and so on ...
So I need something, so I can find back in the update script for which
row the update button was pressed. Each row has his unique id (which is
not shown in the table)

Forgot How To Do A Mass Update In MySQL
I can't remember if I did this last time in phpMyAdmin or if I did it some
other way... I have 2 new fields in a database that I need to fill with
values. One field needs to have the default "0" updated to "1" in every
field. The other one I want to insert a randomly generated password. The
password function is in a form for all subsequent record insertions, but I
want to populate the existing 1100 records with one also. What's the
easiest way to fill these 2 fields without wiping out my data?

Onclck Update Mysql Field?
i have a script (below) when a user clicks on a link i want it to update a field in a database +1 so that i can see how many times it is clicked. but i cant get it to update the field what am i doing wrong? Code:

Using Mysql UPDATE Inside For Loop
I have an array that stores pieces of information that I want to update to a database. I decided to use the for loop to retrieve the peices of information and one by one store them into the database. The last peice of the array is stored repeatedly for the other values....

I have echoed the process the loop takes and i cannot figure out the problem... Here is a simplified version of my code:

Automation - User Management - Update MySQL
What I'm trying to do is design a user management page that will allow me to update the status of a user's account with the click of 1 or 2 buttons.

Preferrably the design is this, My script queries the database and returns results on users that are not activated. That part is done, what I would like to do is on the end of each row (user) have a radio button each with a value of 1, 2, or 3, which are my account status flags in my database.

What I'm having a problem with is how to get the update button to only update that row without having to send a query for the entire table, or worse yet, only updating the last returned value of my while loop.

What i'm looking for is some pointers on the right direction to look on how to do this. Specifically, I need to find out how to get the data that's printed in each table row into a variable so that I can query the item for that row and update that user accordingly.

Fwrite Vs Mysql (update Data), Which One Is Faster ?
I use this code to make a simple log file, counting how many visitors I have each day:
PHP Code:

Php - Update Mysql Database - Syntax Error
When i try and update the database table i get this error.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc='My name is ***** and I'm a 17-yr. old junior. I play electric ba' at line 1

what i am doing is having the user fill in a large text area and saving it to a database. So i think the problem could possibly be that they are using ' and " in textarea to mess it up? Code:

Update MySQL Table Row Upon Leaving Site
How would I update a mysql table row when a user closes their window when they're logged in to my site?  I want it to update a table row called logged_in when they close the window without logging out of the session.  Is this possible?

Php Mysql Update - Echo Not Updated List
I have 2 tables, "Inventory" contains a few details about the shop items, "Shop" contains all the information.  I'm doing it this way because the information is coming from a csv on another server.

So I'm looking for a way to update item quantities between the tables, then echo/print any records that don't exist yet to be updated.

Then I can manually add any new records to my shop database and it will update as usual next time. Anyway, here's what I have so far, but it doesn't display my extra records. Code:

How To Update Mysql Table Without Changing Existing Data
how to update mysql table without changing existing data.

PHP/MySQL Fulltext Search Relevancy Formula Update
The table already has a fulltext index and from there I can use the
MySQL fulltext search query to get results as well as the relevancy
score.

The problem I have is that MySQL has a default setting whereby the
minimum amount of characters is 4 for a search. Being that we're
government and full of TLA (three-letter acronyms), that is not
practical, and furthermore, the app I'm building must be fully
portable, so having MySQL tweaked everywhere this app goes is a
useless exercise.

Hence, for 3-letter words I have to fudge together a relevancy score
to match that of larger and more commonly accepted words.

Here is the function I created, calculate_relevancy(), with notes I
got from a posting by MySQL AB's Sergei Golubchik on the exact formula
(according to him):

Code: ( php )

Can't Update Date Field - Mysql Client Version 5.0.33
I am trying to update record and date field, but it fails although my timestamp echos perfectly.  I don't know what to do:  my sql client version is 5.0.33 and the model table has got date filed which is model_date. Code:

UPDATE Command Is Not Working On MySQL, Windows 2000 Server
Hi all,

I encountered mysterious problem with MySQL and PHP.

UPDATE command is not working on MySQL configured on Apache 2 with Windows 2000 Server.

It pulled my hairs for atleast 5 hours.

MySQL says Affected rows: 0 (Query took ~ sec) always?

Now, I've decided to move all PHP files and db to remote server.

Can anyone suggest possible reasons for above errors?

Need To Update Multiple Mysql Records With A Single Form Submit
I have a wish list like a shoping caty based on a mysql databse where i retrieve records with php I need to update the quantity which is in a text fields :

input type = text name = quantity[] value = $quantity
input type = checkbor value = $id name = id[]

I need to update quantities based on the primary id represented with id with a single submit.

Update Statement Causes Mysql Varchar Field To Be Set To Empty String
I have come across a problem that has me baffled.

I am using PHP with MySQL 4.1.14. Whenever I execute an update
statement against a specific table, some of the varchar fields do not
get set to the new values, but get set to empty strings instead.

I have simplified the code down to updating a single column in the
table, but the same results happen when updating just the single
column.

Here is the stripped down code which causes the problem:

$queryString = "UPDATE REGISTRATION SET passwd = '$pass'' WHERE id =
388";
$db = mysql_connect("hostname", "user", "pass");
mysql_select_db("CUSTOMER", $db) or die(mysql_error());
mysql_query($queryString, $db) or die(mysql_error());

Printing the query string after executing mysql_query shows the
following query:

UPDATE REGISTRATION SET passwd = 'test' WHERE id = 388

This query updates the column successfully when run directly through
phpMyAdmin. When run through PHP using the code above then column is
set to an empty string value.

There is no error returned if I call mysql_error() nor is there any
unusual info returned from mysql_info() (other than it telling me that
1 row was affected).

Does anyone have any ideas what the underlying problem is on this one?
Could be an attribute of the database table or columns that would cause
this behavior? I have racked my brain for a while over this problem.

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";
}
}

Select And Update Vs Update
For doing update or insert code, its worth noting that Example 1 seems to be around 60% faster than Example 2 PHP Code:

Update Mysql Blob With Another Blob Using Php
I have a blob field in a mysql database table. I want to copy a blob
from one record to another. I am having trouble transferring the data
via a php variable. Maybe I need to addslashes or convert to Hex or
something. I've tried a few things but can't quite get it. Here is
simplified code.

mysql_select_db($dbname, $connection);

$query = "SELECT blobthing
FROM mytable
WHERE id = 1;";

$results = mysql_query ($query, $connection);
$row = (mysql_fetch_assoc($result));
$varblobthing = $row['blobthing']; //put the blob in a variable

$query = "UPDATE mytable
SET blobthing = ".$varblobthing.",
WHERE id = 2;";

mysql_query ($query, $connection);


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