Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,670 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,167 people online right now. Registration is fast and FREE... Join Now!




New Member Needs PHP Help With MySQL Database

 
Reply to this topicStart new topic

New Member Needs PHP Help With MySQL Database, need mysql to take data from one table and update another table with i

rtnsolutions
post 30 Jul, 2007 - 09:37 AM
Post #1


New D.I.C Head

*
Joined: 28 Jul, 2007
Posts: 1


My Contributions


Need help, i cannot get this code to work. New to php coding, need the database to update a table called products_description, with column called products_description from another table called products_testing column called Description. Cant seem to get this code to work. Please help fix this code for me and explain what i have done wrong.
Heres the code:
CODE

<?php require_once('../../Connections/oscmax.php'); ?>
<?php
$colname_Recordset1 = "-1";
if (isset($_GET['Description'])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['Description'] : addslashes($_GET['Description']);
}
mysql_select_db($database_oscmax, $oscmax);
$query_Recordset1 = sprintf("SELECT * FROM products_testing WHERE Description = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $oscmax) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$query ("select Description from products_testing");
$query ("UPDATE products_description set products_description") = ("select Description from products_testing where products_testing.Description = products_description.products_description")
$update = "UPDATE products_description SET products_description='$value' WHERE products_testing .Description='$*'";
mysql_query($update) or die("Unable to update because: ".mysql_error);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 31 Jul, 2007 - 09:23 AM
Post #2


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,178



Thanked 33 times

Dream Kudos: 25
My Contributions


Are you getting error(s)? If so, can you post them?
User is online!Profile CardPM

Go to the top of the page

Martyr2
post 31 Jul, 2007 - 09:43 AM
Post #3


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,062



Thanked 175 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Wow, you sure do have some confusing stuff there. You should probably think of better names for some of the variables and columns you use. Just your description of the problem I had to read like three times because you have a column and a table called the same thing.

But anyways...a few things to point out here. Some are key and some are more cosmetic for your benefit later)

1) Costmetic - You should break up your lines a little into logical areas so that you and others can make quick sense of each section saying "ok these are connections, these are queries, these are formatting lines" etc.

2) Key - Your $query lines should probably be formatted like $query = "string here". On one of the lines you are even missing a semicolon on the end of the statement.

3) Key - You can accomplish a table to table copy two ways. One by using an update such as the one below....

CODE


UPDATE products_description     
SET `products_description` =     ( SELECT `description`
FROM products_testing
WHERE products_testing.description = products_description.products_description)
WHERE EXISTS
  ( SELECT `description`
    FROM products_testing
    WHERE products_testing.description = products_description.products_description);



This is saying update the products_description field with the description from products_testing where the descriptions between the two tables match (hence the need for the exists clause to describe that match). A note here, you should try matching records through something like primary keys so that you have solid matching. Matching ordinary fields, which may differ in things like case, spaces etc but appear the same, will make matches fail.

The second way is to select the correct value using a select, store it in a variable, then use that variable in another table. The problem with this way is that if one of the queries fails, you could potentially have an orphan record (a record with no matching row in the other table). To help prevent this (and if your database supports it) you could potentially use a transaction. See the link below on what are transactions. You attempted to do this first and it can work, but your string was impromper. $query = "statement";

4) Costmetic - as mentioned before you really should come up with better and more UNIQUE variable names. Simply tacking on a "1" isn't much of a difference and can be a bit confusing for others to read.

MySQL Transactions Overview

Apply some of what I have put above and repost so we can see how everything has been cleaned up and write out any error messages you are getting. These will be of great help to us.

Thanks!

This post has been edited by Martyr2: 31 Jul, 2007 - 10:00 AM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 05:59AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month