index.php:
- Code: Select all
<link rel="icon" type="image/png" href="https://i.ibb.co/59gR5FP/icono-estatista-comunista.png">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase.js"></script>
<script src="https://apis.google.com/js/platform.js" async defer></script>
<nav class="navbar navbar-dark bg-dark">
<div id="linkslot_214396"><script src="https://linkslot.ru/bancode.php?id=214396" async></script></div>
<a class="navbar-brand" href="#">
Para continuar, necesitas registrarte en el chat:
<meta name="google-signin-client_id" content="464161591015-ljic3th229vojbf83esclvdsobfo95o5.apps.googleusercontent.com">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</a>
<div id="linkslot_214398"><script src="https://linkslot.ru/bancode.php?id=214398" async></script></div>
</nav>
<div class="form-control" rows="10" id="txt1"></div>
<form method="POST"action="index.php">
<input name="imgURL"type="hidden"id="inputIMGURL">
<input name="username"type="hidden"id="inputUserName">
<textarea class="form-control" id="txt2" rows="4" placeholder="Introduce aqui tu mensaje."name="message"></textarea>
<input type="submit" class="btn btn-primary" value="Enviar.">
</form>
<?php
$conexion=mysqli_connect("localhost","root","4624cmv4624","bd3");
if($conexion){
echo '<h1>conectado exitosamente</h1>';
if($_POST["imgURL"]&&$_POST["username"]&&$_POST["message"]){
$query=mysqli_query($conexion,"INSERT INTO mensajes VALUES('".$_POST["message"]."','".$_POST["imgURL"]."','".$_POST["username"]."');");
if($query){
echo '<h1>Fila insertada exitosamente.</h1>';
}else{
echo '<h1>Error de inserción.</h1>';
}
}
}else{
echo "<h1>error de conexion</h1>";
}
?>
<script>
onSignIn=(googleUser)=>{
profile=googleUser.getBasicProfile()
console.log('ID: ' + profile.getId()) // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName())
console.log('Image URL: ' + profile.getImageUrl())
console.log('Email: ' + profile.getEmail()) // This is null if the 'email' scope is not present.
render=()=>{
requestAnimationFrame(render)
inputIMGURL.value=profile.getImageUrl()
inputUserName.value=profile.getName()
}
prevResponse=""
loadDoc=()=>{
xhttp=new XMLHttpRequest()
xhttp.onreadystatechange=()=>{
if(this.readyState==4&&this.status==200&&prevResponse!=this.responseText){
document.getElementById("txt1").innerHTML=this.responseText
}
prevResponse=this.responseText
}
xhttp.open("GET","lectura.php",true)
xhttp.send()
}
render()
setInterval(loadDoc,1000)
}
</script>
<style>
#txt1 {
width: 100%;
height: 50%;
overflow: scroll;
}
</style>
lectura.php:
- Code: Select all
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<?php
$conexion=mysqli_connect("localhost","root","4624cmv4624","bd3");
if($conexion){
$lectura=mysqli_query($conexion,"SELECT * FROM `mensajes`");
if($lectura){
while($row=mysqli_fetch_row($lectura)){
echo <<<EOF
<table class="table">
<tr>
<td rowspan="2">
<img src="
EOF.$row[1].<<<EOF
"width="300"height="300"></img>
</td>
</tr>
<tr>
<td style="width:30px">
<b>
EOF.$row[2].<<<EOF
</b>
</td>
<td>
EOF.$row[0].<<<EOF
</td>
</tr>
</table>
EOF;
}
}else{
echo "Error de lectura.";
}
}else{
echo "Error de conexión.";
}
?>
And the error in the lectura.php file is the following:
Parse error: Invalid body indentation level (expecting an indentation level of at least 4) in C:\xampp\htdocs\utilidades\chat\lectura.php on line 12
And finally, the error in the index.php file is that the messages doesn't appear in the table. I did a xhr many times and tried to print "Hello world" into the chart and printed, but the xhr doesn't print because the URL is blocked or something...