473,396 Members | 1,764 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,396 software developers and data experts.

get table data from php/mysql and save as part of a form to another table

Hi,
I hope some one can help with this frustrating but probably simple issue.
I have 2 mysql tables, one called 'country' the other called 'businessdetails'.
On my page I have a form, people will register thier details and post the form back to 'businessdetails' table This works perfectly well so far. On this page I also pull in the country list from the 'country' table as a drop down list, again no problem at all, it works o.k.
Now the problem, ...as part of the users regististration I want them to select thier country from the 'country' dropdown list, register the rest of their details and save everything to 'businessdetails' where there is another 'country' column name which should be populated from the 'country'dropdown box, I just cannot get it to do this, it just posts the array created from the form details but not the country dropdown box..................HELP!

Thanks
Feb 20 '07 #1
8 5099
The1corrupted
134 100+
Hi,
I hope some one can help with this frustrating but probably simple issue.
I have 2 mysql tables, one called 'country' the other called 'businessdetails'.
On my page I have a form, people will register thier details and post the form back to 'businessdetails' table This works perfectly well so far. On this page I also pull in the country list from the 'country' table as a drop down list, again no problem at all, it works o.k.
Now the problem, ...as part of the users regististration I want them to select thier country from the 'country' dropdown list, register the rest of their details and save everything to 'businessdetails' where there is another 'country' column name which should be populated from the 'country'dropdown box, I just cannot get it to do this, it just posts the array created from the form details but not the country dropdown box..................HELP!

Thanks
Okay..

1. Try assigning numerical values to each country on that list and that numerical value will thus represent the country they selected. Make this a separate form or combine the tables.

2. Make the 'country' and 'businessdetails' on two separate pages and have them submitted separately.

3. Try not to rely on reading so much data from the tables. Write up an include or something to contain these boxes.
Feb 20 '07 #2
ronverdonk
4,258 Expert 4TB
Welcome to The Scripts!

I absolutely do not agree with the former poster. Having you data in tables makes it a lot easier to maintain. Also having 2 different forms also makes it a lot more difficult to maintain

Further I cannot guess what you are trying to do. In order to get things going post your code here.

And don't forget to enclose the posted code within php or code tags!!. See the Posting Guidelines at the top of this forum for the forum rules.

Ronald :cool:
Feb 20 '07 #3
Hi.
Thanks for the very prompt responses, I will post up the scripts this evening.
Just to clarify what I'm doing, I know it was a long winded post.:
On the registration page is a form (name, email address, url, etc)
Also an include(d) php script, this display the country list from the 'country' table.
This works.
When I submit the registration form to the 'businessdetails' table, i want it to include the country they would have selected. I just cannot get the 'country' field in 'businessdetails' populated, I'm sure I've got to get the selected country variable into the form, but I don't know how. The rest of the details (name, email address, url, etc) are inserted ok.

Thanks again.
Feb 21 '07 #4
Hi again, the code as requested, hope this helps. (If it does at least i'll have learnt something)
Thanks
FF

[PHP]
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

<?php
include "dbconn.php";
?>

//<?php
//include "countrylist.php";
//?>

<?php
//NORMALLY THE INCLUDE ABOVE IS USED, Below is the script for the countrylist.php
///////////////////////////////////////////////////////////////////////////////
// Doing my Country table query
$query = 'SELECT c.`printable_name` FROM country c';
$selection = mysql_query($query) or die('Query failed: ' . mysql_error());

$query="SELECT c.`printable_name` FROM country c";

$result = mysql_query ($query);
echo "<select printable_name=country value=''>Country</options>";

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[id]>$nt[printable_name]</option>";

}
echo "</select>";

// Output the resulting info

echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";


// Free resultset
mysql_free_result($result);

// Closing connection
//mysql_close($link);

//END OF THE NORMALLY INCLUDED SCRIPT
/////////////////////////////////////////////////////////////////////////////////
?>

[/PHP]
[HTML]
<p>
Business Name:<br />
<input type="text" name= "BusinessName" size="25" maxlength="40" value="" />
</p>

<p>
Web site address(URL):<br />
<input type="text" name= "URL" size="25" maxlength="40" value="" />
</p>

<p>
Email Address:<br />
<input type="text" name= "EmailAddr" size="25" maxlength="40" value="" />
</p>

<p>
Password Min 8 chars:<br />
<input type="text" name= "User_Password" size="12" maxlength="32" value="" />
</p>

<input type="Submit" name="Submit" value="Submit">
</p>
</form>
[/HTML]
[PHP]
<?php

//If Submit pressed

if (isset($_POST['Submit']))
{

//Get the data input from the form above

$BusinessName = $_POST['BusinessName'];
$URL = $_POST['URL'];
$EmailAddr = $_POST['EmailAddr'];
$printable_name = $_POST['Country'];

//Now put the information into the Business details table

$query = "INSERT INTO businessdetails SET BusinessName='$BusinessName', URL='$URL', EmailAddr='$EmailAddr', Country='$printable_name'";

$result = mysql_query($query);

//***********Successfull or Not?******************
if ($result) echo "<p>Details successfully added, Thankyou. </p>";
else echo "<P> Failed to register details<?p>";

//Below is a small test to see what's in the array to be submitted

echo '<pre>';
print_r($_POST);
echo '</pre>';

mysql_close();
}


