trq Posted October 11, 2011 Share Posted October 11, 2011 The value is not showing! Why! This is exactly why i told you several replies ago not to simply assume your code works. The syntax for a select query should be.... if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $result contains a valid resource object containing data } else { // no records found matching your query. Handle the error } } else { // your query failed. handle the error } Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278202 Share on other sites More sharing options...
trq Posted October 11, 2011 Share Posted October 11, 2011 Full source: Not relevant or helpful. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278203 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 11, 2011 Author Share Posted October 11, 2011 This is exactly why i told you several replies ago not to simply assume your code works. I thought you meant the rest of the code - not related to this thread. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278204 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 11, 2011 Author Share Posted October 11, 2011 The value is not showing! Why! This is exactly why i told you several replies ago not to simply assume your code works. The syntax for a select query should be.... if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $result contains a valid resource object containing data } else { // no records found matching your query. Handle the error } } else { // your query failed. handle the error } Wheres this suppose to go? Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278206 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 11, 2011 Author Share Posted October 11, 2011 My source is trashed from all the effing about on this forum. I'm leaving this website for a bit, restoring the file from backup, and then rebooting this thread. We've gone too deep. Wiping out this thread as though it never existed would be a good thing. im also gonna f off this facebook bull shit. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278207 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 11, 2011 Author Share Posted October 11, 2011 If you've started reading from the beginning of this thread, then you have probably got lost in what its actually about, so I will refresh: I am wanting to make it so if a client tries to submit a value in a HTML INPUT form that is higher than a specific value, then JavaScript will deny the form being submitted and return a message to the client. The value of which the number cannot go over will be variable and be pulled from a MySQL table. I am thinking the JavaScript and HTML portion of the code being something along the lines of this: JavaScript: function validateForm() { if (document.forms["form"]["quantity"].value > <?php $row['quantity'] ?>) { alert ("Cannot submit because quantity exceeds availability."); return false; } } HTML: <INPUT name="quantity" onsubmit="return validateForm()"> So if you've got any ideas on how it can be achieved, then I would love to hear them. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278266 Share on other sites More sharing options...
KevinM1 Posted October 11, 2011 Share Posted October 11, 2011 In your JavaScript, echo $row['quantity']. In your HTML, attach your onsubmit event to the form tag itself, not the input. Remember, you're submitting an entire form, thus the submit event fires on the form. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278272 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 12, 2011 Author Share Posted October 12, 2011 In your JavaScript, echo $row['quantity']. It comes out as blank, and when I use the same code after PHP calls MySQL, it works.. so, I placed the code where PHP calls MySQL before the JavaScript, then the PHP in the HTML stopped working. Whats the go with that?! In your HTML, attach your onsubmit event to the form tag itself, not the input. Already done. The JavaScript code now sits at this in the bold: if (document.forms["form"]["size"].value=="Small") { if (document.forms["form"]["quantity"].value > <?php $row['sizes'] ?>) { alert ("Cannot submit because the quantity exceeds availability."); return false; } } Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278459 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 12, 2011 Author Share Posted October 12, 2011 I have placed the PHP-MySQL call code at every point before the JavaScript and it does not work, yet the PHP code <?php $row['sizes'] ?> continues to work when embedded in HTML. This tells me the PHP code has been implemented wrongly in JavaScript. Perhaps I need to brake out of JavaScript? Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278460 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 12, 2011 Author Share Posted October 12, 2011 I have found one problem - the function validateForm() isn't even working. I'll look into this now and report back my finding. EDIT: The form is only not working because <?php $row['sizes'] ?> is producing nothing. When I replace <?php $row['sizes'] ?> with "3", the whole page works! So, the error lays in getting <?php $row['sizes'] ?> outputting. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278463 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 12, 2011 Author Share Posted October 12, 2011 I solved it with a bit of help from Nightslyr and Old Pedant from codingforums.com. I was told I had to use the PHP-MySQL code before the JavaScript, as $row was undefined. I then found a couple of other problems myself where $id was not defined (which is the reason why PHP in the HTML stopped working earlier) and double quotes were not used around the PHP code in the JavaScript. The page now fully works! This problem is solved. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278467 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 12, 2011 Author Share Posted October 12, 2011 Oh dear! I've spoken way too soon! The code isn't working properly yet. It only worked because I inserted double quotes around the PHP: if (document.forms["form"]["quantity"].value > "<?php $row['sizes'] ?>") ... but the PHP code still fails to produce the number as can be seen in the source code: if (document.forms["form"]["quantity"].value > "") I can confirm however that MySQL is working, as everything else that uses PHP-MySQL works. So, I think this is an issue with the way "<?php $row['sizes'] ?>" is being implemented. I can still say solved though because the JavaScript part has been fixed. Quote Link to comment https://forums.phpfreaks.com/topic/248782-if-client-submits-value-higher-than-x-then-return-false/page/2/#findComment-1278471 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.