RE: [PHP] Storing/passing variables through multiple-part function/casestatement
| From: | John W. Holmes | Date: | Mon, 14 Oct 2002 22:37:17 +0000 |
| Subject: | RE: [PHP] Storing/passing variables through multiple-part function/casestatement | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119960@lists.php.net to get a copy of this message | ||
INSERT INTO table2 SELECT * FROM table1 WHERE ...
DELETE FROM table1 WHERE ...
Where are you stuck?
---John Holmes...
> -----Original Message-----
> From: Verdon Vaillancourt [mailto:vern@verdon.ca]
> Sent: Monday, October 14, 2002 4:31 PM
> To: PHP-General
> Subject: [PHP] Storing/passing variables through multiple-part
> function/casestatement
>
> Hi,
>
> I¹m trying to cobble together a case where where data is retrieved
from
> one
> row of a mySQL table, the row is deleted, the retrieved data is
inserted
> into a new row in different table. Most of my code seems to be working
(I
> think the data is being retrieved, the old row is being deleted, the
new
> row
> is being created) but I am not getting a grip on how to pass the
retrieved
> data into the sql insert statement for the new row in the second
table.
> I¹m
> sure I¹m missing something very basic and would appreciate any help
> extended. The case statement as is now, is below.
>
> TIA, verdon
>
> Ps. Please cc me in any answer to the list as I am on digest mode
>
> case "finishPending":
> if ($user_dblocation)
> {
> @mysql_select_db("$user_dbname") or die ("Unable to select
> database");
>
> $result = mysql_query("select uid, uname, name, url,
email,
> femail, pass, company, bio, description, address, city, province,
> postcode,
> phone, fax, tollfree, otherphone, cat AS uid, uname, name, url, email,
> femail, pass, company, bio, description, address, city, province,
> postcode,
> phone, fax, tollfree, otherphone, cat from " .
$table_prefix."users_que
> where uid='$approve_uid'");
> list($uname) = mysql_fetch_row($result);
>
> mysql_query("lock tables " . $table_prefix."users_que
WRITE");
> mysql_query("delete from " . $table_prefix."users_que
where
> uid='$approve_uid'");
> mysql_query("unlock tables");
> @mysql_select_db("$dbname") or die ("Unable to select
> database");
> }
> else
> {
> $result = mysql_query("select uid, uname, name, url,
email,
> femail, pass, company, bio, description, address, city, province,
> postcode,
> phone, fax, tollfree, otherphone, cat AS uid, uname, name, url, email,
> femail, pass, company, bio, description, address, city, province,
> postcode,
> phone, fax, tollfree, otherphone, cat from " .
$table_prefix."users_que
> where uid='$approve_uid'");
> list($uname) = mysql_fetch_row($result);
>
> mysql_query("lock tables " . $table_prefix."users_que
WRITE");
> mysql_query("delete from " . $table_prefix."users_que
where
> uid='$approve_uid'");
> mysql_query("unlock tables");
> }
>
> mysql_query("LOCK TABLES " . $table_prefix."stories WRITE");
> mysql_query("UPDATE " . $table_prefix."stories SET
> informant='$anonymous' WHERE informant='$uname'");
> mysql_query("UPDATE " . $table_prefix."stories SET
> aid='$anonymous'
> WHERE aid='$uname'");
> mysql_query("UNLOCK TABLES");
>
> global $uid, $uname, $name, $url, $email, $femail, $pass,
> $company,
> $bio, $description, $address, $city, $province, $postcode, $phone,
$fax,
> $tollfree, $otherphone, $cat;
>
> $sql = "insert into ".$table_prefix."users
>
(name,uname,email,femail,url,pass,company,bio,description,address,city,p
ro
> vi
> nce,postcode,phone,fax,tollfree,otherphone,cat,conversionflag) values
>
('$name','$uname','$email','$femail','$url','$pass','$company','$bio','$
de
> sc
>
ription','$address','$city','$province','$postcode','$phone','$fax','$to
ll
> fr
> ee','$otherphone','$cat','1')";
>
> if ($user_dblocation)
> {
> @mysql_select_db("$user_dbname") or die ("Unable to select
> database");
> mysql_query("lock tables " . $table_prefix."users WRITE");
> $result = mysql_query($sql);
> mysql_query("unlock tables");
> @mysql_select_db("$dbname") or die ("Unable to select
> database");
> }
> else
> {
> mysql_query("lock tables " . $table_prefix."users WRITE");
> $result = mysql_query($sql);
> mysql_query("unlock tables");
> }
>
> if (!$result)
> {
> echo mysql_errno(). ": ".mysql_error(). "<br />";
> return;
> }
>
> html_header_location("admin.php?op=adminMain");
> echo mysql_error();
> break;