Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

update and arrays

Posted on 2013-05-22
6
Medium Priority
?
176 Views
Last Modified: 2013-05-23
code:
---------------------------

record_set('artGalNames',"SELECT * FROM art_gallery WHERE artgal_Name = $_POST[name]");
      
      //update the order
      if ($_POST) {
            mysql_query("UPDATE art_gallery SET
                  artgal_Name= '".$_POST[name]."',
                  WHERE artgal_Name = ".$_POST[name]."
            ");

---------------------------

The code below is being used to update the name of an artist in a database called art_gallery
A form posts the artist's name (name) which is used to select an array from art_gallery where all the names = name (the artist's name is represented multiple times)

I need to be able to introduce a loop  which will update ALL the records where the artgal_Name = name
0
Comment
Question by:doctorbill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 20

Expert Comment

by:Mark Brady
ID: 39188518
Two things

1: What is record_set() ? Not sure what that is trying to do.
2: Your query logic doesn't make sense.

You are trying to update a field with the value that is already in that field.

If there is a record in the table and the artgal_Name for that record is 'John Smith'

Your query is going to try to update that record to 'John Smith'

Perhaps if you can post a database schema so I can see how it is built then supply a bit more information as to what the form actually does.

Then I can certainly help you with the code.

Cheers
0
 

Author Comment

by:doctorbill
ID: 39188545
Can you give me an example of updating multiple records in a database :
for example, the database has a variable number of entries with the name "test

I want to be able to update all entries with the name "test" to "test1"

I am ok with database connections and showing records - it is just the looping part I am having a problem with
0
 
LVL 20

Assisted Solution

by:Mark Brady
Mark Brady earned 2000 total points
ID: 39188570
UPDATE `tablename` SET `column` = 'test1' WHERE `column` = 'test';


That query is not a loop but it will update ALL records where the value is 'test'

`tablename` and `column` need to be renamed with your table name and the column name you are using.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:doctorbill
ID: 39188643
How is this put in between php tags on a php page?

<?php


?>
0
 
LVL 20

Accepted Solution

by:
Mark Brady earned 2000 total points
ID: 39188658
<?php

$sql = "UPDATE `tablename` SET `column` = 'test1' WHERE `column` = 'test'";

$result = mysql_query($sql);

if (!$result) {
    die(mysql_error());
}

?>

Open in new window

0
 

Author Closing Comment

by:doctorbill
ID: 39191535
solved
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question