Well here with a doubt:
I currently have a user rating system.
My question is how could I save the id of the user I want to qualify for, so that after doing a SELECT I bring in console all the comments and the rating that user has.
The code is like this:
<?php
session_start();
require'conexion.php';
if(!isset($_SESSION["id_usuario"])){
header("Location: index.php");
}
?>
<?php
$sql = "SELECT id FROM usuarios WHERE id = ?";
$id = $_GET['id'];
$stmt = $mysqli->prepare($sql);
if ($stmt) {
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->store_result();
$statement = mi_fetchassoc($stmt);
}
function mi_fetchassoc($stmt)
{
if($stmt->num_rows>0)
{
$rs = array();
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params[] = &$rs[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
if($stmt->fetch())
return $rs;
}
return null;
}
?>
<?php
require "conexion.php";
if(isset($_POST)){
if(mysqli_query($mysqli,"INSERT INTO comentarios (comentario, rating, usuario, fecha, id_us) VALUES ('".$_POST['comentario']."', '".$_POST['rating']."', '".$_SESSION['id_usuario']."', NOW(), '".$statement['id']."')")){
echo "1";
}else{
echo "2";
}
}
?>
Where:
Comment: it's the buyer's opinion.
Rating: is the value from 1 to 5 in qualification.
User: Here I save the user id of the current session. BUYER
Date: the now brings the current date.
id_us: Here I want to save the id of the user I am qualifying to and where the error is marked. SELLER
TABLE of comments:
id primary key int (11) auto increment not null,
comment varchar (100) not null,
rating int (11) not null,
user varchar (30) not null,
datetime default null date,
id_us int (11)
TABLE users:
id int (11) primary key not null auto_increment,
user varchar (30) not null,
email varchar (30) not null,
pw varchar (30) not null,
name varchar (30) not null.
I hope someone can solve this doubt.
Thank you.