dongqie4233 2015-10-22 17:53
浏览 59

调用php函数

Can anyone tell me what is the problem with the following code? I have chosen a date through JQuery Datepicker. It gets passed in the url onSubmit. I have to check if this date is equal to any of the dates from the database (for which I have used the mysql_fetch_array($getDates_query). Also, I have used localStorage to store the datepicker date. Can I pass this value into a php variable and then check it? If possible, how? Thanks.

Here is my code. To select a date:

<script>
$(document).ready(function () {
$("#datepicker").datepicker({
   dateFormat: "dd-mm-yy"   
});
$('form#dateform').submit(function(){   
var aselectedDate = $('#datepicker').val();

localStorage.setItem('adate', aselectedDate);
});
});
</script>

Connecting to the database:

mysql_select_db("trainingschedule",$con);
$sql="SELECT * FROM events_schedule";
$myData=mysql_query($sql,$con);
echo "<form id=\"dateform\" name=\"dateform\" action=\"#\" method=\"POST\ onSubmit=\"function1()\"><br><br>

<table>

<tr><td>
<b>Select a date &nbsp;&nbsp;<b></td><td><input id=\"datepicker\" name=\"date\" size=\"15\"/></td></tr>

</table>
<br>
<input type=\"submit\" name=\"submit\" value=\"Submit\"/>&nbsp;&nbsp;&nbsp;&nbsp;
</form>";

The php function to check whether the selected date is matching any date from the date base is:

function function1()
{
$sql1="SELECT event_date from events_schedule";
$getDates_query= mysql_query($sql1,$con);

$adateStringValue = $_GET['dateform'];

while($fetchdates = mysql_fetch_array($getDates_query)) {
if ($fetchdates['event_date'] == $adateStringValue) {

$message = "You have selected this date";
echo "<script type='text/javascript'>alert('$message');</script>";
}
else {
$message1 = "Selected this date";
echo "<script type='text/javascript'>alert('$message1');</script>";
}

}
}

The problem here is that the function1() isn't getting called onSubmit. How can I rectify this problem?

  • 写回答

0条回答 默认 最新

    报告相同问题?