Database ---> insert date doesn t work :/

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Database ---> insert date doesn t work :/

Post by Draco_03 »

Hi..

This works really good

Code: Select all

<?php
$connect = odbc_connect("tech_support", "kader", "edh") or die("Connection failed");
$query = "SELECT key FROM Clients";
$queryexe = odbc_do($connect, $query);
while(odbc_fetch_row($queryexe)) 
    { 
    $varkey = odbc_result($queryexe, 1);
	}
$date = $_POST["days"]."-".$_POST["months"]."-".$_POST["years"]; 
$nom = $_POST["nom"]; 
$centre = $_POST["centre"];
$phone = "(".$_POST["indicatif"].")"." ".$_POST["phone1"]."-".$_POST["phone2"];
$person = $_POST["person"];
$serial = $_POST["serial1"]." ".$_POST["serial2"]." ".$_POST["serial3"];
$machine = $_POST["machine"];
$ftp = $_POST["ftp"];
$fta = $_POST["fta"];
$tp = $_POST["tp"];
$key1 = $_POST["key1"];
$key2 = $_POST["key2"];
$key3 = $_POST["key3"];
$garantie = $_POST["garantie"];
$problem = $_POST["problem"];
$var = $varkey;
if ($var == "NULL") {
$var == 1;
}else{
$var++;
}
echo ("<tr align='center' class='textegris'>");
//echo ("<td>$date</td>");
echo ("<td>$centre</td>");
echo ("<td>$nom</td>");
echo ("<td>$phone</td>");
echo ("<td>$person</td>");
echo ("<td>$machine</td>");
echo ("<td>$garantie</td>");
echo ("<td>$var</td>");
echo ("</tr>");
odbc_close($connect);
$connect = odbc_connect("tech_support", "kader", "edh") or die("Connection failed");
$query = "INSERT INTO Clients ( centre, nom, phone, Derniere, machine, garantie, key) VALUES ( '$centre', '$nom', '$phone', '$person', '$machine', '$garantie', '$var')";
$queryexe = odbc_do($connect, $query);
odbc_close($connect);
?>
but when i try to add the date (wich on my form page is automatically filled) it s just doesn t work
so if i change my previous query by this

Code: Select all

<?php
$query = "INSERT INTO Clients ( date, centre, nom, phone, Derniere, machine, garantie, key) VALUES ( '$date', '$centre', '$nom', '$phone', '$person', '$machine', '$garantie', '$var')";
?>
i got an error :
SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect...

btw my date goes like this

Code: Select all

&lt;input name="days" type="text" class="date" maxlength="2" value="&lt;?=date("d")?&gt;" /&gt;
/ 
&lt;input name="months" type="text" class="date" maxlength="2" value="&lt;?=date("m")?&gt;" /&gt;
/ 
&lt;input name="years" type="text" class="date" maxlength="2" value="&lt;?=date("y")?&gt;" /&gt;
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

How is that field formatted in the database? Is it set up to accept a date the way you have it formatted dd-mm-yyyy? Trying doing a straight insert to confirm.

Also you might want to think about changing this

Code: Select all

<?php
$date = $_POST["days"]."-".$_POST["months"]."-".$_POST["years"];
?>
to this

Code: Select all

<?php
$date = $_POST['days']."-".$_POST['months']."-".$_POST['years'];
?>
Not sure if the " to ' really matter but I think I remember reading that somewhere before. Personally I always use a ' and have never had a problem.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

Yeah well i use access database and i did use the dd-mm-yy but it didn t work ..
so i tried to associate text field to my date instead to have it in a date format .. but doens t work..
it s still says my insert have an error.. i don t know why ....
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

OMG since it would output even in a text box i guessed maybe the name date was not okay for some reason.. i changed oit for thedate (my fieldname) and just by changing that well it worked perfectly...

weird..

But thx a lot man :D
Post Reply