New Member Needs PHP Help With MySQL Database

need mysql to take data from one table and update another table with i

Page 1 of 1

2 Replies - 1616 Views - Last Post: 31 July 2007 - 10:43 AM Rate Topic: -----

#1 rtnsolutions   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 28-July 07

New Member Needs PHP Help With MySQL Database

Post icon  Posted 30 July 2007 - 10:37 AM

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:
<?php require_once('../../Connections/oscmax.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" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>


Is This A Good Question/Topic? 0
  • +

Replies To: New Member Needs PHP Help With MySQL Database

#2 Amadeus   User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 253
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: New Member Needs PHP Help With MySQL Database

Posted 31 July 2007 - 10:23 AM

Are you getting error(s)? If so, can you post them?
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5552
  • View blog
  • Posts: 14,558
  • Joined: 18-April 07

Re: New Member Needs PHP Help With MySQL Database

Posted 31 July 2007 - 10:43 AM

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

UPDATE products_description 	
SET `products_description` = 	( SELECT `description`
FROM products_testing
WHERE products_testing.description = products_description.products_description)
  ( 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.


This post has been edited by Martyr2: 31 July 2007 - 11:00 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1