ifis Posted February 26, 2008 Share Posted February 26, 2008 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? Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 Why Don't you change the Die message to give you a little more info die("Cannot inset into Endorsementlog table. MySQL Returned: ".mysql_error()) Quote Link to comment Share on other sites More sharing options...
ifis Posted February 26, 2008 Author Share Posted February 26, 2008 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 Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 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'" Quote Link to comment Share on other sites More sharing options...
ifis Posted February 26, 2008 Author Share Posted February 26, 2008 yeah, your totally right and it kind of makes sense. It works once I changed it. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.