Jump to content

Messed up code due to php 7


daynieman

Recommended Posts

So recently i've been getting issues with a program i wrote for my internship. my internship program broke because of the updated rules on php 7 which we did not get warned about in class. i would like some help solving all of my errors if possible.

I will post all errors below and add the file they occur in below.

Please help me with my issues.

 

With kind regards,

Dayne Tersluijsen
 

 

Errors: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp1\htdocs\ProdyneP\Modules\Welcome.php on line 126

            Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp1\htdocs\ProdyneP\Modules\Welcome.php on line 52

Could not connect: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp1\htdocs\ProdyneP\Modules\Welcome.php on line 126 Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp1\htdocs\ProdyneP\Modules\Welcome.php on line 85

Could not connect: 

Welcome.php

Link to comment
Share on other sites

the way to correctly use any of the php statements is to lean what they do, what parameters they accept as input, and what values they return.

 

i recommend that you re-do your code, making use of the the following -

 

1) use the php PDO extension
 
2) make ONE database connection for the entire page
 
3) use exceptions to handle database errors. this will let you eliminate the error handling logic in your code.
 
4) use prepared queries to supply data values to the sql query statements
 
5) consolidate and put the post method form processing code near the top of your file
 
6) consolidate and put the SELECT queries, that are retrieving the data needed to display the page, next, and put it before the start of your html document. fetch the data from each query into an appropriately named variable. loop over these variables in your html document in order to output the data.
 
7) for the various select/option lists, store the choices in database tables, with an auto-increment column for an id. you would query for the choices and dynamically produce the option lists. the id would be used as the option value attribute and you would store the id in any table holding data related to the select/option choices. you would also 'select' the option choice that matches any existing stored data value.
 
8) don't put/leave code and variables in your code if it isn't being used.
 
9) if you are going to LIMIT the number of rows of data that are being displayed, do that in the query, using a LIMIT clause. you should also use an ORDER BY clause in any SELECT query that is expected to match more than one row.
 
10) if you are going to use literal values in your code, such as the 1,2,3 for the table, use defined constants, with meaningful names, so that anyone looking at the code can tell what the 1,2,3 values mean any place they are being used.
 
11) it appears that your database tables have sequences of columns with times as part of the column name. if so, research 'database normalization'
 
12) it also appears like the three database tables hold similar data, only differing in a 'category'. if so, the data should be stored in a single table, with a category column.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.