- I am trying to have data submitted by a form checked against my database. If a record exists based upon name and email, then an update happens. If no record is there the data is entered.
I need to know how to identify the CustomerId number already in existence in the table for the UPDATE query.
- Next the second part of the informatiion gets put into a second table calling upon the lastId generated to put in the second field as a cross-reference. Will this code work for what has transpired before it?
I'm a little confused by it right now so any help to get this working would be greatly appreciated.
mysql_query("select * from customers where Email='$Email' and FirstName='$FirstName'");
if (mysql_num_results == 0) // then not already there
$query = "INSERT INTO customers VALUES ('NULL','$FirstName','$LastName','$PartnerName','$Number','$Mobile',
'$Fax','$Email','$Gender','$Age','$Bought_Cd','$CustRemarks','$CoName','$CustAddress','$CustCity','$CustState','$CustZip',
'$CustCountry','$Newsletter','$ClientVname','$ClientContact','$ClientAddress','$ClientCity','$ClientCountry','$ClientPhone'
,'$ClientFax','$Clientmobile','$ClientEmail','$ClientRemarks','$mysqlDate')";
$result = mysql_query($query);
else
$query = "UPDATE customers SET FirstName='$FirstName',LastName='$LastName',PartnerNames='$PartnerNames',Number='$Number'
,Mobile='$Mobile',Fax='$Fax',Email='$Email',Gender='$Gender',Age='$Age',Bought_Cd='$Bought_Cd',CustRemarks='$CustRemarks'
,CoName='$CoName',CustAddress='$CustAddress',CustCity='$CustCity',CustState='$CustState',CustZip='$CustZip',CustCountry='$CustCountry'
,Newsletter='$Newsletter',ClientVname='$ClientVname',ClientContact='$ClientContact',ClientAddress='$ClientAddress'
,ClientCity='$ClientCity',ClientCountry='$ClientCountry',ClientPhone='$ClientPhone'
,ClientFax='$ClientFax',Clientmobile='$Clientmobile',ClientEmail='$ClientEmail',ClientRemarks='$ClientRemarks'
,mysqlDate='$mysqlDate'WHERE CustomerId=$lastId";
//not sure about this:
$bookingId = mysql_result /// get the id result from the prev query
$lastId = mysql_insert_id($databaseLink)
or die("Invalid query: " . mysql_error());
$gigDate = "$ShowYear-$ShowMonth-$ShowDate";
$query = "INSERT INTO booking VALUES ('NULL','$lastId','$Vname','$Vaddress','$Vcity','$Vphone',
'$Bookas','$gigDate','$ShowDay','$ShowMonth','$ShowDate','$ShowYear','$ShowLength','$SoundCheck','$ShowTime','$CheckTime','$MultipleShow',
'$EventType',
'$Environment','$Capacity','$TicketPrice','$OpenPublic','$OtherDescription','$Guarantee','$BuyerProvide','$ArtistProvide'
,'$PaysTechnician','$Accommodations',NOW(),'')";
$queryresult = mysql_query($query, $databaseLink);
$bookingId = mysql_insert_id();
printf("$FirstName your unique booking id number is:%d\n", $bookingId);