Jump to content

PHP button function call issues


Iconate

Recommended Posts

I have read into it, and in order to have a proper function call from a button, you need to have something of this format

 

<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">

<input type="button" name="submit" value="Submit">

</form>

 

then have php at the top of your page

 

<?php

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

foo();

}?>

 

The only problem is, in my code, I have to cut my function short to insert the button I want. I do not know if thats the issue, but my function is not being called.

My MySQL statement works, no issue there.

 

<?php  

//all php code above, DB connections etc...

function dataInsert()          //Function trying to be called
{
mysql_query("INSERT INTO b18_3420450_cal.dates (event_id, arena, date, end_date)
VALUES ('6', '1', '2009-05-05 11:00:00', '2009-05-05 12:00:00')")
	or die(mysql_error());	
}

if(isset($_POST['book']))           // calling dataInsert if book is submitted
{
dataInsert();
}

function timeCompare($tabletime)
{


global $result;
global $q;
$available = true;

while ($row = mysql_fetch_array($result))
    {
	$qtime = substr($row['date'], 11, 16);
	if ($tabletime == $qtime)
	{
		echo "<td>TAKEN</td>";
		$available = false;
		break;
	}
    }
if ($available)
{

	echo "<td>";
	echo "AVAILABLE - ";                
	?>
	<form action="<?=$_SERVER['php_SELF'];?>" method="post">
	<input type="submit" name="book" value="   Book Now   ">
	</form>
	<?php 
	echo "</td>";
}


if (mysql_num_rows($result) != 0)
{
	mysql_data_seek($result,0);
}
}

echo "<table border='1'>";

echo "<tr>";
echo "<th>Time</th>";
echo "<th>Availablility for ". $weekday .", ". $q ."</th>";
echo "</tr>";

echo "<tr>";
echo "<td>08:00</td>";
timeCompare("08:00:00");
echo "<tr>";
...

 

Is what I did legal? Is there a way around it if its not? Because I need the timeCompare function to determine the Availability of the indicated time, if available a user could click the button to sign up for that time

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.