Jump to content

Daniel On The Web

Members
  • Posts

    23
  • Joined

  • Last visited

Posts posted by Daniel On The Web

  1. As I thought I did something wrong, I decided to start over on a Mac. PHP works even without XAMPP, so I believe that the service to upload my webpage supports PHP.

     

    Now I'm thinking about reinstalling MySQL and phpMyAdmin in the Mac and test it again.

     

    Anyway, useful info to check what's the right port.

  2. User name: any

    Host name: localhost

    Password: no

    Global privileges: usage

    User group: -

    Grant: no

     

    User name: pma

    Host name: localhost

    Password: no

    Global privileges: usage

    User group: -

    Grant: no

     

    User name: root

    Host name: 127.0.0.1

    Password: no

    Global privileges: all privileges

    User group: -

    Grant: yes

     

    User name: root

    Host name: ::1

    Password: no

    Global privileges: all privileges

    User group: -

    Grant: yes

     

    User name: root

    Host name: localhost

    Password: no

    Global privileges: all privileges

    User group: -

    Grant: yes

  3. In phpmyadmin select test db ( make sure it is exactly as 'test' not 'Test' or 'test '), select permissions tab, and tell us what it says.

    It appears to me as "Privileges", but I think it's the same.

     

    The user I tried to use to connect to the database is:

    User name: root

    Host name: localhost

    Type: global

    Privileges: ALL PRIVILEGES

    Grant: Yes

  4. With MySQLi: No connection could be made because the target machine actively refused it.

    With PDO: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

     

    So they are the same.

     

    The console works well. The problem is connecting to the databases using PHP.

     

    And I'm using a PC.

  5. Ignoring PDO for a moment, does mysqli work?

    <?php
            
    error_reporting(E_ALL);
    ini_set('display_errors','On');
            
    echo 'Php is running...';
    echo '<br/>Connecting to MySQL... ';
    
    $dbcon = mysqli_connect('localhost','root','');
    $dbname = 'test';
            
    if (!$dbcon){
        echo '<br/>Error: Unable to connect to MySQL.';
    }else if(!mysqli_select_db($dbcon,$dbname)){
        echo '<br/>Error: Unable to open '.$dbname.' database.';
    }else{
        echo '<br/>Connected to '.$dbname.' database';
    }
    
    ?>
    

    I have my Apache server running on port 8080 and mysql on the default, which is 3306 and I use the above (except I have a root password).

    I tried with MySQLi but got the same error. Actually I don't care about using PDO or MySQLi. I'm choosing what works best.

  6. I use...

    $svr = "mysql:host=localhost;dbname=mydbname";
    
    try {
    
        $pdo = new PDO($svr, $usr, $pwd);
    

    Make sure you turned on the pdo mysql extension in php.ini.

     

    Seems odd that you don't have a root password but I guess you've tested that in the mysql console.

    Like this?: extension=php_pdo_mysql.dll Because that's how it appears on my php.ini. And it's not commented.

     

    It's clear PDO's MySQL extension is active and enabled because it's attempting to connect to the MySQL server.

     

    Perhaps you should install a server package like XAMPP on your computer for testing, it takes care of setting up the server properly for you. Installing Apache, MySQL and PHP separately is more prone to human error.

    I'm already using it.

  7. Yes! BUT did actually check mysql.ini file or phpinfo() to identify which port mysql is actually using.

    I checked the port it is using and it's 3306. But I still find the message that says me that the connection failed.

  8.  

    MYSQL DOES NOT USE SAME PORT AS WEB SERVER, so using localhost:80 WON'T work, default port for MYSQL database server is usually 3306, if you use just localhost, by default it will listen for port 3306 for MYSQLl server connection, using localhost:3306 will work also because it pointing to same port, but! localhost:80 WILL NOT!

    Both "localhost" and "localhost:3306" didn't work as servers.

  9. I don't know your MySQL server's username, password or port number (and it wouldn't be smart to post the user and password on a public forum), but the issue could be that one of those is wrong.

     

    Of course. I know that I shouldn't post such kind of information.

     

    However, I set up an user, a host and a password and wrote the same information in the PHP and the code is still throwing the error.

  10. <?php
    $serv = "localhost:81";
    $user = "root";
    $password = "";
    
    
    try {
    	$con = new PDO("mysql:host=$serv;dbname=test", $user, $password);
    	
    	$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    	
    	echo "Successfully connected."; 
    } catch (PDOException $e) {
    	echo "Connection failed: " . $e->getMessage();
    }
    ?>
    

    Here I'm trying to use PDO to connect to my SQL database "test". However, I receive this error each time I connect:

     

    SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.

     

    Am I connecting with the wrong server, user or password? Because I fail to see here the mistake.

  11. Ok. I went through the file httpd.conf of the Apache Module and changed the port to listen from. Now it's port 81. And it worked. However, when I type http://localhost I found an error 404 even with Apache activated. And what I am supposed to see is the XAMPP page. What else do I have to do?

     

    Edit: I changed the main port for Apache to 81 as well and typed http://localhost:81. This took me to the XAMPP page. Now I have to configure PHP and Apache so I can use them in my website.

  12. Hello everyone. I tried to install and configure PHP and MySQL for use on my own website using XAMPP. However, the Apache module gives me an error each time I try to start it.

    10:40:53  [main] 	Starting Check-Timer
    10:40:53  [main] 	Control Panel Ready
    10:41:07  [Apache] 	Problem detected!
    10:41:07  [Apache] 	Port 80 in use by "Unable to open process" with PID 4!
    10:41:07  [Apache] 	Apache WILL NOT start without the configured ports free!
    10:41:07  [Apache] 	You need to uninstall/disable/reconfigure the blocking application
    10:41:07  [Apache] 	or reconfigure Apache and the Control Panel to listen on a different port
    10:41:07  [Apache] 	Attempting to start Apache app...
    10:41:07  [Apache] 	Status change detected: running
    10:41:10  [Apache] 	Status change detected: stopped
    10:41:10  [Apache] 	Error: Apache shutdown unexpectedly.
    10:41:10  [Apache] 	This may be due to a blocked port, missing dependencies, 
    10:41:10  [Apache] 	improper privileges, a crash, or a shutdown by another method.
    10:41:10  [Apache] 	Press the Logs button to view error logs and check
    10:41:10  [Apache] 	the Windows Event Viewer for more clues
    10:41:10  [Apache] 	If you need more help, copy and post this
    10:41:10  [Apache] 	entire log window on the forums 

    As the log said, I have to find and uninstall, disable or reconfigure the application which is blocking Port 80 or reconfigure Apache and the Control Panel to listen to a different port.

    The question is: What should I do? Should I change port or should I find the blocking application? And if the latter, which application could be blocking Port 80?

  13. So, in order to solve the issue, I have to:

    • Download XAMPP or something similar and set up a test server on my own computer.
    • Make sure the page and the XML are both in that server.

    I have downloaded XAMPP, but now the question is, how do I create my test server?

  14.  

    You probably should run this on a server. Local AJAX requests are blocked by some browsers for security reasons.

    If your code is not

    xhttp.open("GET", "news.xml", true);

    but rather

    xhttp.open("GET", "http://example.com/news.xml", true);

    then this is not permitted, you can only access files on your site's domain name.

    There's only one way to load files from example.com with AJAX, and that's by configuring the example.com server to send an Access-Control-Allow-Origin HTTP header.

     

    So I should create a server using a domain, and then configure it to send an Access-Control-Allow-Origin HTTP header. Am I right?

  15. Hello and thank you all for bringing me into this forum. I would want to make a website about video games with news, articles, login system, etc., and I'm learning to make it with W3Schools.
    My issue is with the XML DOM. I tried to use JavaScript to add XML data (in the form of a news list) to my HTML page, so I used the following JavaScript code:

    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
        newsDisplay(xhttp);
        }
    };
    xhttp.open("GET", "news.xml", true);
    xhttp.send();
     
    function newsDisplay(xml) {
        var xmlDoc, maxNews, txt, titles, dates;
    xmlDoc = xml.responseXML;
    maxNews = 5;
    txt = "";
    titles = xmlDoc.getElementsByTagName("title");
    dates = xmlDoc.getElementsByTagName("date");
    for (i = 0; i < maxNews; i++) {
     txt += '<a href="news/news_' + + '.html"><div class="news_block">' +
     '<div class="news_title">Noticia' + titles[i].childNodes[0].nodeValue + '</div>' +
     '<div class="news_date">Fecha' + dates[i].childNodes[0].nodeValue + '</div></div></a>';
    }
    document.getElementById("news").innerHTML = txt;
    }

    Being:

    • news.xml the file where the news come from, with the <title> and <date> tags in each of the news
    • maxNews the number of news to show in the list (from the first ones in the XML)

    But when I test my web page, the console says: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

    .

    Thank you for any help.

×
×
  • Create New...