Jump to content

[SOLVED] Problems writing to MySQL database


ifis

Recommended Posts

I am trying to save information from a form in an 'Endorsementlog' table.  The only problem is that only the first option of "lic" will write to the database.  All the other options still work and set "lic" to whatever it is supposed to be, but will not write to the table.

echo "<form id='form1' name='form1' method='POST' action='endorsementform.php'>
    <p>
      <input name='firstName' type='hidden' id='firstName' value='$row[firstName]' />
   <input name='lastName' type='hidden' id='lastName' value='$row[lastName]' />
    </p>
    <p>Endorsement:<br />
      <select name='lic' id='lic'>
        <option>Pre-Solo Aeronautical Knowledge</option>
        <option>Pre-Solo Flight Training</option>

<?php
$today=date("Y/m/d");
$make=$_POST['make'];
$lic = $_POST['lic'];
$student=$_POST['student'];
$sex = $_POST['sex'];
$CFI=$_POST['CFI'];
$expireip=$_POST['expireip'];
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];

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");

//write to instructor log
mysql_query("INSERT INTO $tbl_name (Username, Date, Student, Endorsement) VALUES ('{$_SESSION['myusername']}','$today', '$student','$lic')");

What am I doing wrong?

Change it to:

<?php
$today=date("Y/m/d");
$make=$_POST['make'];
$lic = $_POST['lic'];
$student=$_POST['student'];
$sex = $_POST['sex'];
$CFI=$_POST['CFI'];
$expireip=$_POST['expireip'];
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];

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");

//write to instructor log
mysql_query("INSERT INTO $tbl_name (Username, Date, Student, Endorsement) VALUES ('{$_SESSION['myusername']}','$today', '$student','$lic')") or die (mysql_error());

and tell us the error it produces.

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.