Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

A problem with queries #1

Closed
LorinWeb opened this Issue Feb 10, 2012 · 4 comments

Comments

Projects
None yet
2 participants

Hi sunnysingh,
I'm not so good in php, so it may be an easy to fix issue. That's the problem:
When i try to insert a new user in my database, i get this error message

"Undefined index: query in /opt/lampp/htdocs/public_html/www.gaptricesimo.it/PHP/classes/database.php on line 51".

I used the sintax provided by you in the docs $insert = $db->query("INSERT INTO people (name, age) VALUES('Bob', '123')");
I also tryed the other sintax for sensitive variables but after that the errors became two:

Notice: Undefined index: query in /opt/lampp/htdocs/public_html/www.gaptricesimo.it/PHP/classes/database.php on line 51
Notice: Undefined variable: markers in /opt/lampp/htdocs/public_html/www.gaptricesimo.it/PHP/classes/database.php on line 79

Can you please help me to find out where i'm wrong?
Thank you so much and congratulations for the great Class, i hope to get it working.

P.S. I included the file correctly and the rows are actually stored in the database, just wondering why those errors appear. Working with xampp on linux.

Lorin

Owner

sunnysingh commented Feb 10, 2012

It seems like your error_reporting level is too strict. I suggest you edit your php.ini file or use the error_reporting() function to change it to E_ALL ^ E_NOTICE (which is the default).

So it would look like this:

<?php

error_reporting(E_ALL ^ E_NOTICE);

// the rest of your code here...

Let me know if that changes anything.

Thank you so much, that solved the problem. But why php flags it as an
error if the script works fine as it is? Just can't figure out... That
said, it's really the best class i've found around the net, tons of thanks
could never be enough :-)

Owner

sunnysingh commented Feb 10, 2012

There's different levels of error reporting in PHP. Even though my code works, there's a few things that I could improve so that the code will still work even at strict error reporting levels.

For example, on line 71 I have this:

$markers .= "i";

Which basically adds the letter "i" to whatever the previous value of $markers was. PHP complains about that though, because $markers was never defined (it's as if I'm adding "i" to a string that doesn't exist).

Instead, I should really do:

$markers = "";
$markers .= "i";

That way I know that $markers is an empty string before I add anything on to it. It's not a huge deal, that's why PHP gives you different error reporting levels. Coding habits change though, and now I do prefer to declare variables before using the .= operator. In the future I want to update the framework and fix these little bugs that aren't really bugs.

Hope that explained it, and thanks for using my framework.

Very clear, i'll try doing it on my own :-). Thank's again.

@sunnysingh sunnysingh closed this Feb 10, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment