Jump to content

Adding info to 2 different databased from 1 php script


ifis

Recommended Posts

I have a form the needs to search one database to set information for the output that I want, but then I want to write the result of that into the users database.  Here is what I have:

  <?php


//get data
$make=$_POST['make'];
$lic = $_POST['lic'];
$student=$_POST['student'];
$sex = $_POST['sex'];
$CFI=$_POST['CFI'];
$expireip=$_POST['expireip'];
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$limitations=$_POST['limitations'];
$departure=$_POST['departure'];
$destination=$_POST['destination'];
$route=$_POST['route'];
$airport=$_POST['airport'];
$airspace=$_POST['airspace'];
$landingair=$_POST['landingair'];
$seldate=$_POST['seldate'];
$pilotcertificate=$_POST['pilotcertificate'];
$pilotnumber=$_POST['pilotnumber'];

include("endorsement.inc");

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

//Convert male/female to he/she
if ($sex == 'Male'){
$preposition= he;
}
If ($sex == 'Female'){
$preposition= she;
}

$sql = "SELECT * FROM Endorsements WHERE lic='$lic'";
$result=mysql_query($sql);

//get the first entry from the result
$row = mysql_fetch_array($result);

$find = array("\$student","\$make","\$preposition","\$firstName","\$lastName","\$CFI","expire","limitations","departure","destination","\$route","\$airport","landingair","\$airspace","seldate","pilotcertificate","pilotnumber");
$replace = array($student,$make,$preposition,$firstName,$lastName,$CFI,$expireip,$limitations,$departure,$destination,$route,$airport,$landingair,$airspace,$seldate,$pilotcertificate,$pilotnumber);

$end =str_replace($find,$replace,$row['end']);
$end1 =str_replace($find,$replace,$row['end1']);
$end2 =str_replace($find,$replace,$row['end2']);
echo "$end</br>";
echo "$end1</br>";
echo "$end2</br>";

mysql_close();

include("endorsementlog.inc");

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$today=date("Y/m/d");

mysql_query("INSERT INTO Endorsementlog (end, end1, end2) VALUES ('$end','$end1','$end2') WHERE Student='$student' and Date='$today' and Endorsement='$lic'") or die("cannot inset into Endorsementlog table");

mysql_close();
?>

  I get the die message from the INSERT INTO query.  Any ideas?

that helped.  It said I have a syntax problem with my WHERE. 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE Student='georgy' and Date='2008/02/25' and Endorsement='Pre-Solo Aeronauti' at line 1

 

Now that I actually looked at the SQL, I don't think you can have WHERE's in an INSERT SQL

 

Are you possably trying to UPDATE? tables

 

Or create a new table

 

if your trying to UPDATE

 

"UPDATE Endorsementlog SET (end, end1, end2) VALUES ('$end','$end1','$end2') WHERE Student='$student' and Date='$today' and Endorsement='$lic'"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.