Author Topic: Please help - Following a video tutorial, script not working  (Read 194 times)


PHP Help Forum




PHP Help Forum



Anonymous Newbie

  • New Member
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Now the getPage function in his 3rd tutorial doesn't work either :/
I get a fatal error for that one... Call to undefined function getPage()

But back on the subject of my original post, here's my code, it should be almost exactly like his, except the name of my project is Radical Rodents:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  <?php
  
require_once("system/functions.php");
  require_once(
"system/config.php");
  
  
//DATABASE CONNECTION
  
$dbserver     =   "localhost";
  
$dbusername =    "root";
  
$dbpassword  =    " ";
  
$db =     "radical rodents"
 
 
//CREATE CONNECTION
 
$conn = new mysqli($dbserver$dbusername$dbpassword);
 
 
//CHECK CONNECTION
 
if($conn->connect_error)
 {
 die(
"Connection failed".$conn->connect_error);
 }
 else
 {
 
	
//IF CONNECTION IS GOOD, GET DATA FROM DATABASE
 
	
$query "SELECT name, seperator, description, maintenance, logo FROM configuration";
 
	
	
$result mysqli_query($conn$query);
 
	
	
$row mysqli_fetch_assoc($result);
 
	
$name $row ['name'];
 }
  
  
//TECHNICAL SETTINGS
 
$maintenance   =   false;
 
 
 
?>




Thank you for replying so quickly! I am on the localhost in Chrome, and I have my project open on the "index.php" file.


PHP Help Forum

Re: Please help - Following a video tutorial, script not working
« Reply #2 on: May 15, 2017, 08:53:51 pm »



PHP Help Forum




PHP Help Forum

Re: Please help - Following a video tutorial, script not working
« Reply #4 on: May 16, 2017, 04:47:17 pm »



PHP Help Forum




PHP Help Forum



phdr

  • New Member
  • *
  • Posts: 24
  • Karma: 1
    • View Profile
So far, the only indication that any of your php code is running at all, is the fatal runtime error you mentioned in reply #2, which is for some code other than the current problem code.

Back to the php error_reporting/display_errors settings. How have you obtained and installed your web server/php? If you used one of the all-in-once packages, the control panel for it should have a way of editing the php.ini. Otherwise, you can find where the php.ini that php is using is, by creating a .php script file with the following in it, then request the file through your web server using your browser -
1
2
3
 <?php
 phpinfo
();
 
?>



There will be a Loaded Configuration File line in the resulting output that shows the path and filename of the php.ini that you would need to edit with the error_reporting/display_errors settings. The output from the phpinfo() statement also shows what the error_reporting/display_errors settings are. To insure that any changes you make to the php.ini take effect, you need to restart your web server and check using a phpinfo() statement that the changes actually have taken effect.

While you are making changes to the php.ini, find what the output_buffering setting is, and set it to OFF, it if is anything other than OFF. This setting hides problems and hides output from your code and php errors, making it harder to write and test code. The only time you should use output buffering is if you need to buffer output and this setting should normally be off.

This should get you to the point where php and/or your code will give you an indication of why it isn't running on your server. As to why the code you are finding in a tutorial doesn't work for you, there can be typos, differences in php configuration, and differences in php versions that would allow code to work on one server but not another. This is why you must get php to help you when you are leaning, developing, and debugging code, by having the error_reporting/display_errors settings set as suggested.

You also need to ALWAYS have error handling for statements that can fail, in this case the database connection and query statements, and you shouldn't output the actual error messages when running code on a live/public server, as this gives hackers useful information. The easiest way of adding error handling, that doesn't involve adding conditional logic for each statement (Keep It Simple - KISS), is to use exceptions and let php catch any exceptions. This also addresses not outputting the actual error information when on a live serve, since php will use the error_reporting/display_errors/log_errors settings to control what happens with the actual error information. When on a live server, you would set display_errors to OFF and set log_errors to ON. To enable exceptions for the mysqli statements, add the following two lines of code before the database connection code, and remove the code trying to detect the connection error (which may not be working correctly anyway) -
1
2
3
4
 
 
// note: the variable $driver in these two lines of code can be any chosen name and is not tied to any variable name you are using in the rest of your database code
 
$driver = new mysqli_driver();
 
$driver->report_mode MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT// MYSQLI_REPORT_ALL <- w/index checking; w/o index checking -> MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;



BTW - the code in reply #2 is not selecting a database, so after you get the error_reporting/display_errors settings set as suggested and enable exceptions, you should be getting some useful error output when the code runs. Also, the $conn->connect_error doesn't work in older php versions and the posted code may not be detecting a connection error at all, which may account for the symptoms you are getting, but this problem will go away if you switch to use exceptions and remove the code trying to use $conn->connect_error. What php version are you using?

Lastly, the php mysqli extension is the not written the best (the problem with the $conn->connect_error not working in some versions of php is just one of the many problems with it.) You should instead learn the php PDO extension. It is better written and is simpler and more straight-forward to use.

PHP Help Forum

Re: Please help - Following a video tutorial, script not working
« Reply #7 on: May 21, 2017, 11:45:25 am »