Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Passing a value using drop down Using Html Form to php
Old 04-06-2009, 11:42 AM Passing a value using drop down Using Html Form to php
Junior Talker

Posts: 1
Trades: 0
The code with the dropdown:
I can't seem to to get the value from the drop down box to add to the database.

#!c:/php/php.exe
<?php
// open database connection
$server="localhost";
$user="student1";
$password="student1pw";
$database="localdatabase";

$connect = mysql_connect("$server","$user","$password");
if (!$connect)
{
die('Could not connect!' . mysql_error());
} // end if
mysql_select_db($database);
// generate and execute query
$query = "SELECT TripID,TripName FROM tripinformation";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());
// if records are present
if (mysql_num_rows($result) > 1) {
$row = mysql_fetch_object($result);
if (mysql_num_rows($result) > 0) {




print '<form method="post" action="Customeroutings.php">';
print "\n";
$TripName =0;

print "<select name=\"TripSelect\>";
while ($row = mysql_fetch_object($result)) {
?>
<option value="<?= $row->TripID ?>" ><?=$row->TripName?> </option>

<input type="hidden" name="test" value="<?echo TripName?>">




<?php
} // end while
print "</select>";



} // end if
echo "<br>";
echo "Firstname:";
echo "<input type=\"text\" name=\"Name\"> ";
echo "<br>";
echo "Surname:";
echo "<input type=\"text\" name=\"Surname\"> ";
echo "<br>";
echo "Phonenumber:";
echo "<input type=\"text\" name=\"Phonenumber\">";

echo "<br><input type=\"submit\" name=\"submit\" value=\"Submit!\">";

echo '</form>';

}
else
{
print "uh oh!";
} // end if


mysql_close($connect)

?>






The code im trying pass the value to

#!c:/php/php.exe
<?php


$server="localhost";
$username ="student1";
$password="student1pw";
$database="localdatabase";
$connect = mysql_connect("$server","$username","$password");
$test = $_POST["TripSelect"];
print $test;
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}// Create database
mysql_select_db($database, $connect);
$sql="INSERT INTO customeroutings(Name,Surname, Phonenumber,TripName)
VALUES
('$_POST[Name]',

'$_POST[Surname]',
'$_POST[Phonenumber]'
'$_POST[test]')";

if (!mysql_query($sql,$connect))
{
die('Error: ' . mysql_error());
}
echo "You have been added too the database: (Please click the on the link to return to the home page)";
mysql_close($connect)
?>
<br>
<br>
<br>
Cburns is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-08-2009, 10:51 AM Re: Passing a value using drop down Using Html Form to php
dark_lord's Avatar
Experienced Talker

Posts: 41
Name: Parijat Roy
Location: INDIA-KOLKATA
Trades: 0
i think you need to change two areas
PHP Code:
<option value="<?= $row->TripID ?>" ><?=$row->TripName?> </option>

<input type="hidden" name="test" value="<?echo TripName?>">
to
PHP Code:
<option value="<?=$row->TripName?>" ><?=$row->TripName?> </option>
AND

PHP Code:
$sql="INSERT INTO customeroutings(Name,Surname, Phonenumber,TripName)
VALUES
('
$_POST[Name]',

'
$_POST[Surname]',
'
$_POST[Phonenumber]'
'
$_POST[test]')"
to
PHP Code:
$name $_POST["Name"];
$surname $_POST["Surname"];
$phone $_POST["Phonenumber"];
$trip $_POST["TripSelect"];
$sql="INSERT INTO customeroutings(Name,Surname, Phonenumber,TripName)
VALUES ('
$name','$surname','$phone','$trip')"
__________________
I AM THE BEAUTIFUL NIGHTMARE

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by dark_lord; 04-08-2009 at 10:58 AM..
dark_lord is offline
Reply With Quote
View Public Profile Visit dark_lord's homepage!
 
Old 04-09-2009, 12:58 AM Re: Passing a value using drop down Using Html Form to php
Novice Talker

Posts: 7
Trades: 0
Woah thats a bit of a mess that script is, I would suggest to re-write the hole thing over again a bit more simple and not as complex and you should get better results.

I am not going to go into full detail right here because I don't have the time, but if you want go to customscripters.com and submit a request for a quote for this and I can have them set you up with the full source on this guaranteed working for $5.

Last edited by ryandanielt; 04-09-2009 at 01:00 AM..
ryandanielt is offline
Reply With Quote
View Public Profile
 
Old 04-09-2009, 01:16 AM Re: Passing a value using drop down Using Html Form to php
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by ryandanielt View Post
Woah thats a bit of a mess that script is, I would suggest to re-write the hole thing over again a bit more simple and not as complex and you should get better results.

I am not going to go into full detail right here because I don't have the time, but if you want go to <<LINK DROP>> and submit a request for a quote for this and I can have them set you up with the full source on this guaranteed working for $5.
Or he could just hang onto his money and make the changes Parijat suggested.

@Cburns
Your code will be easier to read and correct if you use the PHP tags to post it. Formatting is lost when you copy and paste.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-30-2009, 03:24 PM Re: Passing a value using drop down Using Html Form to php
Junior Talker

Posts: 1
Name: Jack
Trades: 0
cburns did that fix your problem? I'm looking to do something like what you had asked for.
jchri66 is offline
Reply With Quote
View Public Profile
 
Old 04-30-2009, 03:47 PM Re: Passing a value using drop down Using Html Form to php
Average Talker

Posts: 28
Name: Amit Soni
Trades: 0
Here's another tip(even though I always recommend, keeping the php/html separate from each other as much as possible.

Code:
echo "Firstname:";
echo "<input type=\"text\" name=\"Name\"> ";
echo "<br>";
echo "Surname:";
echo "<input type=\"text\" name=\"Surname\"> ";
echo "<br>";
echo "Phonenumber:";
echo "<input type=\"text\" name=\"Phonenumber\">";
Code:
echo '
Firstname:<input type="text" name="Name"><br>
Surname:<input type="text" name="Surname"><br>
Phonenumber:<input type="text" name="Phonenumber">';
__________________
--Amit

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

amitsoni is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Passing a value using drop down Using Html Form to php
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.37850 seconds with 12 queries