Impossibile connettersi al server localhost.

matrobriva

Nuovo Utente
23 Set 2010
14
0
0
matrobriva.altervista.org
Ciao a tutti. Questo listato mi non riesce a connettersi a localhost... dov'è l'errore?

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>Nuovo Alunno</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta name="generator" content="Geany 0.18" />
</head>
<body>

<?php
    print("Nuovo alunno");
    $host1=fopen("host.txt","r");
    $host2=fread($host1,filesize("host.txt"));
    $user1=fopen("user.txt","r");
    $user2=fread($user1,filesize("user.txt"));
    $pwd1=fopen("pwd.txt","r");
    $pwd2=fread($pwd1,filesize("pwd.txt"));
    $db1=fopen("db.txt","r");
    $db2=fread($db1,filesize("db.txt"));
    $host = $host2;
    $user = $user2;
    $password = $pwd2;
    $database = $db2;
    $db = mysql_connect($host, $user, $password) or die ("Impossibile connettersi al server $host");
    mysql_select_db($database, $db) or die ("Impossibile connettersi al database $database");
    $query = "insert into alunni " . 
            "(nome, cognome, sesso, cittadinanza, residenza, trasporti, as_di_riferimento, data_di_iscrizione, frequenza, provenienza, trasferimenti, codice_fiscale, luogo_data_nascita, city, street, home_phone, mobile_phone, another_phone, e-mail, father_name, father_surname, father_born, father_title, father_job, father_live, father_home_phone, father_mobile_phone, father_work_phone, mother_name, mother_surname, mother_born, mother_title, mother_job, mother_live, mother_home_phone, mother_mobile_phone, mother_work_phone, tutor_name, tutor_born, tutor_title_job, tutor_phone) " .
            "VALUES('" .
                $_REQUEST['nome'] . "','" .
                $_REQUEST['cognome'] . "','" .
                $_REQUEST['sesso'] . "','" .
                $_REQUEST['cittadinanza'] . "','" .
                $_REQUEST['residenza'] . "','" .
                $_REQUEST['trasporti'] . "','" .
                $_REQUEST['as_di_riferimento'] . "','" .
                $_REQUEST['data_di_iscrizione'] . "','" .
                $_REQUEST['frequenza'] . "','" .
                $_REQUEST['provenienza'] . "','" .
                $_REQUEST['trasferimenti'] . "','" .
                $_REQUEST['codice_fiscale'] . "','" .
                $_REQUEST['luogo_data_nascita'] . "','" .
                $_REQUEST['city'] . "','" .
                $_REQUEST['street'] . "','" .
                $_REQUEST['home_phone'] . "','" .
                $_REQUEST['mobile_phone'] . "','" .
                $_REQUEST['another_phone'] . "','" .
                $_REQUEST['e-mail'] . "','" .
                $_REQUEST['father_name'] . "','" .
                $_REQUEST['father_surname'] . "','" .
                $_REQUEST['father_born'] . "','" .
                $_REQUEST['father_title'] . "','" .
                $_REQUEST['father_job'] . "','" .
                $_REQUEST['father_live'] . "','" .
                $_REQUEST['father_home_phone'] . "','" .
                $_REQUEST['father_mobile_phone'] . "','" .
                $_REQUEST['father_work_phone'] . "','" .
                $_REQUEST['mother_name'] . "','" .
                $_REQUEST['mother_surname'] . "','" .
                $_REQUEST['mother_born'] . "','" .
                $_REQUEST['mother_title'] . "','" .
                $_REQUEST['mother_job'] . "','" .
                $_REQUEST['mother_live'] . "','" .
                $_REQUEST['mother_home_phone'] . "','" .
                $_REQUEST['mother_mobile_phone'] . "','" .
                $_REQUEST['mother_work_phone'] . "','" .
                $_REQUEST['tutor_name'] . "','" .
                $_REQUEST['tutor_surname'] . "','" .
                $_REQUEST['tutor_born'] . "','" .
                $_REQUEST['tutor_title_job'] . "','" .
                $_REQUEST['tutor_phone'] . "')";
                
if (!mysql_query($query, $db))
{ 
    print("Impossibile inserire il record");
    }
    else
    { 
    print("Record inserito!");
    }
    
    mysql_close($db);

    
?>
</body>
</html>
 

alessandro1997

Utente Attivo
6 Ott 2009
5.302
1
0
26
Roma
alessandro1997.netsons.org
A parte il fatto che scrivere i singoli valori di accesso al database in dei file di testo, leggibili da chiunque, mi sembra una soluzione veramente poco sicura. E poi cosa intendi con "non riesce a connettersi"? Non riesce ad accedere al database? Se sì, prova a stampare il risultato della funzione mysql_error, per vedere qual è precisamente l'errore.
 

