Okay, I've been through Learnable's PHP/MySQL class with Kevin Yank twice. This is my first attempt applying my new skills to an actual site. It's going okay so far, but my first trial to get database information to display on the page isn't going well.

My goal is to allow the client to updates their announcements and schedule in-house. I haven't started on the CMS portion yet, I'm just entering a couple test lines of data via PHPMyAdmin for now. When I try to get the announcement in the database to come up on the site, it's just blank. My test line for database connection comes up, but that's it.

Most people here could likely get this entire request done in an afternoon, but I'm coming from just doing front-end development. Please let me know what I missed in spelling or whatever so I can quit pulling my hair out. Thanks.

Have youvar_dump($eventitem)to see what is being returned? Have you using PHPMyAdmin run your SELECT query to see if it returns any results.

Check these first and then well go from there.

Regards,Steve

vmtech
—
2012-03-21T21:08:55Z —
#3

I'm not familiar with the "var_dump" item, so I may have done it wrong. I put it in as "var_dump($eventitem);", "var_dump($announcements);", and "var_dump($event['text']);" in my index file and received NULL. Running the select statement in PHPMyAdmin produced the results I was looking for, date and text just as I expected.

ServerStorm
—
2012-03-21T22:10:44Z —
#4

Hi vmtech,

Your first two examples of var_dump(); is how one normally uses it, the var_dump($event['somethin']); will return a value but you would normally var_dump($event) and it would tell you that it is an array and show the values (if any exist).

The null values mean that the variables are not being set. Your query (run from PHP using the mysqli) is not returning the data. You have to check if the query string is actually a string and you have to ensure that any variables you are quoting out in that string also have values; otherwise the query will not return results.

The var_dump($variable); will provide verbose output of the contents of a variable. The Mysqli query should return and array so normally var_dump($results); should return something that looks like this:

Your query should return an array similar, only the key names will be the column names defined in the query.

To troubleshoot, I recommend starting a very simple PHP page that you setup the mysqli connection and try to run the SELECT and then run var_dump($results); Get the query working there first before you do everything else you are attempting in your scripts.

Steve

vmtech
—
2012-03-21T22:58:10Z —
#5

Thanks, that makes sense. Time for more testing and debugging.

Mittineague
—
2012-03-21T23:40:53Z —
#6

If you don't have this at the beginning of your PHP file it may help if your config doesn't already have them set.

I'm working on a test page with the suggestions given, but unfortunately I'm not gaining ground.

On my test page I don't link to the script the script (announce.php) that has the code retrieving information from the database, just like I did in class. However, I then get errors of undefined variables on every line with a variable. If I add an include announce.php line, the undefined variable errors don't come up, just the attached screen shot.

The two files, test.php and announce.php are below. None of the others have changed since my original post. Thanks for the help so far. I'm sure that it's something minor I'm missing, but I don't see what it is. Test and announce are both in the same directory on the server.

Hi vmtech, Here is what I notice:[LIST=1][*]Notice that your are doing a 'circular include' where announce.php is including test.php and test.php is including announce.php. You should only have announce.php including test.php and instead of using include you should use require_once('test.php');[*]I think that you are not getting any reading in var_dump($events) as you are not really including the database file that contains this global variable.[*]You should initialize your variables before you use them, so for example before your

If you still get nothing when you output var-dump(events) then you are not getting anything back in your mysqli_fetch_array() so you will need to ensure that this is returning results. Inside the while loop put a var_dump($row) ; statement.[/LIST]

Regards,Steve

vmtech
—
2012-03-27T14:59:52Z —
#9

Sorry for the delay, other work and life came up. I made the changes and tests suggested, but I'm still not seeing a changes.

I put the var_dump statement in the announce.php page and it does produce the array with the expected results when I go directly to announce.php in my browser on my test server. Unfortunately, going to test.php, the page that is supposed to show the results, I only get undefined variable errors.

This is half of two parts that will be showing database contents. I did the other section just to see if I missed something, but I get the same results as this one with undefined variable errors. The new coding for the pages is below. Thanks again for the help.

The debugging line came up with a few complaints, but it FINALLY displayed the database information as it should. Thank you very much for the help, it looks like I can keep going, for now at least.

vmtech
—
2012-06-13T15:36:49Z —
#13

Sorry to bring up old threads, but I'm having trouble with this DbFactory now on the active site. It was just now uploaded to the site's server, so this project has been well dragged out to say the least.

The page produces this error: Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in e:\websites\1414\sullychristian.org\assets\includes\DbFactory.php on line 3

Other than the server connection information, I have not changed anything from the code given a few months ago in the code above. This is also the only time I've worked with DbFactory, so please help when possible.

ServerStorm
—
2012-06-13T17:13:16Z —
#14

Hi vmtech,

What version of PHP is your Active Site? If it is PHP 4 then this error will be thrown.

vmtech
—
2012-06-13T17:32:17Z —
#15

I thought of that, but it's on 5.

ServerStorm
—
2012-06-13T17:50:15Z —
#16

Hi

Can you let us know what echo PHP_VERSION; returns?

Steve

vmtech
—
2012-06-13T18:02:06Z —
#17

Well, I set it up on PHP MySQL 5 server, but the echo came back with 4.4.6.

ServerStorm
—
2012-06-13T21:51:03Z —
#18

That's why then... I don't know if you can upgrade this to a version 5.3.x but if possible you should. PHP 4 (as you likely know) is a dinosaur that you should avoid like a Rex ;D

vmtech
—
2012-06-13T21:55:35Z —
#19

It's on a generic, cheap, hosted system, but I'll see what I can do. Thanks.

vmtech
—
2012-06-19T16:20:34Z —
#20

After finally finding the correct person at the host, getting the upgrade went well. Now everything is running, but it's coming up with two variable errors. One is that db is undefined in line 14 of DbFactory.php and the other is fields on line 5 of getschedule.php. My login also is isn't working, but I'm getting to it yet.

From what I see, both of the variables are declared. They haven't changed from my testing model, so I'm not sure where to look. The scripts are posted below, so maybe you can see something. This site is now up at: http://www.sullychristian.org/calendar.php, everything is up except the index. I'm testing the PHP site before removing html.