i am building a registration page where a user register for a username. i am able to insert this into mysql. the situation is every time data is inserted into example table1 in mysql in database1 for example at the same time i would like to extract the username, password and email from table1 based on the last inserted row and insert these values into another table ex table2 in a different database called database2.
the issue i am having is with the select query as it is not returning values from table1 for me to insert those values into
table2 in database2.
NOTE = the hostname, user name, password are the same for both the tables and databases and are physically in 1 server machine itself.
presently my code is -
$conn = mysql_connect($hostname, $user, $dbpassword);
-
-
if(!$conn)
-
{
-
-
}
-
else
-
{
-
mysql_select_db($database, $conn);
-
$insertqueryresult = mysql_query($insertqueryfortable1);
-
$lastid = mysql_insert_id();
-
-
$selectqueryoftable1 = "Select username, password, email from table1 where slno = '$lastid'";
-
slno is an autoincrement and primary key which is like a serial number
-
-
$selectunempsq = mysql_query($selectqueryoftable1);
-
-
while($rowunemps = mysql_fetch_assoc($selectunempsq))
-
{
-
$unis = $rowunemps['username'];
-
$psis = $rowunemps['password'];
-
$emis = $rowunemps['email'];
-
}
-
-
$insertqueryfortable2 = "Insert into table2(username, password, email) VALUES ('$unis', '$psis', '$emis')";
-
-
$unpsemresult = mysql_query($insertqueryfortable2);
-
the values in the 3 variables $unis, $psis, $emis are blank.
i have tried
a) while($rowunemp s = mysql_fetch_arr ay($selectunemp sq))
b) creating the table2 in database1 itself to see if it works
but both these methods is not working
data is being inserted into table1 but i am not able to read the values stored in table1 and then insert into table2. i have used echoing the values of the 3 variables $unis, $psis, $emis however the values are blank. with the insertquery for table2 everytime the insert query is executed a new row is created but there are no values for the 3 fileds username, password, email in table2
initially i had $conn = mysql_connect($ hostname, $user, $dbpassword); 2 times as the tables were in different database now i have only 1 mysql_connect
please advice how to fix this ideally both tables sitting in different databases.
thanks.
2 1396 This is the last warning after several (incl PMs) previous: As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use the tags in future.
MODERATOR.
You should test the status of each MySQL function after executing it by checking the false or true result. A statement should be something like:[php]$selectunempsq = mysql_query($se lectqueryoftabl e1)
or die("SELECT error: ".mysql_error() );[/php]That is the only way to see if the error you presumed is really that and not the result of the execution of an invalid SQL statement.
Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: alwaysawn |
last post by:
Hi,
I have databases on two different machines which I want to select from
in one query, any good way of doing this without moving tables from
one machine to another?
Thanks,
Alwaysawn
|
by: Henri |
last post by:
Hello,
I am quite new to ms-sql and I have a problem : I want to create an SQL
request which would copy serveral records from a table in a given database
to another table (with exactly the same structure) in another database
(theses two tables and databases already exist).
Could you please tell me how to do this ? I dont know how to access two
different databases in a single SQL request.
|
by: Rick Brandt |
last post by:
I know that a heterogeneous query joining tables from two different servers
has performance penalties but is the same true when joining tables from two
different databases on the same SQL Server 2000 instance?
We are looking at setting up a Data Warehouse using DTS on a SQL Server box
and I'm wondering about the best way to logically set it up; i.e. one big
honking db or several dbs determined by some logical organization. With the...
|
by: Steve |
last post by:
Hi;
I am looking for suggestions about how to solve a problem using tsql.
I have been asked to create a report concerning 4 tables.
Each of the 4 tables is in its own database.
The 4 tables are identical in name and structure.
|
by: Greg |
last post by:
I am working on a project that will have about 500,000 records in an XML
document. This document will need to be queried with XPath, and records
will need to be updated. I was thinking about splitting up the XML into
several XML documents (perhaps 50,000 per document) to be more efficient but
this will make things a lot more complex because the searching needs to go
accross all 500,000 records. Can anyone point me to some best practices...
| |
by: Shane |
last post by:
I wonder if someone has any ideas about the following.
I am currently producing some reports for a manufacturing company who work
with metal.
A finished part can contain multiple sub-parts to make up the finished part.
The sub-parts can also be made up of sub-parts and those sub-parts can also
be made up of sub-parts etc etc.
All parts are contained within the same table and I have a seperate table
|
by: Ober |
last post by:
I'm having trouble with my security model, Application_Start, and accessing
my database.
My ASP.NET app is only going to be running in an intranet environment (not
on the public Internet). The production environment will have installed
everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
Win2k Server).
|
by: sql_er |
last post by:
Guys,
I have an XML file which is 233MB in size. It was created by loading 6
tables from an sql server database into a dataset object and then
writing out the contents from this dataset into an XML file.
Once my application starts, I load this XML file into a DataSet object
using "ReadXML" function. This creates a dataset in memory with 6
tables.
|
by: plmanikandan |
last post by:
Hi,
I'm having two databases in the name of n1,n2 having same design
I want to query both the databases by giving the database name in query
Databases
N1
N2
Table(both database contains same table)
Detail
Table details
No -int
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |