Foro de elhacker.net

Programación => PHP => Mensaje iniciado por: colcrt en 5 Enero 2017, 06:26 am



Título: que hago mal? (jquery + php)
Publicado por: colcrt en 5 Enero 2017, 06:26 am
hola foreros  ;D
vengo a pedir de su gran ayuda, por mas que busco no logro entender que estoy haciendo mal en este pequeño codigo, veran estoy aprendiendo jquery por lo que aun se me dificulta bastante esto si alguno muy amable pudiera decirme donde esta el error le estaria muy agradecido, es un pequeño sistema de puntuación por estrellas

Código:
<div id="star-container" class="votacion">
<i class="fa fa-star star" id="star-1"></i>
<i class="fa fa-star star" id="star-2"></i>
<i class="fa fa-star star" id="star-3"></i>
<i class="fa fa-star star" id="star-4"></i>
<i class="fa fa-star star" id="star-5"></i>
</div>
<div id="result"></div>
<noscript>Necesitas tener habilitado javascript para poder votar</noscript>

Código:
<script>
$(document).ready(function(){
$('.star').on("mouseover",function(){

var star_id = $(this).attr('id');
switch (star_id){
case "star-1":
$("#star-1").addClass('star-checked');
break;
case "star-2":
$("#star-1").addClass('star-checked');
$("#star-2").addClass('star-checked');
break;
case "star-3":
$("#star-1").addClass('star-checked');
$("#star-2").addClass('star-checked');
$("#star-3").addClass('star-checked');
break;
case "star-4":
$("#star-1").addClass('star-checked');
$("#star-2").addClass('star-checked');
$("#star-3").addClass('star-checked');
$("#star-4").addClass('star-checked');
break;
case "star-5":
$("#star-1").addClass('star-checked');
$("#star-2").addClass('star-checked');
$("#star-3").addClass('star-checked');
$("#star-4").addClass('star-checked');
$("#star-5").addClass('star-checked');
break;
}
}).mouseout(function(){

$('.star').removeClass('star-checked');
});

$('.star').click(function(){

var star_index = $(this).attr("id").split("-")[1],
 
star_container = $(this).parent(),
result_div = $("#result");

$.ajax({
url: 'pages/rating_start.php',
type: 'POST',
data: {star:star_index},
beforeSend: function(){
star_container.hide();
result_div.show().html("<h6>Loading...</h6>");
}
})
.done(function(data){
result_div.html(data);
})
.fail(function(data) {
alert( "error" );
 })

});

});
</script>

Código:
<?php
    if(isset($_POST['star'])){
        $star = htmlentities(mysql_real_escape_string($_POST['star']));
        //valid star id array
        $valid_star = array('1','2','3','4','5');
 

        if(!in_array($star, $valid_star)){
            echo '<div class="alert alert-danger" role="alert">Porfavor no haga esto!</div>';
            exit();
        }
 
  
        echo '<div class="alert alert-success" role="alert">Gracias! '.$star.' Estrellas.</div>';
    }
?>

se queda en esta linea ""result_div.show().html("<h6>Loading...</h6>");"" y salta el error



Título: Re: que hago mal? (jquery + php)
Publicado por: ThinkByYourself en 5 Enero 2017, 07:53 am
Como consejo, puedes usar el console.debug para saber más acerca del error.


Título: Re: que hago mal? (jquery + php)
Publicado por: colcrt en 6 Enero 2017, 02:01 am
solo veo este error

Código:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)


Título: Re: que hago mal? (jquery + php)
Publicado por: engel lex en 6 Enero 2017, 02:54 am
Es un problema del php, está retornando código 500


Título: Re: que hago mal? (jquery + php)
Publicado por: colcrt en 6 Enero 2017, 03:10 am
 :huh: es un vps, que debiria ver o que archivo de configuracion editar? nose que hacer pls una ayuda


Título: Re: que hago mal? (jquery + php)
Publicado por: eLank0 en 6 Enero 2017, 10:42 am
Error 500, 90% error programacion servidor. Cual es el metodo al q llamas?


Título: Re: que hago mal? (jquery + php)
Publicado por: colcrt en 6 Enero 2017, 23:12 pm
hola, aun sigo sin poder solucionar esto  :-\ me puse a ver los log's y me tope con esto que podria ser??

Código:
Stack trace:
#0 {main}
  thrown in /var/www/html/pages/rating_start.php on line 3" while reading response header from upstream, client: xx.xx.xx.xx, server: www.xxxxxx.ga, request: "POST /pages/rating_start.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "www.xxxxxx.ga", referrer: "https://xxxxxx.ga/"
2017/01/06 00:50:21 [error] 1195#1195: *4076 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function mysql_real_escape_string() in /var/www/html/pages/rating_start.php:3
Stack trace:
#0 {main}
  thrown in /var/www/html/pages/rating_start.php on line 3" while reading response header from upstream, client: xx.xx.xx.xx, server: www.xxxxxx.ga, request: "POST /pages/rating_start.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "www.xxxxxx.ga", referrer: "https://xxxxxx.ga/"
2017/01/06 00:50:51 [error] 1195#1195: *4076 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function mysql_real_escape_string() in /var/www/html/pages/rating_start.php:3
Stack trace:
#0 {main}
  thrown in /var/www/html/pages/rating_start.php on line 3" while reading response header from upstream, client: xx.xx.xx.xx, server: www.xxxxxx.ga, request: "POST /pages/rating_start.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "www.xxxxxx.ga", referrer: "https://www.xxxxxx.ga/"
2017/01/06 01:00:16 [error] 1195#1195: *4101 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function mysql_real_escape_string() in /var/www/html/pages/rating_start.php:3
Stack trace:
#0 {main}
  thrown in /var/www/html/pages/rating_start.php on line 3" while reading response header from upstream, client: xx.xx.xx.xx, server: www.xxxxxx.ga, request: "POST /pages/rating_start.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "www.xxxxxx.ga", referrer: "https://www.xxxxxx.ga/"

y se repite varias veces...

edito ya encontre el error me di cuenta que "mysql_real_escape_string" esta en desuso por lo que daba ese error la cambie a "mysqli_real_escape_string" ahora se ya funciona  ;-) ;-) gracias chicos por su ayuda