Salve ragazzi, sono alle prese con il mio primo script php.
La questione è abbastanza urgente, dato che si tratta di un caso di studi e devo completarlo in fretta.
Ho un problemone.
Ho creato il database con phpmyadmin e dall'interfaccia sembra tutto corretto, tuttavia da php non riesco ad accedervi.
L'errore è il seguente:
Ecco i codici:codice:Warning: mysql_connect() expects parameter 2 to be string, resource given in /opt/lampp/htdocs/eTakeAway/addUser.php on line 38 Impossibile connettersi al database
Script php:codice:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://w3.org/1999/xhtml"> <head> <title>Form di registrazione eTakeAway!</title> <link rel = "stylesheet" type = "text/css" href = "css/styleReg.css" /> <script type="text/javascript"> <!-- function checkForms(){ var email = document.getElementById('email').value; var emailConfirm = document.getElementById('emailConfirm').value; var nome = document.getElementById('nome').value; var surname = document.getElementById('surname').value; var pass = document.getElementById('pass').value; var passwordConfirm = document.getElementById('passwordConfirm').value; var condition = document.getElementById('condition').checked; var telephone = document.getElementById('telephone').value; var cell = document.getElementById('cell').value; var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/; if (!email_reg_exp.test(email) || !email_reg_exp.test(emailConfirm) || emailConfirm == "undefined" || emailConfirm == "" || email == "undefined" || email == "") { alert("Indirizzo email non valido!"); document.getElementById('email').select(); return false; } else if (email != emailConfirm) { alert("L'indirizzo email non coincide!"); document.getElementById('email').focus(); return false; } else if (pass.length < 6 || pass.length > 20) { alert("La password deve essere di almeno 6 caratteri alfanumerici e di massimo 20!"); document.getElementById('pass').focus(); return false; }else if (pass != passwordConfirm) { alert("La password non coincide!"); document.getElementById('passwordConfirm').value = ""; document.getElementById('passwordConfirm').focus(); return false; } else if (nome == "" || nome == "undefined") { alert("L'inserire nome!"); document.getElementById('nome').focus(); return false; } else if (surname == "" || surname == "undefined") { alert("L'inserire cognome!"); document.getElementById('surname').focus(); return false; } else if (telephone == "" || telephone == "undefined") { alert("L'inserire recapito telefonico!"); document.getElementById('telephone').focus(); return false; }else if (cell == "" || cell == "undefined") { alert("L'inserire recapito telefonico(cellulare)!"); document.getElementById('cell').focus(); return false; }else if (!condition) { alert("DEVI ACCETTARE LE CONDIZIONI PER ISCRIVERTI!"); document.getElementById('condition').focus(); return false; } } //--> </script> </head> <body> <form id = "register" method = "post" action = "addUser.php"> <table border = "0" align = "center"> <thead> <th rowspan = "1"> <label for = "email">Inserisci eMail di registrazione: </label> <div class="input-reg"><input id = "email" name = "email" type="text" /> </div></p> <label for = "pass">Scegli una Password: </label> <div class="input-reg"><input id = "pass" name="pass" type="password" /> </div></p> <label for = "nome">Nome: </label> <div class="input-reg"><input id = "nome" name = "nome" type="text" /> </div> </p> <label for = "telephone">Recapito telefonico: </label> <div class="input-reg"><input id = "telephone" name = "telephone" type="text" /> </div> </p> </th> <th rowspan = "1"> <label for = "emailConfirm">Conferma eMail: </label> <div class="input-reg"><input id = "emailConfirm" name = "emailConfirm" type="text" /> </div></p> <label for = "passwordConfirm">Conferma Password: </label> <div class="input-reg"><input id = "passwordConfirm" name="passwordConfirm" type="password" /> </div> </p> <label for = "surname">Cognome: </label> <div class="input-reg"><input id = "surname" name = "surname" type="text" /> </div></p> <label for = "cell">Recapito telefonico(cellulare): </label> <div class="input-reg"><input id = "cell" name = "cell" type="text" /> </div></p> </th> <div> </thead> </table> <div class="input-radio"> Dove sei venuto a conoscenza del nostro servizio web? </p> <label for = "howtosite" >In un nosto punto vendita </label> <input id = "howtosite" name = "howtosite" value = "pvendita" type = "radio"> <label for = "howtosite">Pubblicita' </label> <input id = "howtosite" name = "howtosite" value = "publicity" type = "radio"> <label for = "howtosite">Nel Web </label> <input id = "howtosite" name = "howtosite" value = "web" type = "radio"> <label for = "howtosite">Da un amico </label> <input id = "howtosite" name = "howtosite" value = "friend" type = "radio"> <label for = "howtosite">Altro </label> <input id = "howtosite" name = "howtosite" value = "other" type = "radio"> </p> </div> <div><label for = "condition"> In base alla legge 675/96 sulla tutela dei dati personali autorizzo il trattamento degli stessi per finalita' informative e/o pubblicitarie all'azienda </label> <input id = "condition" name = "condition" value = "Accept" type = "checkbox"/> </div> <div align = "center"><button type = "submit" id = "submit" value = "Register" onclick = "checkForms()">Registrati</button> </div> </form> </body> </html>
codice:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://w3.org/1999/xhtml"> <head> <title>Conferma Registrazione.</title> </head> <body> <?php extract( $_POST ); $email = $_REQUEST["email"]; $nome = $_REQUEST["nome"]; $surname = $_REQUEST["surname"]; $telephone = $_REQUEST["telephone"]; $cell = $_REQUEST["cell"]; $howtosite = $_REQUEST["howtosite"]; // Costruzione delle query $query = "INSERT INTO CLIENTI ". "(email,pass)". "VALUES ('$email','$pass')"; $query = "INSERT INTO DettClienti ". "(email,nome,surname,telephone,cell,howtosite)". "VALUES ('$email','$nome','$surname','$telephone','$cell','$howtosite')"; //Connessione a MySql if ( !($database = mysql_connect("localhost","root","") ) ) die( "Impossibile connettersi a MySql" ); //Connessione al Database if ( !($database = mysql_connect("eTakeAway", $database) ) ) die( "Impossibile connettersi al database" ); //Esecuzione della query if ( !($result = mysql_query($query,$database) ) ) { print ( "Impossibile eseguire la query " ); die( mysql_error() ); } ?> </body> </html>

Rispondi quotando
