Hello!!!
Well, here I am, 10 years after my last php script, trying to execute a simple SQL query in a DB... and I'm not able to know why it doesn't work. I'm very conscious that there are lots of errors, but I will be glad if you can tell me them and make a bit of explanation to understand them. Lots of years without upgrading my knowledge and I'm very lost.
As you can see, it's a single web that try to do the following:
Session is active when you can do a connection to my DB with a determinated user who has a few rights over certain tables (this works, but I can't detect when the connection fails, it gets stuck, seems that errno doesn't work as it should do).
After that, I want to retrieve every single register of a table with a certain flag (SQL query works OK directly in server, and in the future I'll do a more acurate version), and show some fields of each registry, while I want maintain hidden the id to pass it through a form button.
I cannot retrieve the data stored in the DB, NO ERROR APPEARS, it's very frustrating and I don't know why.
Can you help me, please?
Thanks.
<?php
session_start();
// Change this to your connection info.
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'myuser';
$DATABASE_PASS = 'hispassword';
$DATABASE_NAME = 'mydb';
// Try and connect using the info above.
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()){
// If there is an error with the connection, stop the script and display the error.
//Doesn't work, why is the server unable to process it?
echo('Failed to connect to MySQL: ' . mysqli_connect_errno());
$con->close();
session_destroy();
exit();
}
else{
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
$_SESSION['name'] = $DATABASE_USER;
$_SESSION['id'] = $id;
echo 'Bienvenido ' . $_SESSION['name'] . '!';
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Listas</title>
<link href="./CSS/basic_style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="titulo">
<h1>Cursillos disponibles</h1>
</div>
<div class="content">
<form action="comprar.php" name="comprar" method="post">
<table name="contents" width="100%">
<tr>
<th>Título</th>
<th>Subtítulo</th>
<th>Descripción</th>
<th>Importe (€)</th>
<th>Adquirir</th>
</tr>
<?php
$resultado = $con->excute_query("SELECT * FROM cursillo where cursillo.activo='0'", MYSQLI_USE_RESULT);
foreach ($resultado as $fila) {
echo $fila[1];
?>
</td>
<td>
<?php
echo $fila[2];
?>
</td>
<td>
<?php
echo $fila[3];
?>
</td>
<td>
<?php
echo $fila[4];
?>
</td>
<td>
<input type="submit" name="pagar" value="<?php$fila[0]?>">
</td>
</tr>
<?php
}
mysql_free_result($resultado);
$con->close();
?>
</table>
</form>
</div>
</body>
</html>