daynieman Posted August 29, 2017 Share Posted August 29, 2017 (edited) 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 Edited August 29, 2017 by daynieman Quote Link to comment https://forums.phpfreaks.com/topic/304755-messed-up-code-due-to-php-7/ Share on other sites More sharing options...
Solution PravinS Posted August 29, 2017 Solution Share Posted August 29, 2017 You haven't passed link identifier returned by mysqli_connect() to mysqli_query() function Check Manual for more details: http://php.net/manual/en/mysqli.query.php Quote Link to comment https://forums.phpfreaks.com/topic/304755-messed-up-code-due-to-php-7/#findComment-1550308 Share on other sites More sharing options...
daynieman Posted August 29, 2017 Author Share Posted August 29, 2017 @PravinS If i might ask what do you mean by that exactly? is there any way a newbie like me could fix it? Quote Link to comment https://forums.phpfreaks.com/topic/304755-messed-up-code-due-to-php-7/#findComment-1550309 Share on other sites More sharing options...
mac_gyver Posted August 29, 2017 Share Posted August 29, 2017 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. 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. Quote Link to comment https://forums.phpfreaks.com/topic/304755-messed-up-code-due-to-php-7/#findComment-1550328 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.