Jump to content

Recommended Posts

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
}

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?

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.

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.

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;

}

}

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?

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.

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.

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.

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.