Jump to content

Highest Reputation Content

#20304 Php/mysql Error Message?

Posted by Emilie on 20 August 2014 - 6:55 AM



Another typo:


The closing quotation mark is missing.


Also, if your ID is numeric, you should not quote it:

where (ID='23')


If this doesn't do the trick, I would suggest testing a few lines only at a time, until you find where the query goes wrong.


I hope this helps,



  • 3

#20294 Php/mysql Error Message?

Posted by Emilie on 19 August 2014 - 7:53 AM



MySQL doesn't 'know' the variables you created with PHP. In order to test your query, you need to replace the variables with their values.


I hope this helps,



  • 3

#20055 I'm Having Trouble With Sorting Query Results In Chapter 5... Plz Help!

Posted by Emilie on 30 July 2014 - 1:07 PM



What is "wrong", according to you?


The registration date is the same for all users because you entered all of them at one go into the database, and therefore the timestamp corresponding to NOW() is the same for everyone. Because of that, ordering the results by registration_date DESC has no real meaning.


I hope this helps,



  • 3

#15289 Use Data Type Enum For Form Drop-Down Options

Posted by margaux on 2 July 2013 - 5:02 PM

Glad I could provide a little help. When I'm struggling with some code, I use var_dump and print_r to see what is being returned. Then I know how to manipulate the data.

  • 3

#15287 Use Data Type Enum For Form Drop-Down Options

Posted by margaux on 2 July 2013 - 3:10 PM

You're close. You have not stored your result anywhere with mysqli_fetch_array, so you won't be able to access the returned data.

$table_name = "collection";
$column_name = "PENDING";

echo "<select name=\"$column_name\"><option>Select one</option>";
    WHERE TABLE_NAME = '$table_name' AND COLUMN_NAME = '$column_name'";
$r = mysqli_query($dbc, $q);

$row = mysqli_fetch_array($r);

$enumList = explode(",", str_replace("'", "", substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE'])-6))));
foreach($enumList as $value)
    echo "<option value=\"$value\">$value</option>";

echo "</select>";

  • 3

#13394 Pls Help Need Urgent Help. The .Inc Extension. Chapter 11

Posted by margaux on 11 March 2013 - 4:45 AM

It's difficult to debug when the code is presented in this way. Please would you use code tags.


At first look, no error immediately jumps out. Which line is line 46? Look at that line and the few lines before it.


Probably not causing this error but it looks like you may have a typo on the tablename in the SELECT statement - users instead of usera?

  • 3

#13112 Forms In Javascript Or Php?

Posted by HartleySan on 19 February 2013 - 10:38 AM

Awesomo, to give you a concrete example, I'm going to use Jonathon's example above because I think it's a good example.
First off, you'll want to attach a JS event handler to the form so that when the form is submitted, JS intercepts the form submission and allows you to do whatever you need to before the form is actually submitted.
This can be accomplished as follows:
document.forms[0].onsubmit = function () {
  return false;
On any HTML page that contains at least one form, JS provides you with the forms array, which is a property of the document object. forms[0] always applies to the first form on the page. You can adjust the array index as need be.
The return false statement actually stops the form from being submitted. (Don't worry though, as we'll actually force the form to be submitted in a second, assuming everything is okay.)
Next, let's imagine that we have a user name text input that must be only letters and numbers, as Jonathon said. Here's a simple JS regex we can write to test for that:
document.forms[0].onsubmit = function () {
  if (/^[A-Za-z0-9]+$/.test(this.elements[0].value)) {
  return false;
The above if statement tests that the user name text input contains only letters (either uppercase or lowercase) and numbers (and is not an empty string). I should note that I make several assumptions with this code:
The user name text input is the first input in the form. This can be seen by the this.elements[0] in the if statement. In this case, this refers to the form object we're interested in, and elements is an array attached to all JS form objects that allows you to access all the inputs items in the form. Naturally, elements[0] refers to the first element in the form. If you'd rather check the user name text input by ID (assuming the ID is "username"), you can replace this.elements[0] with document.getElementById('username'). The value property at the end will give you the actual string entered into the text input object.
If the above if statement evaluates to true, then we can assume that the user name does in fact only contain letters and numbers. That being the case, we should then submit the form normally.
However, if the if statement returns false, then we should change the border of the user name text input to red.
The following code will do just that:
document.forms[0].onsubmit = function () {
  if (/^[A-Za-z0-9]+$/.test(this.elements[0].value)) {
  } else {
    this.elements[0].style.border = '#F00 solid 2px';
  return false;
As before, this refers to the form object in question. this.submit() will actually submit the form as if JS never intercepted the form submit request in the first place.
If the if statement fails, then we use this.elements[0] (or document.getElementById('username'), if you want) to reference the user name text input object, and then change the border to a 2-pixel red border.
That's the basic concept to simple JS form validation built on top of standard PHP form validation.
One of the keys to this method is that you only submit the form when everything is okay.
And naturally, the concepts above can be rinsed and repeated as many times as necessary to validate all your form input.
I hope that helps.

  • 3

#11560 Simple Question On Php Form Validation...

Posted by HartleySan on 8 December 2012 - 12:32 AM

When you execute the header(Location: 'somelocation.php#contact'); line, you're reloading the page, which causes the $_POST array, $errors variable, etc. to no longer exist. This essentially amounts to the same thing as having never performed any validation at all (and thus the $errors variable not existing, which is why your "Please fix the errors" line is never printed out).

A better solution would be to put the anchor jump (i.e., the fragment part in the URL after the number sign (#)) in the URL specified for the action attribute of the contact form. For example, if the following is the opening tag for your contact form:

<form action="somelocation.php" method="post">

Then change it to the following:

<form action="somelocation.php#contact" method="post">

Of course, this assumes that somelocation.php refers to the original page the form is on (which seems to be the case according to what you said).
By doing the above, you can very easily get the jump you want and still properly validate everything.

In terms of outputting a thank you message upon successful validation, I'd do something like the following:

if (!$errors) {

  // Validation was successful. Output a thank you message.

} else {

  // Either there was an error or this is the first time the page was loaded.
  // Load the page with the form and any necessary sticky values and error messages.


Hope that helps.
  • 3

#14402 Really Disturbing

Posted by margaux on 1 May 2013 - 4:56 PM

Hey xto, I'm going to try to say this in the nicest way possible -  You're in danger of trying people's patience not because you ask questions, we like questions, but because you ask questions in a way that doesn't provide the information needed to try to answer them.


1. please read the forum guidelines - Look for the little grey text bottom right of most pages, labelled Guidelines

2. please post only RELEVANT code and error messages within code tags. We don't need to see the entire output from your error message. It's actually distracting. Use code tags which are on the edit bar and they look like <>

3. post the relevant CODE, you keep posting the error message but not any code.

4. You should start a new thread for each new question. One reason for doing so is that other people with the same question can search and find your thread. If your question is part of another thread, it won't be found and won't help others.

5. You're asking questions that you should be able to solve 1 because the level of  experience for this book expects you know some basic debugging strategies and 2. with a little bit of online searching you would get some pointers as to where to look for the cause of your error.


I really shouldn't answer your question given the above but ...


somewhere in your code you are referencing an array value using 'sale_price' as the index, which doesn't exist. I'm going to hazard a guess that you have a line that includes $row['sale_price']. From the error dump you posted, you will see there is no index 'sale_price' but there is one named 'price'. Given what info you've provided that's all I can help with. If this doesn't help solve the problem, start a new thread and post the code that is causing the error :)

  • 4