0

Hey all, my first time asking on stackoverflow!

Anyway. So this morning (and most of last night) I have been working on an a project of mine. Its a simple small scale e-commerce site.

Not to bog down with the details of the website, I'll skip straight to it.

Basically, I have my website hosted on a webserver with my own domain. In order to submit the work to my University tutors, I have to transfer the files to their web-server. This can only be accessed when connected to the university network and runs under the path http://jawa/handins/...../

Now in order for the MySQL and PHP to function I have to extract the tables and information from my personal phpmyadmin panel and dump it into the phpmyadmin panel provided on the Uni network. The database is called something alot different but the tables are the same, so a small minute to make sure my mysql_connect functions are pointing to the correct database and everything is working fine. Or at least that is the plan..

For some reason my PHP variables (Which WORK on MY server) are now undefined - How? I havent changed a single piece of code except where the database is and that is it:

//form data
                        $firstName = strip_tags($_POST['firstName']);
                        $lastName = strip_tags($_POST['lastName']);
                        $Email = strip_tags($_POST['Email']);
                        $userName = strip_tags($_POST['userName']);
                        $regPass = strip_tags($_POST['regPass']);
                        $repeatPass = strip_tags($_POST['repeatPass']);
                        $date = date("Y-m-d");
                        $permissions = strip_tags($_POST['permissions']);

Everything matches up with the relevant submit fields. There is nothing different with the code I have running on my personal webserver, and the code hosted on the university network. Yet now these variables you see here are not defined. Forgive me for being stupid if it's obvious, but ive been up for 20hrs straight now and I'm getting really agitated with small problems. However I will not vent my frustration out on anyone, it's not your fault!

Essentially, those variables are used for a registration form. Each sumbit field is given the value which is passed on the $_POST[] function. The form is "POSTING" so no problems there. Im just at a loss!

4
  • 1
    Could you post the actual error message you're getting, along with the line of code that the error message mentions, preferably with enough context for us to know what's going on beforehand? Commented May 19, 2011 at 10:52
  • Check your error_reporting setting locally and remotely. Propably the remote one is more strict. See: php.net/manual/en/function.error-reporting.php Commented May 19, 2011 at 10:54
  • It has nothing to do with jquery, html or css. Retagged. Please don't use random tags to improve visibility. Commented May 19, 2011 at 10:54
  • do a var_dump($_POST) and match the keys with those you use in your script. Commented May 19, 2011 at 11:00

3 Answers 3

2

You probably have a different error_reporting level on your own machine, then it is on the other server. Please add error_reporting(E_ALL); to the top of your page, and these will yell at you.

Sign up to request clarification or add additional context in comments.

5 Comments

Just to be a noob, is that specifically how you declare all error reporting?
Just add error_reporting(E_ALL); to the start of your script.
@ARandomGuy No it's not. You edit this line in your php.ini file: error_reporting = E_ALL & ~E_STRICT. This would show all errors. (Best for when you're coding but once it's finished and in production you want a lower level of error reporting; you don't want your users seeing your coding mistakes)
do you mean error_reporting(E_ALL & ~E_STRICT);? Your example threw a syntax error of its own.
That's because you tried to put the example I gave you into your PHP file and not edit that line in the php.ini file like I said. This is to answer your "is that specifically how you declare all error reporting?" question. You can't specify the error-reporting for all PHP files on the University Server though because you can't access the php.ini
0

As @Wesley van Opdorp mentioned, your machine must've a different reporting level, if you set it to E_ALL you will see all errors diplayed such as warnings, notices, and fatal errors.

You have to remember, if you're writing code with the error_reporting turned off or it is set to hide warnings or even notices and everything is working fine, if you turn it on, it may affect your code as it will report every single undefined variable and some other warnings as if it's on strict mode. You may have to add additional checks if that's the case like using isset or is_null before using or referring to undefined variables. Just a thought.

9 Comments

Just to add something. My doctype declaration is <!DOCTYPE html> which i believe is html5 - I was referred to do this by a friend to force the latest standards. Would this be the issue?
Urgh this is bugging me so much! it works fine on my server and domain!
have you verified your server's error_reporting level? try using ini_set('display_errors', 1); error_reporting(E_ALL);
Look This isnt anything to do with error buggging level or whatever, if there was a problem with my code I would have picked it up on my server, but there is no errors. I have not touched the forms/queries/anything. The only thing different from the code on www.jacoblimb.com and the pages stored on my university network is the db_conn file which has the updated Mysql server details (as well as the relevant SQL Statements inserting & updating data etc.
sure there is no problem with your code because you see it work, what we're all saying is there are error levels that shows you such notice like undefined. your server might have been set to only display parse, fatal, syntax errors but not notices and warnings those are the kinds that doesnt halt the execution, but if error_reporting is set to E_ALL you will be spammed with those. ALOT.
|
0

@Wesley is probably right about error reporting.

Try this too though. Check if the input has been entered before trying to use it:

$firstName = isset($_POST['firstName'])?strip_tags($_POST['firstName']):null;

Looks rough I know, but looks it can be as easy as this:

$date = date("Y-m-d");

$inputs = array('firstName', 'lastName', 'Email', 'userName', 'regPass', 'repeatPass', 'permissions');
foreach($inputs as $input)
{
    $values[$input] = isset($_POST[$input])?$_POST[$input]:null;
    //if it was set/used, store it in the variable, if not store null
}

This saves you writing a line for each of the inputs.

So for example $values['firstName'] would have the value of "John" OR null

So when using any of the $values elements check if it's null or use empty() to see if they put in an actual value.

8 Comments

Im really just confused. I understand what your code is doing, but im trying to relate it to my problem and its not solving anything.
Hmm it's hard for me to understand what you mean without seeing it. But this would remove the errors you gave us. Because if you tried to echo $values['firstName'];, the index 'firstName' would be defined. In every/any case you can think of. The second code block I gave is unnecessary for you, you can just change each of your lines in the same way I did for the first example and it'll do the same but it's more work for you (especially if you have to change something in the future)
After playing around. I notice that the variables are only undefined until they are given a value. But surely thats assumed? Why would it give me a whole wad of errors when I didnt request them? If I just ignore the error messages, enter the word "foo" in the first name input box and echo the variable out (which is undefined) it works and all the error messages go away! :S
That's what my code protects you against! The error_reporting level set gives you the errors as a guide to make sure what you know what you're doing (which can be helpful in a big project). If you implement my suggestion, you will never get those errors.
Okay so Im 99% sure ive fixed the pesky errors, I just dont think the SQL is working :/ Ill post more details when Im there
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.