The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Empty Form Field Validation? Reply To: Empty Form Field Validation?


The validation part of your code works but there are a couple of issues. I have id as a PK. How do I pass a non value, bypass (I don’t know the correct term) this field so the script doesn’t generate an error?

Simply by omitting the column name from the query. If you notice, the query I wrote specifies each column name it uses: the id is not included, so it won’t be passed a value.

This will only cause an error if the field has no default value. If your PK is an auto_increment field, then this won’t be a problem.

I cannot login as usernames and passwords are no longer recognised, due to this statement in my authenticate script?

$Link = mysql_connect($Host, $User, $Password);

Connecting to PDO will not be affected, in any way, by any mysql_* functions you call. If you are unable to connect, then the problem lies elsewhere. Did you edit the database credentials for the get_PDO_connection function?

  • $DB_host: The name of your database host. Likely the same (though I cannot guarantee it) as $Host in your current script.
  • $DB_name: The name of the database to use. Likely the same as $DBname.
  • $DB_user: The database username. Likely the same as $User.
  • $DB_pass: The database password. Likely the same as $Pass.

I wanted to get everything working before re-writing my code, which is one of the reasons I have been using older methods for validation.

I understand. If you still wish to do so, that’s okay. I can only recommend that you read the manual entries very closely, since there are situations where choosing one function over the other —such as using mysql_escape_string instead of mysql_real_escape_string— will create serious problems. In cases like this, I cannot help you learn how to use them correctly, because there is no “correct way” to use them.

As I said, use mysql_real_escape_string (not mysql_escape_string) and mysql_select_db + mysql_query (not mysql_db_query); otherwise, there’s nothing particularly wrong with your db code. Feel free to remove the PDO stuff and use your old code if you wish. It can go in the same spot.

If you still get an error, please describe it.

If you need a reference for the old mysql_* functions, use the PHP manual (and read all the warnings carefully). Except for using die to handle errors, this ext/mysql tutorial is fairly decent.