Mis-use of STR_TO_DATE

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
algorob
Forum Newbie
Posts: 1
Joined: Wed Oct 13, 2010 1:27 pm

Mis-use of STR_TO_DATE

Post 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)
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Mis-use of STR_TO_DATE

Post 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))
Post Reply