|
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>
|