Forum Moderators: coopster
Code:
<HTML>
<HEAD>
</HEAD>
<?php
include("dbinfo.inc.php");
$db = mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to connect to database");
if($_POST['add_x']) // Test the button chosen
{ // _x is used because the coordinates of the pic are needed
// Post the vairables
$FIRST_NAME = $_POST['FIRST_NAME'];
$LAST_NAME = $_POST['LAST_NAME'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$PHONE_NUM = $_POST['PHONE_NUM'];
$EMAIL = $_POST['EMAIL'];
$Membership = $_POST['Membership'];
$air_pref_1 = $_POST['air_pref_1'];
$air_pref_2 = $_POST['air_pref_2'];
$air_pref_3 = $_POST['air_pref_3'];
$hotel_pref_1 = $_POST['hotel_pref_1'];
$hotel_pref_2 = $_POST['hotel_pref_2'];
$hotel_pref_3 = $_POST['hotel_pref_3'];
$car_pref_1 = $_POST['car_pref_1'];
$car_pref_2 = $_POST['car_pref_2'];
$car_pref_3 = $_POST['car_pref_3'];
$Client_num = $_POST['Client_num'];
$query = "INSERT INTO Clients VALUES ('$FIRST_NAME','$LAST_NAME','$Address','$City',
'$State','$Zip','$PHONE_NUM','$EMAIL','$Membership','$air_pref_1','$air_pref_2',
'$air_pref_3','$hotel_pref_1','$hotel_pref_2','$hotel_pref_3','$car_pref_1',
'$car_pref_2',$car_pref_3', NULL)"; // Add values to database
mysql_query($query, $db);
//echo "Record Added";
mysql_close(); // Close the Database
}
else if($_POST['edit_x'])
{
$FIRST_NAME = $_POST['FIRST_NAME'];
$LAST_NAME = $_POST['LAST_NAME'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$PHONE_NUM = $_POST['PHONE_NUM'];
$EMAIL = $_POST['EMAIL'];
$Membership = $_POST['Membership'];
$air_pref_1 = $_POST['air_pref_1'];
$air_pref_2 = $_POST['air_pref_2'];
$air_pref_3 = $_POST['air_pref_3'];
$hotel_pref_1 = $_POST['hotel_pref_1'];
$hotel_pref_2 = $_POST['hotel_pref_2'];
$hotel_pref_3 = $_POST['hotel_pref_3'];
$car_pref_1 = $_POST['car_pref_1'];
$car_pref_2 = $_POST['car_pref_2'];
$car_pref_3 = $_POST['car_pref_3'];
$Client_num = $_POST['Client_num'];
$query = "UPDATE Clients SET ('$FIRST_NAME','$LAST_NAME','$Address','$City',
'$State','$Zip','$PHONE_NUM','$EMAIL','$Membership','$air_pref_1','$air_pref_2',
'$air_pref_3','$hotel_pref_1','$hotel_pref_2','$hotel_pref_3','$car_pref_1',
'$car_pref_2',$car_pref_3', NULL)";
mysql_query($query, $db);
//echo "Update Successfull";
mysql_close();
}
else if($_POST['delete_x'])
{
$FIRST_NAME = $_POST['FIRST_NAME'];
$LAST_NAME = $_POST['LAST_NAME'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$PHONE_NUM = $_POST['PHONE_NUM'];
$EMAIL = $_POST['EMAIL'];
$Membership = $_POST['Membership'];
$air_pref_1 = $_POST['air_pref_1'];
$air_pref_2 = $_POST['air_pref_2'];
$air_pref_3 = $_POST['air_pref_3'];
$hotel_pref_1 = $_POST['hotel_pref_1'];
$hotel_pref_2 = $_POST['hotel_pref_2'];
$hotel_pref_3 = $_POST['hotel_pref_3'];
$car_pref_1 = $_POST['car_pref_1'];
$car_pref_2 = $_POST['car_pref_2'];
$car_pref_3 = $_POST['car_pref_3'];
$Client_num = $_POST['Client_num'];
$query = "DELETE FROM Clients WHERE Client_num = $Client_num ('$FIRST_NAME','$LAST_NAME','$Address','$City',
'$State','$Zip','$PHONE_NUM','$EMAIL','$Membership','$air_pref_1','$air_pref_2',
'$air_pref_3','$hotel_pref_1','$hotel_pref_2','$hotel_pref_3','$car_pref_1',
'$car_pref_2',$car_pref_3', NULL)";
mysql_query($query, $db);
//echo "Delete Successfull";
mysql_close();
?>
<BODY BGCOLOR="#DEDFE4">
<CENTER>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="755" HEIGHT="578" bgcolor="#FFFFFF" style="border-collapse: collapse" bordercolor="#111111">
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="76">
<img border="0" src="images/samsbutton.jpg" width="113" height="76"></TD>
<TD ROWSPAN="1" COLSPAN="2" WIDTH="642" HEIGHT="76">
<img border="0" src="images/travelbutton.jpg" width="642" height="76"></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="77">
<img border="0" src="images/side3.jpg" width="113" height="107"></TD>
<form name = "index" action = "index.php" method = "post">
<TD ROWSPAN="8" COLSPAN="1" WIDTH="516" HEIGHT="422" valign=top>
<font size="4">Client Number: </font>
<input type="text" name="Client_num" size="20" value="<? echo $Client_num;?>">
<p><font size="4">First Name:
<input type="text" name="FIRST_NAME" size="19">Last Name:
<input type="text" name="LAST_NAME" size="22"></font></p>
<p><font size="4">Address:</font><font size="4">
<input type="text" name="Address" size="19"></font></p>
<p><font size="4">City:
<input type="text" name="City" size="21">
State:
<input type="text" name="State" size="6">
Zip:
<input type="text" name="Zip" size="14">
</font></p>
<p><font size="4">Phone:</font>
<input type="text" name="PHONE_NUM" size="21"> <font size="4">
Memberships:</font>
<textarea rows="2" name="Membership" cols="15"></textarea></p>
<p><font size="4">Email:</font>
<input type="text" name="EMAIL" size="21"> <font size="4">
</font></p>
<p><font size="2">Airline Preference:
Hotel Preference:
Car Company Preference:</font></p>
<p><font size="2"></font>
<input type="text" name="air_pref_1" size="14"><font size="2">
</font>
<input type="text" name="hotel_pref_1" size="14"> <font size="2">
</font>
<input type="text" name="car_pref_1" size="14"></p>
<p><font size="2"> </font>
<input type="text" name="air_pref_2" size="14"> <font size="2">
</font>
<input type="text" name="hotel_pref_2" size="14"> <font size="2">2
</font>
<input type="text" name="car_pref_2" size="14"></p>
<p><font size="2">3 </font>
<input type="text" name="air_pref_3" size="14"> <font size="2">
</font>
<input type="text" name="hotel_pref_3" size="14"> <font size="2">
</font>
<input type="text" name="car_pref_3" size="14"></p>
<p align="center">
<input border="0" src="images/add.gif" name="add" width="99" height="24" type="image">
<input border="0" src="images/edit.gif" name="edit" width="117" height="24" type="image">
<input border="0" src="images/delete.gif" name="delete" width="99" height="24" type="image">
<p align="center">
<input border="0" src="images/search.gif" name="search" width="117" height="24" type="image"></TD>
<TD ROWSPAN="9" COLSPAN="1" WIDTH="126" HEIGHT="502">
<img border="0" src="images/side1.jpg" width="126" height="627"></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="52">
<a href="flights.php?<? echo $Client_num; // Passes Variables in URL?>">
<img border="0" src="images/flightsbutton%20copy.jpg" width="113" height="64"></a></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="47">
<a href="hotels.php?<? echo $Client_num; // Passes Variables in URL?>">
<img border="0" src="images/hotelsbutton%20copy.jpg" width="113" height="60"></a></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="48">
<a href="carrentals.php?<? echo $Client_num; // Passes Variables in URL?>">
<img border="0" src="images/carrentalbutton%20copy.jpg" width="113" height="60"></a></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="47">
<a href="bus.php?<? echo $Client_num; // Passes Variables in URL?>">
<img border="0" src="images/busbutton%20copy.jpg" width="113" height="65"></a></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="48">
<a href="trains.php?<? echo $Client_num; // Passes Variables in URL?>">
<img border="0" src="images/trainsbutton.jpg" width="113" height="57"></a></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="2" WIDTH="113" HEIGHT="49">
<img border="0" src="images/infobutton%20copy.jpg" width="113" height="51"></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="2" WIDTH="113" HEIGHT="54">
<img border="0" src="images/side2.jpg" width="113" height="83"></TD>
</TR>
<TR>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="113" HEIGHT="80">
<img border="0" src="images/sidebottom.jpg" width="113" height="80"></TD>
<TD ROWSPAN="1" COLSPAN="1" WIDTH="516" HEIGHT="80">
<img border="0" src="images/bottommid.jpg" width="516" height="80"></TD>
</TR>
</TABLE>
</BODY>
</form>
</HTML>
or die(mysql_error());after every mysql statement and examine the messages. Go have a closer look at the UPDATE and DELETE statement syntax at the mySQL documentation [dev.mysql.com]
Regards
Markus
<?php
include("dbinfo.inc.php");
$db = mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die(mysql_error());
if($_POST['add_x']) // Test the button chosen
{ // _x is used because the coordinates of the pic are needed
// Post the vairables
$FIRST_NAME = $_POST['FIRST_NAME'];
$LAST_NAME = $_POST['LAST_NAME'];
$Address = $_POST['Address'];
$City = $_POST['City'];
$State = $_POST['State'];
$Zip = $_POST['Zip'];
$PHONE_NUM = $_POST['PHONE_NUM'];
$EMAIL = $_POST['EMAIL'];
$Membership = $_POST['Membership'];
$air_pref_1 = $_POST['air_pref_1'];
$air_pref_2 = $_POST['air_pref_2'];
$air_pref_3 = $_POST['air_pref_3'];
$hotel_pref_1 = $_POST['hotel_pref_1'];
$hotel_pref_2 = $_POST['hotel_pref_2'];
$hotel_pref_3 = $_POST['hotel_pref_3'];
$car_pref_1 = $_POST['car_pref_1'];
$car_pref_2 = $_POST['car_pref_2'];
$car_pref_3 = $_POST['car_pref_3'];
$Client_num = $_POST['Client_num'];
$query = "INSERT INTO clients VALUES ('$FIRST_NAME','$LAST_NAME','$Address','$City',
'$State','$Zip','$PHONE_NUM','$EMAIL','$Membership','$air_pref_1','$air_pref_2',
'$air_pref_3','$hotel_pref_1','$hotel_pref_2','$hotel_pref_3','$car_pref_1',
'$car_pref_2','$car_pref_3', NULL)"; // Add values to database
mysql_query($query, $db) or die(mysql_error());
echo "Record Added";
mysql_close(); // Close the Database
}