Iconate Posted May 26, 2009 Share Posted May 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159635-single-quotedouble-quote-issues/ Share on other sites More sharing options...
Masna Posted May 26, 2009 Share Posted May 26, 2009 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); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159635-single-quotedouble-quote-issues/#findComment-842001 Share on other sites More sharing options...
Iconate Posted May 26, 2009 Author Share Posted May 26, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/159635-single-quotedouble-quote-issues/#findComment-842007 Share on other sites More sharing options...
Masna Posted May 26, 2009 Share Posted May 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159635-single-quotedouble-quote-issues/#findComment-842011 Share on other sites More sharing options...
Iconate Posted May 26, 2009 Author Share Posted May 26, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/159635-single-quotedouble-quote-issues/#findComment-842025 Share on other sites More sharing options...
Masna Posted May 26, 2009 Share Posted May 26, 2009 What you did looks fine (and should work). Quote Link to comment https://forums.phpfreaks.com/topic/159635-single-quotedouble-quote-issues/#findComment-842034 Share on other sites More sharing options...
Iconate Posted May 26, 2009 Author Share Posted May 26, 2009 My table is being created which is good, however I know my function isn't being called because I created a mysql_query guaranteed to give me an error, and it does not. Quote Link to comment https://forums.phpfreaks.com/topic/159635-single-quotedouble-quote-issues/#findComment-842040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.