Eliox

Utente Attivo
25 Feb 2005
4.390
3
0
PHP:
$db = mysql_connect($host, $user, $password) or die (mysql_error());

comunque stampati il contenuto di $host, $user, $password per vedere se i dati di connessione vengono retti correttamente.
 

lotus

Utente Attivo
5 Mag 2009
543
8
0
il database è correttamente attivo e funzionante, su quale porta? quella di default?
hai verificato che la richiesta pervenga adl db?

Ciao,Ciro
 

Eliox

Utente Attivo
25 Feb 2005
4.390
3
0
hai corretto usando:
PHP:
$db = mysql_connect($host, $user, $password) or die (mysql_error());
?
che errore ti restituisce?
 
Discussioni simili
Autore Titolo Forum Risposte Data
asevenx Impossibile connettersi al database - mysql system error: 111 MySQL 3
C Impossibile loggarsi. HTML e CSS 1
S Impossibile scorrere un oggetto in JavaScript Javascript 0
felino [Joomla 1.5] Backend senza toolbar, impossibile eseguire qualunque operazione Joomla 1
felino [Windows 8.1 Pro] Impossibile attivare/avviare Windows Defender Windows e Software 3
W Errore di run-time di Microsoft VBScript error '800a0035' Impossibile trovare il file Classic ASP 0
S PHP Impossibile stabilire la connessione PHP 8
W Impossibile Trovare Provider Classic ASP 7
M Impossibile visionare la immagini dall'App. IP Cam e Videosorveglianza 8
Q impossibile modificare un file ....... C/C++ 2
ste80 [MS Access] Impossibile aprire una maschera da pulsante MS Access 2
C Impossibile "entrare" nel IPCAM IP Cam e Videosorveglianza 0
M [Photoshop] impossibile impostare Profilo colori Photoshop 1
Magenta [WordPress] impossibile reinstallare NextGallery in locale WordPress 1
T [PHP] Calcolo anzianità soggetti [era: Help me :( Esercizio per me impossibile] PHP 9
P prestashop - Impossibile raggiungere sito..impiegato troppo tempo a rispondere E-Commerce 0
G Somma variabili impossibile Javascript 3
felino [Backend] Impossibile accedere al backend WordPress 2
A Impossibile accedere alle configurazioni del router Reti LAN e Wireless 1
F Aiuto: impossibile la mappatura di un'immagine con Dreamweaver CC2015 HTML e CSS 8
R Bootstrap Carousel allineamento a sinistra impossibile! HTML e CSS 1
A Gestione completa di una tabella del Database... impossibile PHP 0
M Impossibile accedere a pc su LAN Reti LAN e Wireless 1
R Errore nel CSS impossibile HTML e CSS 2
P Creare un social network in 2 persone: arduo o impossibile? Discussioni Varie 2
A impossibile installare sp 1 Windows e Software 0
M Login Admin impossibile V 1.9 Magento 0
Marco_88 Impossibile accedere al database PHP 16
T Impossibile installare ChatWee Joomla 0
C Aggiunta nuovo ruolo utente e impossibile modificare le pagine WordPress 7
P Impossibile selezionare il database PHP 7
P impossibile selezionare il database PHP 0
renoir09 impossibile visualizzare bacheca siti in modalità multisito in locale (mamp) WordPress 0
felino [Virtuemart] Impossibile effettuare alcun modifiche dall'amministrazione Joomla 0
S Impossibile collegarsi al DB... PHP 7
P Impossibile completare immediatamente l'operazione sul socket non a blocchi. PHP 1
P Impossibile usare socket_connect PHP 2
asevenx Problema Dreamweaver "impossibile individuare i file correlati dinamicamente..." e con i <div> HTML e CSS 1
G Aiuto!problema impossibile da risolvere Joomla 1
M Impossibile digitare password da terminale Linux e Software 1
best impossibile accedere Supporto Mr.Webmaster 4
A Favicon sull' Url - Impossibile HTML e CSS 5
renoir09 Impossibile caricare immagini con wordpress WordPress 0
T [MySql] impossibile estrarre dati da campi TEXT MySQL 0
borgo italia outlook: impossibile bloccare indirizzo di posta Windows e Software 5
L Paginazione impossibile HTML e CSS 3
neo996sps Impossibile caricare file su di un sito PHP 4
moon Impossibile spostare cartella Windows e Software 6
borgo italia impossibile inviare email Discussioni Varie 0
M Impossibile svuotare cache DNS Reti LAN e Wireless 1

Discussioni simili