Jump to content

Single Quote/Double Quote issues


Iconate

Recommended Posts

Ive been trying to make a simple function call through a button, and to make sure its working properly, I want to display an alert, but I have been having difficulty thus far;

 

function dataInsert()
{
echo "alert('TEST')";
}



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 - ";
	echo '<input type=button name="book" value="  BOOK NOW   " onClick="dataInsert()"/>';             //This is supposed to call the function, and display the alert message
	echo "</td>";
}
if (mysql_num_rows($result) != 0)
{
	mysql_data_seek($result,0);
}
}

 

To be honest, Im not sure if I am supposed to be echoing the alert or not, as well whether or not im supposed to be using single quotes or double quotes. I have messed around with both, and no luck. Any help and additional knowledge would be great

Link to comment
Share on other sites

Lol.

 

There's an extremely distinct difference between JavaScript and PHP (that which doesn't allow you to mix them).

 

Try this:

 

<script type="text/javascript">
function dataInsert()
{
alert('TEST');
}
</script>

<?php

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 - ";
	echo '<input type=button name="book" value="  BOOK NOW   " onClick="javascript:dataInsert()"/>';             //This is supposed to call the function, and display the alert message
	echo "</td>";
}
if (mysql_num_rows($result) != 0)
{
	mysql_data_seek($result,0);
}
}

?>

Link to comment
Share on other sites

Hmm tried that, now my table doesn't render. But I am planning to use MySQL in the function, so I am staying away from javascript in this file

 

However what you said makes sense, and I guess alert() is a javascript function, Im just looking for a way to indicate to me that the function is being called

Link to comment
Share on other sites

so I am staying away from javascript in this file

 

Well, clearly, you're not. You're use of the "onClick" attribute of input "book" clearly indicates that you're trying very much so to incorporate JavaScript in this file.

Link to comment
Share on other sites

Ok well I still need to have a PHP function called in a button form. I looked around on the net, and many examples were posed like the following

 

You can however do this...

 

<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();

}

?>

 

However I have trouble understanding how I can incorporate this into my file. Would it look something like this?

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$q=$_GET["q"];

$con = mysql_connect('----', '----', '----');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("----", $con);

$a = $q[0];    
$q = substr($q, 1, 11);

$sql="SELECT * FROM dates WHERE arena = '".$a."' AND date LIKE '%".$q."%'";

$result = mysql_query($sql) 
or die(mysql_error());

$weekday = date('l', strtotime($q)); 

function dataInsert()                   //Function I wanna call
{ 
//MySQL stuff
}

if(isset($_POST['book']))
{
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">          //This button is still created 
	<input type="button" 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>";

...

echo "</table>";


mysql_close($con);
?> 

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.