logo elektroda
logo elektroda
X
logo elektroda

Connecting & Displaying Database on Website: XAMPP, Fatal Error, MySQL, Apache, strona.php

hubert85 4809 14
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16808925
    hubert85
    Level 8  
    Hello
    I got a job at school to create a database and display it on the website. I made the database but trying to display it on the website I can't connect. Apache and Mysql are enabled. The error that is displayed to me

    Fatal error: Uncaught Error: Call to undefined function mysql_connect () in C: \ xampp \ htdocs \ strona.php: 2 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ strona.php on line 2

    Thank you in advance for your help.

    Code: PHP
    Log in, to see the code
  • ADVERTISEMENT
  • #2 16809331
    adamz74
    Level 32  
    MySQL databases are not enabled in PHP. There can be several reasons, the most common:
    - php_mysql.dl and libmysql.dll libraries missing or unavailable (wrong path in php.ini - extension_dir = "C: \ PHP \ ext"),
    - commented line in php.ini - extension = php_mysql.dll


    https://www.youtube.com/watch?v=hcVI83ymuWg

    Greetings!
  • #3 16809564
    hubert85
    Level 8  
    The same error is still there
  • #4 16809980
    arnoldziq
    VIP Meritorious for electroda.pl
    hubert85 wrote:
    The same error is still there

    I suggest you run PHPInfo from Xampp and check if and what MySQL support is installed.

    Among other things, something like this should be 'shown':

    Connecting & Displaying Database on Website: XAMPP, Fatal Error, MySQL, Apache, strona.php
  • ADVERTISEMENT
  • #5 16809994
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #7 16810534
    hubert85
    Level 8  
    adamz74 wrote:
    One more thing ... from PHP 5.5.0, mysql_connect () is considered obsolete and probably has been removed since version 7.0.0.

    You can use mysqli http://php.net/manual/en/book.mysqli.php instead


    I changed xampp to an older version and now I get this error

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\strona.php on line 6


    code same as above
  • #8 16811246
    arnoldziq
    VIP Meritorious for electroda.pl
    I suggest using a code like this:
    Code: PHP
    Log in, to see the code


    Another observation; I do not know how my colleague has set the database engine, but the use of Polish characters in the names of tables / record fields is not always properly supported. Maybe there is a problem here.
  • #9 16812076
    hubert85
    Level 8  
    arnoldziq wrote:
    I suggest using a code like this:
    Code: PHP
    Log in, to see the code


    Another observation; I do not know how my colleague has set the database engine, but the use of Polish characters in the names of tables / record fields is not always properly supported. Maybe there is a problem here.


    Now such a problem comes up
    Notice: Undefined variable: polaczenie in C:\xampp\htdocs\stronaa.php on line 5
    
    Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\stronaa.php on line 5
    Blad zapytania:
  • #10 16812453
    adamz74
    Level 32  
    Undefined variable $ connection.
    mysql_query () expects the resource id as the 2nd parameter.

    In this case, it means you have a typo in the variables you are using.

    $ connection != $ connection
  • #11 16812844
    hubert85
    Level 8  
    it doesn't go with the other variable either and it's the same Error
  • #12 16813322
    arnoldziq
    VIP Meritorious for electroda.pl
    hubert85 wrote:
    it doesn't go with the other variable either and it's the same Error
    I suggest my colleague paste here exactly the code that my colleague is currently using.
    Because such comments do not bring anything new to the discussion.

    BTW: Sorry for the typo. You know; autism, dyslexia, dysorthography :)
  • Helpful post
    #14 16814226
    arnoldziq
    VIP Meritorious for electroda.pl
    And so:
    Execution of the inquiry:
    Code: SQL
    Log in, to see the code
    in phpAdmin it returns correctly.
    Connecting & Displaying Database on Website: XAMPP, Fatal Error, MySQL, Apache, strona.php
    However, as I suspected; calling the script with the same query displays the following message:
    PHP wrote:
    Query Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?y, id_klienta, id_towaru, ilo??, data from `Sprzedaż?` at line 1

    Which means exactly what I wrote a few posts earlier; Polish letters in the names of variables, arrays, fields, etc. is not a good idea: /
    Code used:
    Code: PHP
    Log in, to see the code

    However, the use of a code that avoids the use of Polish characters in the query;
    Code: PHP
    Log in, to see the code
    gives a good effect in my opinion:
    Connecting & Displaying Database on Website: XAMPP, Fatal Error, MySQL, Apache, strona.php
  • ADVERTISEMENT
  • #15 16814417
    hubert85
    Level 8  
    Thank you :D You are great.
    Thank you to the rest of the speakers too ;)

Topic summary

The discussion revolves around a user's difficulty in connecting a MySQL database to a website using XAMPP, encountering a "Fatal error: Call to undefined function mysql_connect()" message. Responses suggest checking PHP configuration, specifically the php.ini file for missing MySQL extensions and ensuring the correct version of PHP is used, as mysql_connect() is deprecated in PHP 5.5.0 and removed in PHP 7.0.0. Users are advised to switch to mysqli functions. The user later experiences issues with undefined variables and incorrect parameters in mysql_query(), leading to further troubleshooting. The final resolution involves avoiding Polish characters in database queries, which resolves the issues encountered.
Summary generated by the language model.
ADVERTISEMENT