Page 1 of 1

Mis-use of STR_TO_DATE

Posted: Wed Oct 13, 2010 1:38 pm
by algorob
Can someone tell me what I'm doing wrong here:
All is working except the date's if I enter a date eg. 15/02/1947 I get zero values added to the table for both fields. ?????




<body>
<form action="addevent.php" method="post">


<body><table style="width: 100%;">
<tr>
<td class="style1">
Event Start Date*:
</td>
<td>
<input type="text" name="EventStartDate" />
</td>

</tr>
<tr>
<td class="style1">
Event End Date:
</td>
<td>
<input type="text" name="EventEndDate" />
</td>

</tr>
<tr>
<td class="style1">
Event Name*:
</td>
<td>
<input type="text" name="EventName" />
</td>

</tr>
<tr>
<td class="style1">
Event Description*:
</td>
<td>
<input type="comment" cols="50" rows="10" name="EventDesc" />
</td>

</tr>
<tr>
<td class="style1">
Event Location*:
</td>
<td>
<input type="text" name="EventLoc" />
</td>

</tr>
<tr>
<td class="style1">
Poster Location/Name:
</td>
<td>
<input type="text" name="Poster" />
</td>

</tr>
<tr>
<td class="style1">
Flyer Location/Name:
</td>
<td>
<input type="text" name="Flyer" />
</td>
<td>&nbsp;

</td>
</tr>

</table>

<input type="submit" />
</form>

<?php
$con = mysql_connect("myServer","myUser","myPass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("myDB", $con);


$sql="INSERT INTO eventsdiary (EventStartDate, EventEndDate, EventName, EventDesc, EventLoc, Poster, Flyer) VALUES ('$_POST(STR_TO_DATE([EventStartDate], %d/%m/%Y))', '$_POST (STR_TO_DATE([EventEndDate], %d/%m/%Y))', '$_POST[EventName]', '$_POST[EventDesc]', '$_POST[EventLoc]', '$_POST[Poster]', '$_POST[Flyer]')";


if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";

mysql_close($con)
?>

Re: Mis-use of STR_TO_DATE

Posted: Wed Oct 13, 2010 1:50 pm
by John Cartwright
Oh boy, I never knew $_POST array had this kind of functionality! But seriously, you want to pass the input to the MYSQL function.

The problem:

Code: Select all

$_POST(STR_TO_DATE([EventStartDate], %d/%m/%Y))