Jump to content

Archived

This topic is now archived and is closed to further replies.

tjverge

Variable not passing from form

Recommended Posts

<head>
<script language="javascript" type="text/javascript" src="datetimepicker.js">
</script>
</head>
<form action="main.php?id=test.php" method="post">
  <p>Start Date:
  <input name="start" id="start" type="text" size="10">
  <a href="javascript:NewCal('start','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
    End Date: <input name="end" id="end" type="text" size="10">
  <a href="javascript:NewCal('end','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
  <input name="submit" type="submit" value="Look Up">
</form>
<?php
if(isset($_POST['submit']))
{
$start = $_POST['start'];
$end = $_POST['end'];	
$sql = "SELECT * FROM `corps` WHERE `notedate` BETWEEN '$start' AND '$end'";

$results = mysql_query($sql) OR DIE(mysql_error());
$numrow = mysql_num_rows($results) ;
$i = 0;
While ($i < $numrow)
$shownotes = mysql_result($results,$i,'notes');
echo $shownotes."<br>";
{
Echo "Records found ".$i."<br>";
$i++;
}
}

 

The $start, and $end don't seem to be getting any values

Share this post


Link to post
Share on other sites

Add the 3 indicated lines, and see what exactly is in the post array. If they aren't there, disable javascript in your browser, enter something in the text fields and try it again.

 

if(isset($_POST['submit']))
{

echo '<pre>'; // <----- ADD
print_r($_POST); // <----- ADD
echo '</pre>'; // <----- ADD

$start = $_POST['start'];
$end = $_POST['end'];
$sql = "SELECT * FROM `corps` WHERE `notedate` BETWEEN '$start' AND '$end'"

Share this post


Link to post
Share on other sites

Array

(

    [start] => 1-2-2011

    [end] => 5-2-2011

    [submit] => Look Up

)

 

 

Fatal error: Maximum execution time of 30 seconds exceeded in /home5/ccccomma/public_html/test.php on line 29

Share this post


Link to post
Share on other sites

Array

(

    [start] => 1-2-2011

    [end] => 5-2-2011

    [submit] => Look Up

)

 

 

Fatal error: Maximum execution time of 30 seconds exceeded in /home5/ccccomma/public_html/test.php on line 29

 

Line 29 is: $shownotes = mysql_result($results,$i,'notes');

Share this post


Link to post
Share on other sites

Ok got rid of the error but back to my first problem noting is showing up on the page

 

<head>
<script language="javascript" type="text/javascript" src="datetimepicker.js">
</script>
</head>
<form action="main.php?id=test.php" method="post">
  <p>Start Date:
  <input name="start" id="start" type="text" size="10">
  <a href="javascript:NewCal('start','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
    End Date: <input name="end" id="end" type="text" size="10">
  <a href="javascript:NewCal('end','ddmmyyyy')"><img src="cal.gif" width="16" height="16" border="0" alt="Pick a date"></a>
  <input name="submit" type="submit" value="Look Up">
</form>
<?php
if(isset($_POST['submit']))
{

echo '<pre>'; // <----- ADD
print_r($_POST); // <----- ADD
echo '</pre>'; // <----- ADD	

$start = $_POST['start'];
$end = $_POST['end'];	
$sql = "SELECT * FROM `corps` WHERE `notedate` BETWEEN '$start' AND '$end'";

$results = mysql_query($sql) OR DIE(mysql_error());
$numrow = mysql_num_rows($results) ;
$i = 0;
While ($i < $numrow)
{
$shownotes = mysql_result($results,$i,"notes");
echo $shownotes."<br>";

$i++;
}
}

?>

 

 

Share this post


Link to post
Share on other sites

What do you mean nothing is showing up? Blank screen, or just not the data you expected?

Share this post


Link to post
Share on other sites

well besides the

Array
(
    [start] => 1-2-2011
    [end] => 5-2-2011
    [submit] => Look Up
)

 

there are no records showing up, there are records that would match in the database table

Share this post


Link to post
Share on other sites

I may have an idea what the problem is the entered date format is DDMMYYYY, where as the mysql format is YYYYMMDD, I'm not sure how to convert it to match.

Share this post


Link to post
Share on other sites

Ah, then you should change the format the date picker sends it over in the $_POST array. Change ddmmyyyy to yyyymmdd and that should do it, if it's the same date picker I've used in the past.

Share this post


Link to post
Share on other sites

Ah, then you should change the format the date picker sends it over in the $_POST array. Change ddmmyyyy to yyyymmdd and that should do it, if it's the same date picker I've used in the past.

I tried that I get "undefined" instead of a date

Share this post


Link to post
Share on other sites

Problem solved I added a new function to the JavaScript file and it works now thank you all

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.