wearefree Posted October 15, 2013 at 01:26 PM Report #529022 Posted October 15, 2013 at 01:26 PM boa tarde estou com uma pequena dificuldade em conseguir passar dados para a base de dados. isto é o index.php <?php $con=mysqli_connect("localhost","root","","index"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_query($con,"INSERT INTO registo (email, confirmaremail, password, confirmarpassword, nome, apelido) VALUES ('teste@gmail.com', 'teste@gmail.com', 'rui', 'rui', 'tio', 'yio')"); mysqli_query($con,"INSERT INTO registo (email, confirmaremail, password, confirmarpassword, nome, apelido) VALUES ('aloaloalo@gmail.com', 'aloaloalo@gmail.com', 'ruim', 'ruim', 'tiol', 'yiol'))"); mysqli_close($con); ?> isto é para chamar a base de dados depois tenho este codigo tambem que é o inserindo.php <?php $con=mysqli_connect("localhost","root","","index"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO registo (email, confirmaremail, password, confirmarpassword, nome, apelido) VALUES ('$_POST[email]','$_POST[confirmaremail]','$_POST[password]','$_POST[confirmarpassword]','$_POST[nome]','$_POST[apelidoin]')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?> na parte do html <form name="password_form" action="inserindo.php" method="POST"> <fieldset> <div> <label for="email"> <b>Email *</b></label> <input type="text" id="email" name="email" size="50" required></input> não coloco os outros campos pois são muitos e penso que basta o primeiro para perceber que o resto está tudo igual. quando carrego no botão submeter ele a pagina que aparece é o código do inserindo.php e não coloca nenhum registo na base de dados como posso resolver esta situação?
I-NOZex Posted October 15, 2013 at 01:59 PM Report #529030 Posted October 15, 2013 at 01:59 PM (edited) troca as ultimas linhas por estas: $res = mysqli_query($con,$sql); if (mysqli_affected_rows($res ) > 0){ echo "1 record added"; }else{ die('Error: ' . mysqli_error($con)); } essa é a maneira correcta de saberes se o registo foi ou nao enviado e se queres ajuda a resolver, coloca o resto do html... algo pode ter-te escapado... experimenta tambem trocar para isto: $sql="INSERT INTO registo (email, confirmaremail, password, confirmarpassword, nome, apelido) VALUES ('".$_POST['email']."','".$_POST['confirmaremail']."','".$_POST['password']."','".$_POST['confirmarpassword']."','".$_POST['nome']."','".$_POST['apelidoin']."')"; Edited October 15, 2013 at 02:03 PM by I-NOZex B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
Pivot Posted October 15, 2013 at 02:00 PM Report #529031 Posted October 15, 2013 at 02:00 PM Tens o apache instalado? Tens o PHP instalado? Se não tens faz download aqui do xampp: (Eu uso e recomendo - Já vem com o PhpMyAdmin (Gestor de BD's)) http://www.apachefriends.org/en/xampp.html Abraço, Rafael
wearefree Posted October 15, 2013 at 02:18 PM Author Report #529035 Posted October 15, 2013 at 02:18 PM viva rafael, eu uso o wamp continua igual aparece na mesma o código todo do inserindo.php :S Aqui está o meu codigo html <!DOCTYPE html> <html> <head> <script type="text/javascript" src="teste.js"></script> <script language="javascript" src="jquery.js"></script> <script language="javascript" src="passwordStrengthMeter.js"></script> <script language="javascript"> jQuery(document).ready(function() { $('#password').keyup(function(){$('#result').html(passwordStrength($('#password').val(),$('#username').val()))}) }) function showMore() { $('#more').slideDown() } </script> <script type="text/javascript"> <!-- function teste() { var carCode = event.keyCode; if ((carCode < 48) || (carCode > 57)) { alert('Por favor digite apenas números.'); event.cancelBubble = true event.returnValue = false; } } --> </script> </head> <body> <h3>Registe-se gratuitamente</h3> <p>Registe-se de forma fácil e rápida. O registo é rápido e grátis. </p> <form name="password_form" action="inserindo.php" method="POST"> <fieldset> <div> <label for="email"> <b>Email *</b></label> <input type="text" id="email" name="email" size="50" required></input> <br/> </div> <label for="confirmaremail"> <b>Confirmar Email *</b></label> <input type="text" id="confirmaremail" name="confirmaremail" size="50" required></input> </br> </div> <div class="style1" id='main'> <label for="password"> <b>Password *</b> </label> <input type="password" id="password" name="password" required onkeyup="verify.check()"></input><span style="color:green" id='result'></span> <br> </div> <div id='more' style="display:none;background-color:#EEEEEE;padding:10px;margin:10px;width:600px"> <ul type="disc"> <li dir="ltr"><strong>Score += password length * 4</strong></li> <li dir="ltr"><strong>Score -= repeated characters in the password</strong> ( 1 char repetition ) </li> <li dir="ltr"><strong>Score -= repeated characters in the password</strong> ( 2 char repetition ) </li> <li dir="ltr"><strong>Score -= repeated characters in the password</strong> ( 3 char repetition ) <span dir="rtl"> </span></li> <li dir="ltr"><strong>Score -= repeated characters in the password</strong> ( 4 char repetition ) <span dir="rtl"> </span></li> <li dir="ltr">If the password has 3 numbers then <strong>score += 5</strong></li> <li dir="ltr">If the password has 2 special characters then <strong>score += 5</strong></li> <li dir="ltr">If the password has upper and lower character then <strong>score += 10</strong></li> <li dir="ltr">If the password has numbers and characters then <strong>score += 15</strong></li> <li dir="ltr">If the password has numbers and special characters then <strong>score += 15</strong><span dir="rtl"> </span></li> <li dir="ltr">If the password has special characters and characters then <strong>score += 15</strong><span dir="rtl"> </span></li> <li dir="ltr">If the password is only characters then <strong>score -= 10</strong></li> <li dir="ltr">If the password is only numbers then <strong>score -= 10</strong></li> </ul> <ul type="disc"> <li dir="ltr">If score > 100 then <strong>score = 100</strong></li> </ul> <ul type="disc"> <li dir="ltr">If 0 < score < 34 then <strong>BadPassword</strong></li> <li dir="ltr">If 34 < score < 68 then <strong>GoodPassword</strong></li> <li dir="ltr">If 68 < score < 100 then <strong>StrongPassword</strong></li> </ul> </div> </div> <div> <label for="confirmarpassword"><b>Confirmar Password *</b> </label> ;<input type="password" id="confirmarpassword" name="confirmarpassword" required onkeyup="verify.check()"></input><span id="password_result"></span> <br> </div> <div class="registrationFormAlert" id="divCheckPasswordMatch"></div> <div> <label for="nome"><b>Nome *</b></label> ;<input type="text" id="nome" name="Nome" required></input><input type="text" id="nome" name="apelido" value="Apelido" required></input> <br> <div> <label for="Rua"><b>Rua / Nº</b></label> <input type="text" id="Rua" name="Rua" size="50"></input> <br> </div> <div> <label for="codigopostallocalidade"><b>Código Postal / Localidade</b></label> <input type="text" id="codigopostal" name="codigopostal"><input type="text" id="localidade" name="Localidade" size="30"></input> <br> </div> <label for="pais"><b>País</b></label> <select name="Pais"> <option value="Espanha">Espanha</option> <option value="Itália">Itália</option> <option value="Portugal" selected>Portugal</option> <option value="Inglaterra">Inglaterra</option> </select> <br> </div> <div> <label for="NIF"> <b>NIF</b></label> <input type="text" id="NIF" name="NIF" maxlength="9" onkeypress="teste()"></input> <br> </div> <div> <label for="telefone"><b>Telefone</b></label> <input type="text" id="telefone" name="Telefone" Value="Insira o número aqui."></input> <br> </div> <input type="submit" ></input> </fieldset> </form> <SCRIPT TYPE="text/javascript"> <!-- verify = new verifynotify(); verify.field1 = document.password_form.password; verify.field2 = document.password_form.confirmarpassword; verify.result_id = "password_result"; verify.match_html = "<SPAN STYLE=\"color:blue\">Password igual!<\/SPAN>"; verify.nomatch_html = "<SPAN STYLE=\"color:red\">A password não se coincide.<\/SPAN>"; // Update the result message verify.check(); // --> </SCRIPT> </body> </html>
I-NOZex Posted October 15, 2013 at 04:28 PM Report #529057 Posted October 15, 2013 at 04:28 PM qual é o output? B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
HappyHippyHippo Posted October 15, 2013 at 04:33 PM Report #529060 Posted October 15, 2013 at 04:33 PM (edited) continua igual aparece na mesma o código todo do inserindo.php :S só existe uma razão para que seja apresentado o código de um ficheiro PHP : o ficheiro não está a ser interpretado pelo servidor HTTP. por isso a questão recai na anteriormente efectuada pelo @Pivot: Tens o PHP instalado? à qual eu adiciono as segunites : - seguiste algum tutorial na instalação do WAMP ? - andas-te a mexer na configurações do Apache ? - andas-te a mexer na configurações do PHP ? Edited October 15, 2013 at 04:33 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
wearefree Posted October 15, 2013 at 05:13 PM Author Report #529072 Posted October 15, 2013 at 05:13 PM só existe uma razão para que seja apresentado o código de um ficheiro PHP : o ficheiro não está a ser interpretado pelo servidor HTTP. por isso a questão recai na anteriormente efectuada pelo @Pivot: à qual eu adiciono as segunites : - seguiste algum tutorial na instalação do WAMP ? - andas-te a mexer na configurações do Apache ? - andas-te a mexer na configurações do PHP ? eu utilizo o WAMP por causa do Drupal, e não andei a mexer nas configurações. se o ficheiro não está a ser interpretado pelo servidor HTTP, terei de instalar o XAMPP??
Devexz Posted October 15, 2013 at 10:30 PM Report #529114 Posted October 15, 2013 at 10:30 PM (edited) E se fizeres um echo dentro do ficheiro funciona? <?php echo "eu fou fixe"; ?> Edited October 15, 2013 at 10:31 PM by Devexz Contador de calorias: caloriaspordia.com
wearefree Posted October 16, 2013 at 01:26 AM Author Report #529120 Posted October 16, 2013 at 01:26 AM sempre que carrego no botão concluir, dá me sempre isto <?php $con=mysqli_connect("localhost","root","","index"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="INSERT INTO registo (email, confirmaremail, password, confirmarpassword, nome, apelido) VALUES ('".$_POST['email']."','".$_POST['confirmaremail']."','".$_POST['password']."','".$_POST['confirmarpassword']."','".$_POST['nome']."','".$_POST['apelido']."')"; $res = mysqli_query($con,$sql); if (mysqli_affected_rows($res ) > 0){ echo "1 record added"; }else{ die('Error: ' . mysqli_error($con)); } ?>
I-NOZex Posted October 16, 2013 at 08:54 AM Report #529129 Posted October 16, 2013 at 08:54 AM então é isso, nao tens um servidor apache+php+mysql a funcionar como deve de ser recomendo o easyphp http://easyphp.org/ leve, sem burocracias de configuraçoes... é instalar e ta pronto a andar B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
wearefree Posted October 16, 2013 at 09:36 AM Author Report #529131 Posted October 16, 2013 at 09:36 AM então é isso, nao tens um servidor apache+php+mysql a funcionar como deve de ser recomendo o easyphp http://easyphp.org/ leve, sem burocracias de configuraçoes... é instalar e ta pronto a andar mesmo assim está igual... acontece a mesma coisa como referi em cima
I-NOZex Posted October 16, 2013 at 02:47 PM Report #529217 Posted October 16, 2013 at 02:47 PM ja exprimentas-te o que este user disse? E se fizeres um echo dentro do ficheiro funciona? <?php echo "eu fou fixe"; ?> e tens o wampserver (seja qual for) a correr? ja reinicias-te o computador? exprimenta desinstalar tudo, correr o ccleaner ou similar (limpeza de ficheiros/limpeza de registo), reiniciar pc, instalar de novo, reiniciar, e voltar a testar... B2R » Beat2Revolution v3.0b | Regista e divulga-nos beat2revolution.net
Virneto Posted October 16, 2013 at 06:04 PM Report #529285 Posted October 16, 2013 at 06:04 PM @wearefree... vamos partir do príncipio que tens tudo muito bem instalado devidamente configurado... fazes assim: Desinstalas tudo e depois voltas aqui: ...recomendo o easyphp http://easyphp.org/ leve, sem burocracias de configuraçoes... é instalar e ta pronto a andar Depois segues a sugestão do @Devexz e colocas num ficheiro index.php o seguinte: <?php echo "eu sou fixe!"; ?> Queres ver que a máquina vai dizer que és fixe?!! 1 Report "Que inquieto desejo vos tortura, Seres elementares, força obscura? Em volta de que ideia gravitais?" >> Anthero de Quental - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Linuxando.com | ...
HappyHippyHippo Posted October 16, 2013 at 07:57 PM Report #529292 Posted October 16, 2013 at 07:57 PM Depois segues a sugestão do @Devexz e colocas num ficheiro index.php o seguinte: <?php phpinfo(); ?> aparece a informação de configuração do PHP ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now