On Fri, Mar 30, 2012 at 1:10 AM, Ethan Rosenberg <ethros@xxxxxxxxxxxxx> wrote: > Sending again, since no response on 1st try. > > Ethan > ================== > Dear List > > I am trying to insert data into a table, with no success. > > I have two tables: > > mysql> describe Visit3; > +--------+--------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | Extra | > +--------+--------------+------+-----+---------+----------------+ > | Indx | int(4) | NO | PRI | NULL | auto_increment | > | Site | varchar(6) | YES | | NULL | | > | MedRec | int(6) | YES | | NULL | | > | Notes | text | YES | | NULL | | > | Weight | int(4) | YES | | NULL | | > | BMI | decimal(3,1) | YES | | NULL | | > | Date | date | YES | | NULL | | > +--------+--------------+------+-----+---------+----------------+ > > +--------+-------------+------+-----+---------+-------+ > | Field | Type | Null | Key | Default | Extra | > +--------+-------------+------+-----+---------+-------+ > | Site | varchar(6) | NO | PRI | | | > | MedRec | int(6) | NO | PRI | NULL | | > | Fname | varchar(15) | YES | | NULL | | > | Lname | varchar(30) | YES | | NULL | | > | Phone | varchar(30) | YES | | NULL | | > | Height | int(4) | YES | | NULL | | > | Sex | char(7) | YES | | NULL | | > | Hx | text | YES | | NULL | | > +--------+-------------+------+-----+---------+-------+ > > I calculate some values: > > default_timezone_set('America/New_York'); > $Date = date('M d Y'); > $sql1 = "select MedRec, Height from Intake3 where (MedRec = > '$_POST[MedRec]')"; > $result = mysqli_query($cxn, $sql1); > $row = mysqli_fetch_array($result); > $MedRec = $row[0]; > $Height = $row[1]; > $Weight = $_POST['Weight']; > $Notes = $_POST['Notes']; > $sql4 = "select MedRec, Weight from Visit3 where (MedRec = > $_POST[MedRec])"; > $result4 = mysqli_query($cxn, $sql4); > $row4 = mysqli_fetch_array($result4); > $MedRec = $_POST['MedRec']; > $BMI = ($Weight*703)/($Height*$Height); > $BMI = round($BMI,1); > $fptr1 = fopen("/home/ethan/PHP/HRecnumSite", "r+"); > fscanf($fptr1,"%d %s",$Num, $Site); > echo "$Site, $MedRec, $Notes, $Weight $BMI, $Date <br />"; > $sql2 = "INSERT INTO Visit3(Indx, Site, MedRec, Notes, Weight, BMI, > Date) VALUES(null, '$Site', '$MedRec', '$Notes', $Weight, $BMI, '$Date'"; > $result2 = mysqli_query($cxn, $sql2); > > They display properly. > > $sql3 = "select max(Indx) from Visit3"; > $result3 = mysqli_query($cxn, $sql3); > var_dump($result3); > echo "result3 "; > print_r($result3); > $row = mysqli_fetch_array($result3); > $Indx = $row[0]; > > echo "<tr>\n"; > > echo "<td> $Indx </td>\n"; > echo "<td> $Site </td>\n"; > echo "<td> $MedRec </td>\n"; > echo "<td> $Notes </td>\n"; > echo "<td> $Weight </td>\n"; > echo "<td> $BMI </td>\n"; > echo "<td> $Date </td>\n"; > > echo "</tr>\n"; > echo "</table>"; > > The date value is not inserted properly into the table: > > mysql> select * from Visit3; > | 2416 | AA | 10001 | uih s45t | 125 | 19.0 | 0000-00-00 | > | 2417 | AA | 10000 | bnkjlolk | 174 | 28.1 | 0000-00-00 | > > Advice and help, please. > > Thanks. > > Ethan Rosenberg > I think MySQL wants the date in YYYY-M-D format, did you try changing $Date = date('M d Y'); to $Date = date('Y-m-d'); - Matijn -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php