473,398 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Passing ID through form

Lazandra
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("db69117798","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_ffrontchest')");

if ($saved)
$infos = mysql ("db69117798", "select * from info");
while ($info = mysql_fetch_array($infos))
{
echo "<script type='text/javascript'>
<!--
window.location = 'payment.php?infoid=$info[id]'
//-->
</script>";
exit;
}
}

else
{
echo mysql_error() ;
}
}
[/PHP]
Sep 27 '07 #1
5 1681
Atli
5,058 Expert 4TB
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_globals 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).
Sep 27 '07 #2
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="<?=$names[infoid];?>" />
[/PHP]

I hope this makes sense...

xx
Sep 27 '07 #3
Atli
5,058 Expert 4TB
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="<?=$names[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:
Expand|Select|Wrap|Line Numbers
  1. # Do this after the INSERT query
  2. header("Location: payment.php?id=". mysql_insert_id());
  3.  
Sep 27 '07 #4
The header() function function worked perfectly! And so much simpler!

Spank you so much!

xxx
Sep 27 '07 #5
Atli
5,058 Expert 4TB
Glad I could help :)
Don't hesitate to post again if you have any more questions or problems (or anything) we can help with!
Sep 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
1
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:...
2
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,...
4
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...
8
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...
13
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...
7
by: AMP | last post by:
Hello, I have this in form1: namespace Pass { public partial class Form1 : Form { public Form2 form2; public Form1() {
0
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...
5
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.