Hiya
I have an order form and once submitted it goes straight to the payment form. I have 2 databases one order and the other payment. So in the order form i need to pass the id to the payment form to tie them together.
Heres my code... can anyone help?
Cheers xx
[PHP]
if ($submit == "Next")
{
$saved = mysql("db691177 98","insert into info values (0, '$name', '$address', '$city', '$county', '$postcode', '$country', '$email_address ', '$tel', '$fax', '$pet_name', '$pet_breed', '$pet_sex', '$pet_steps', '$pet_weight', '$pet_legs', '$pet_frontlegs ', '$pet_vet', '$pet_cause', '$pet_arise', '$pet_comments' , '$pet_aweight', '$pet_bshoulder ', '$pet_ctail', '$pet_dchest', '$pet_echest', '$pet_ffrontche st')");
if ($saved)
$infos = mysql ("db69117798 ", "select * from info");
while ($info = mysql_fetch_arr ay($infos))
{
echo "<script type='text/javascript'>
<!--
window.location = 'payment.php?in foid=$info[id]'
//-->
</script>";
exit;
}
}
else
{
echo mysql_error() ;
}
}
[/PHP]
5 1710 Atli 5,058
Recognized Expert Expert
Hi Lazandra. Welcome to The Scripts!
I see you print some JavaScript code there. Is that not working?
Could we see the code that is accepting the ID?
Also, I have a few thoughts on your code.
First, all the variables in your first query. Where are they coming from? If they are from a form, are you retrieving them from the $_POST super-global or are you perhaps relying on the register_global s constant? (which is very very bad btw!)
Second, your second query, you use * (wildcard) to fetch every single column of the table, when all you need is the ID column. This will increase the database load, which again may cause problems. I would recommend against using the * (wildcard) wherever possible, even if that means typing the names of 45 out of 50 columns. This will also protect your code from failing due to any future table alterations (especially with UPDATE and INSERT statements).
Hi Atli!
Thanks for the reply :-)
I'm using a form and its going through POST. Your right about the query using * i will change it forthwith.
In regards to the javascript; that is working and directing to the correct page. But the id that keeps being passed is "1" instead of the actual id.
This is the accepting code.
[PHP]
<input name="infoid" type="hidden" value="<?=$name s[infoid];?>" />
[/PHP]
I hope this makes sense...
xx
Atli 5,058
Recognized Expert Expert
In regards to the javascript; that is working and directing to the correct page. But the id that keeps being passed is "1" instead of the actual id.
This is the accepting code.
[PHP]
<input name="infoid" type="hidden" value="<?=$name s[infoid];?>" />
[/PHP]
This is most likely because the second query in your first code will always fetch every single row. Then you loop through them using a while loop, which will echo the JavaScript with the ID of the first row, causing the browser to be redirected and ignore all the other rows.
To fix this you need to put a WHERE clause and specify the row you want to fetch.
Alternately you could use the mysql_insert_id () function to fetch the ID of the row you inserted with your first query and pass that through your JavaScript.
Also, consider using the header() function instead of the JavaScript.
For example: -
# Do this after the INSERT query
-
header("Location: payment.php?id=". mysql_insert_id());
-
The header() function function worked perfectly! And so much simpler!
Spank you so much!
xxx
Atli 5,058
Recognized Expert Expert
Glad I could help :)
Don't hesitate to post again if you have any more questions or problems (or anything) we can help with!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Paul |
last post by:
I want to use sessions to cover myself in case the user switches off cookies
so I am passing the session ID manually through a hidden input field. This
is what I have so far.
index.php page contains:
<?php
$_SESSION = "";
$_SESSION = "";
|
by: Paul |
last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and
session.use_trans_sid = 1 in my php.ini file. Index.php contains:
----------------------------------------------------------------------------
<?php
ini_set("session.use_cookies", "off");
ini_set("session.use_trans_sid", "on");
session_start();
$_SESSION = "";
$_SESSION = "";
echo "<form method='POST' action='login.php'>
|
by: Curtis Justus |
last post by:
Hi,
I currently have a control that is on a form and I want to pass that
exact instance of the control to another form (a child form that
appears on a button click). The control has state, etc. that works with
both forms.
In my button click on FormA, I take my control and pass it to a constructor
in FormB. Here is the code in the constructor:
|
by: Ron Rohrssen |
last post by:
I want to show a dialog and when the form (dialog) is
closed, return to the calling form. The calling form
should then be able to pass the child form to another
object with the form as a parameter.
For example,
FormOptions formOptions = new FormOptions();
if (formOptions.ShowDialog(this) == DialogResult.OK)
{
|
by: Johnny |
last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form
(fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip
code is passed to the lookup form/dialog by reference. I then load a...
| |
by: Deano |
last post by:
Apparently you can only do this with one value i.e Call
MyAssetLocationZoom(Me!txtLocation, "Amend data")
This runs;
Public Sub MyAssetLocationZoom(ctl As Control, formName As String)
On Error GoTo err_zoom
strFormName = formName
|
by: AMP |
last post by:
Hello,
I have this in form1:
namespace Pass
{
public partial class Form1 : Form
{
public Form2 form2;
public Form1()
{
|
by: Magnus Bergh |
last post by:
I am developing an application for pocketpc and this involvs a but of
juggling with different forms.
I have an "order entry" type of application. On the main form I have a
grid which displays Order headers. Let call this form "OrderList"
From this view I edit/enter new orders by opening a new form for
entering data. This is done using (more or less) the designer generated
forms, so I have a "Order edit view dialog. I pass the binding...
|
by: jmartmem |
last post by:
Greetings,
I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few.
Upon clicking the 'submit' button, I want the form values to pass to a confirmation page that shows the values entered and selected, with a CDONTS auto email generated at the same time. My problem is that I'm having trouble passing the values from the form to both the confirmation page and the...
|
by: John Sheppard |
last post by:
Hello there I was wondering if anyone could help me,
I am trying to pass a typed dataset to a dialoged child form by reference.
I have binding sources sitting on the child form. So to refresh them I just
set their datasource. I am guessing this is probably what is causing the
problem. Is there a better way to do this?
Anyway this all works happily and things show up when the record already
exists but I have 2 problems ;
1) When I add...
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |