Welcome to WebmasterWorld Guest from 54.204.100.232

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Can you spot the error please

help appreciated

   
7:40 pm on Mar 6, 2002 (gmt 0)

10+ Year Member



Hi,
I'm back. I've added a field to a table and I want to populate it with the values in another table. I have written this basic code so I can call it at my browser. This is so I can do it one record at a time, ie.

www.mydomain.com/update.php3?id=1

I have all required permissions and both tables match id for id. But this script does not update even though it seems to follow the syntax in the manual. The request to the table membersid is successful and brings in the value I need.

(any value xxxxx is for security reasons :)

<?php

// connect to database
$db = mysql_connect("localhost", "xxxxx", "xxxxx");
mysql_select_db("xxxxxxxxx");

// get value from existing column
$result = mysql_query("SELECT * FROM membersid WHERE id=$id");
$myrow = mysql_fetch_array($result);
$actualid=$myrow["actualid"];

// update new column
$result1 = mysql_query("UPDATE members SET actualid=$actualid WHERE id=$id");

?>

As always, thanks in advance for any help.

7:48 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



have you tried these queries while in mysql, through telnet?

do you get an error or does it not do anything at all?

7:51 pm on Mar 6, 2002 (gmt 0)

10+ Year Member



Write it like this

$result = mysql_query("UPDATE members SET actualid='".$actualid."' WHERE id=".$id)

or

$result = mysql_query("UPDATE members SET actualid='$actualid' WHERE id=$id")

7:54 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



if the fields are ints though that won't matter becasue they don't require single quotes.
7:57 pm on Mar 6, 2002 (gmt 0)

10+ Year Member



True.
Check the database through telnet like jatar_k said.

I always forget about ints not needing it.

7:59 pm on Mar 6, 2002 (gmt 0)

10+ Year Member




do you check the values of $result or $result1 anywhere? what is in your error logs?
8:06 pm on Mar 6, 2002 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I was wondering,

>>UPDATE members SET actualid=$actualid WHERE id=$id

if you are trying to set actualid == id shouldn't you be comparing a different field in your where statement?

I could be misunderstanding what you are trying to do

11:02 pm on Mar 6, 2002 (gmt 0)

10+ Year Member



Thanks for all the responses.

The first example by circuitjump did the trick.

This is a great forum. Quick and accurate responses, look out for me again as I get deeper into PHP :)