?>
[/PHP]
Feb 21 '07 #5
ronverdonk
4,258 Expert 4TB
What is this statement doing there?
[php]echo "<select printable_name=country value=''>Country</options>";[/php]

The proper format of the select statement is and the text display option is:
[php]echo "<select name='country'>";
echo "<option value=''>Select Country</option>";[/php]

Ronald :cool:
Feb 21 '07 #6
Hi thanks for the response again.
Sorry, the first line that you mention wasn't supposed to be there, in my frustration I've been trying anything and everything.
As you pointed out, the correct line that you instruct to use has now allowed the country option to be part of the array.
Unless I'm missing something, on the second line you say to insert, if I use that piece of script, the dropdown box just repeats the words 'select country' a couple of hundred times.
So you have certainly moved me forward, thanks, I just now need to get a selected country from the dropdown list attached to the array so that it will insert into the business details table.

FF
Feb 22 '07 #7
ronverdonk
4,258 Expert 4TB
You should only construct the 'Select country' option once, at the start of the drop down box. I reworked tat particular part of your code a bit, hope that makes it clearer:

[php]
// perform the query
$result = mysql_query ($query)
or die("Query error: ".mysql_errror());;

// start the drop down box
echo "<select name='country'>";

// echo the top content of the drop down box
echo "<option value=''>Select Country</option>";

// echo every country in the array
while ($nt=mysql_fetch_array($result)){ //Array or records stored in $nt
echo "<option value='".$nt['id']."'>".$nt['printable_name']."</option>";
}

// close the drop down box
echo "</select>";
[/php]

Ronald :cool:
Feb 23 '07 #8
Yes that is clearer now and the dropdown is good.
Maybe the final furlong?....
I still don't get how when i make a selection from the dropdown, e.g. Canada, to save as part of the form into my business details table. I just cannot see how to get it posted with the other array items.
I can't see for the life of me how I make that connection work
At the bottom of my script I use the following to see what in the array will get submitted to the Business details table:

[PHP]echo '<pre>';
print_r($_POST);
echo '</pre>';
[/PHP]

This always shows the following:--- (note country is not populated even though a selection was made).


Details successfully added, Thankyou.

Array
(
[BusinessName] => xyz ltd
[url] => www.xyz.com
[EmailAddr] => xyz@xyz.com
[User_Password] => 12345678
[country] =>
[Submit] => Submit
)


I notice that even though I REM out the 'country item in the post section of the form, it is not used anyway as it was declared earlier e.g.

[PHP]$country = $_POST['country'];[/PHP]
is not required, so where do i get the data from to get it to be inserted, the query insert looks like this and it works ok for all the other bits of the form:

[PHP]$query = "INSERT INTO businessdetails SET BusinessName='$BusinessName', URL='$URL', EmailAddr='$EmailAddr', country='$country'";[/PHP]
Thanks again for your support
Feb 25 '07 #9

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

Similar topics

1
by: Caroline | last post by:
I need to update a table by copying a column from another table (having the same structure, but on another database), from the record having the same primary key. 1 - What is the correct...
5
by: Peter van Rijn | last post by:
Having my SQL-background in Oracle I'm looking for the MySQL equivalent for: update tableA set column1=(select count(*) from tableB where tableA.key= tableB.key) cannot find anything similar...
1
by: Bryan | last post by:
Hi, I have two tables. I want to update two columns in my first table, and with two values and held in my #temp table but based on a RUN_DATE from my first table. Can anyone point me in...
3
by: Shannan Casteel via AccessMonster.com | last post by:
I have a table called tblParttest. It has fields PartNo, PartNo2, PartNo3, .. .., PartNo25 and Quantity, Quantity2, Quantity3, ...Quantity25. If I enter "1234" into the PartNo field and "4" into...
0
by: lanky_tx | last post by:
Hi All, I am trying to acess the rows within a child table of a windows form datagrid. I have tried using the CurrencyManager & BindingManagerBase to get the data but doesn't work. The...
4
by: Cyberwolf | last post by:
I have a form that users enter information into. What I want to do is to update certain fields from another table once they have entered a number in a field. The form is already based on a query...
3
by: Dhanasekaran B | last post by:
Hi, I need to move one table in one server(Live) to another server(Development) through Visual basic coding. Please send soultion for this
3
by: webcat | last post by:
this is crazy, why can't i get this to work?!! i have a complex DB with many tables, but the ones that count here are: a linked SQL table with many records and a field called userEmail ...
2
by: Kaallis | last post by:
Hi there, Let me explain my problem more clearly: I have: a form FRM_Main 2 tables TBL_2007_OT and TBL_2007_Date a querry QRY_Dates_2007 The TBL_2007_Date is a number from 1 to 365 as...
3
by: kopekiR | last post by:
Hi I need to create a table that is empty, but has the data structure (i.e. the same columns) of another table. Both tables should be in the same DB. I need this as part of my VBA code. I...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
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
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.