I'm working on a project that I would like to get an answer as soon as possible.
Problem: I have a project I'm doing. In this project, there will be events to buy tickets. The index will show all the records of the SQL database. When the event is clicked, only the information of the selected project will appear. However, this is where the problem lies. When I click on an event in the Index, it goes to the individual page of the product, but on that page, only the information of the first record always appears. Even if I click on another event in the index, the information from the first record will always appear on the individual page. (Example: The id 4 and 5 appear in the index. However, when I click on event 5, the information of id 4 will always appear on the page "eventoindividual.php". I would like your best attention to solve the problem.
[DATABASE SQL]
https://i.stack.imgur.com/KtoUQ.png
index.php
<?php
session_start();
require('config.php');
if(!$con){
header('location:erro.php');
}
$sql=sprintf("SELECT * FROM eventos ORDER BY id DESC LIMIT 8");
$res=mysqli_query($con,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="logotipoicon.png" />
<!-- ==========================
Meta Tags
=========================== -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- ==========================
Title
=========================== -->
<title>shop</title>
<!-- ==========================
Fonts
=========================== -->
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,200,200italic,300,300italic,400italic,600,600italic,700,700italic,900,900italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,900,800' rel='stylesheet' type='text/css'>
<!-- ==========================
CSS
=========================== -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
<link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/dragtable.css" rel="stylesheet" type="text/css">
<link href="assets/css/owl.carousel.css" rel="stylesheet" type="text/css">
<link href="assets/css/animate.css" rel="stylesheet" type="text/css">
<link href="assets/css/color-switcher.css" rel="stylesheet" type="text/css">
<link href="assets/css/custom.css" rel="stylesheet" type="text/css">
<link href="assets/css/color/red.css" id="main-color" rel="stylesheet" type="text/css">
<!-- ==========================
JS
=========================== -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- ==========================
SCROLL TOP - START
=========================== -->
<div id="scrolltop" class="hidden-xs"><i class="fa fa-angle-up"></i></div>
<!-- ==========================
SCROLL TOP - END
=========================== -->
<!-- ==========================
COLOR SWITCHER - START
=========================== -->
<!-- ==========================
COLOR SWITCHER - END
=========================== -->
<div id="page-wrapper"> <!-- PAGE - START -->
<!-- ==========================
HEADER - START
=========================== -->
<div class="top-header hidden-xs hidden">
<div class="container">
<div class="row">
<div class="col-sm-5">
<ul class="list-inline contacts">
<li><i class="fa fa-envelope"></i> [email protected]</li>
<li><i class="fa fa-phone"></i> +1111111111</li>
</ul>
</div>
<div class="col-sm-7 text-right">
<ul class="list-inline links">
<li><a href="my-account.html">Minha Conta</a></li>
<li><a href="checkout.html">Checkout</a></li>
<li><a href="wishlist.html">Lista de Desejos</a></li>
<li><a href="compare.html">Comparar</a></li>
<li><a href="signin.html">Logout</a></li>
</ul>
</div>
</div>
</div>
</div>
<header class="navbar navbar-transparent navbar-fixed-top">
<div class="container" style="width: 50%;">
<div class="navbar-header">
<a href="index.php" class="navbar-brand"> <img src="logotipo.png"> </a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> <i class="fa fa-bars"></i> </button>
</div>
<!-- <div class="teatroarte"><img src="opcoes/teatroarte.png"></div>
<div class="musicafestivais"><img src="opcoes/musicafestivais.png"></div>
<div class="familia"><img src="opcoes/familia.png"></div>
<div class="quatro"><img src="opcoes/desportoaventura.png"></div> -->
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
</li>
<li class="dropdown navbar-cart hidden-xs">
<a href="carrinho.php" class="dropdown-toggle" data-toggle="dropdown" data-hover="dropdown" data-delay="300" data-close-others="true"><i class="fa fa-shopping-cart"></i></a>
<ul class="dropdown-menu">
<li>
<div class="row">
<div class="col-sm-6">
<a href="carrinho.php" class="btn btn-primary btn-block">Ver carrinho</a>
</div>
<div class="col-sm-6">
<a href="checkout.html" class="btn btn-primary btn-block">Finalizar</a>
</div>
</div>
</li>
<!-- CART ITEM - END -->
</ul>
</li>
<li class="dropdown navbar-search hidden-xs">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-search"></i></a>
<ul class="dropdown-menu">
<li>
<form>
<div class="input-group input-group-lg">
<input type="text" class="form-control" placeholder="Pesquisar...">
<span class="input-group-btn">
<button class="btn btn-primary" type="button">Pesquisar</button>
</span>
</div>
</form>
</li>
</ul>
</li>
<li class="dropdown">
<a href="signin.php" class="fa fa-user" data-toggle="dropdown" data-hover="dropdown" data-delay="300" data-close-others="true"></a>
<ul class="dropdown-menu">
<li><a href="signin.php">Iniciar Sess??o</a></li>
<li><a href="signup.php">Criar Conta</a></li>
</ul>
</li>
</ul>
</div>
</div>
</header>
<!-- ==========================
HEADER - END
=========================== -->
<!-- ==========================
JUMBOTRON - START
=========================== -->
<section class="content jumbotron jumbotron-full-height">
<div id="homepage-2-carousel" class="nav-inside">
<div class="item slide-1">
<div class="slide-mask"></div>
<div class="slide-body">
</div>
</div>
<div class="item slide-2">
<div class="slide-mask"></div>
<div class="slide-body">
</div>
</div>
<div class="item slide-3">
<div class="slide-mask"></div>
<div class="slide-body">
</div>
</div>
<div class="item slide-4">
<div class="slide-mask"></div>
<div class="slide-body">
</div>
</div>
<div class="item slide-5">
<div class="slide-mask"></div>
<div class="slide-body">
</div>
</div>
<div class="item slide-6">
<div class="slide-mask"></div>
<div class="slide-body">
</div>
</div>
</div>
</section>
<!-- ==========================
JUMBOTRON - END
=========================== -->
</div>
<!-- ==========================
RECENT BLOG POSTS - START
=========================== -->
<section class="content recent-blog-posts">
<div class="container">
<div class="section-title">
<br>
<h2 id="ultimasnovidades">??LTIMAS NOVIDADES</h2>
<p>Encontra aqui as ??ltimas novidades anunciadas.</p>
<br>
</div>
<div class="row">
<?php
while($reg=mysqli_fetch_array($res)){
$sql_consulta=sprintf("select * from eventos where id=%d;",$reg['id']);
$res_consulta=mysqli_query($con,$sql_consulta);
$_SESSION['idevento'] = $reg['id'];
$reg_consulta=mysqli_fetch_array($res_consulta);
$link='eventoindividual.php?id='.$reg_consulta['id'];
?>
<div class="col-xs-6 col-sm-3">
<article class="post">
<a href="<?php echo $link; ?>"> <img src="<?php echo 'admin/documentos/'.$reg['nome_doc']; ?>" class="img-responsive" alt=""> </a>
<h3><a href="<?php echo $link; ?>"><?php echo $reg['nome']; ?></a></h3>
<span class="date"><?php echo $reg['data']; ?></span>
</article>
</div>
<?php
}
?>
</div>
</div>
</section>
eventoindividual.php
<?php
session_start();
require('config.php');
if(!$con){
header('location:erro.php');
}
$sql=sprintf("select * from eventos where id = '".$_SESSION['idevento']."'");
$res=mysqli_query($con,$sql);
?>
<!DOCTYPE html>
<html>
<head>
<!-- ==========================
Meta Tags
=========================== -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- ==========================
Title
=========================== -->
<title>shop</title>
<!-- ==========================
Fonts
=========================== -->
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,200,200italic,300,300italic,400italic,600,600italic,700,700italic,900,900italic&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Raleway:400,100,200,300,500,600,700,900,800' rel='stylesheet' type='text/css'>
<!-- ==========================
CSS
=========================== -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
<link href="assets/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="assets/css/dragtable.css" rel="stylesheet" type="text/css">
<link href="assets/css/owl.carousel.css" rel="stylesheet" type="text/css">
<link href="assets/css/animate.css" rel="stylesheet" type="text/css">
<link href="assets/css/color-switcher.css" rel="stylesheet" type="text/css">
<link href="assets/css/custom.css" rel="stylesheet" type="text/css">
<link href="assets/css/color/red.css" id="main-color" rel="stylesheet" type="text/css">
<!-- ==========================
JS
=========================== -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- ==========================
SCROLL TOP - START
=========================== -->
<div id="scrolltop" class="hidden-xs"><i class="fa fa-angle-up"></i></div>
<!-- ==========================
SCROLL TOP - END
=========================== -->
<!-- ==========================
COLOR SWITCHER - START
=========================== -->
<!-- ==========================
COLOR SWITCHER - END
=========================== -->
<div id="page-wrapper"> <!-- PAGE - START -->
<!-- ==========================
HEADER - START
=========================== -->
<div class="top-header hidden-xs hidden">
<div class="container">
<div class="row">
<div class="col-sm-5">
<ul class="list-inline contacts">
<li><i class="fa fa-envelope"></i> [email protected]</li>
<li><i class="fa fa-phone"></i> +111111111</li>
</ul>
</div>
<div class="col-sm-7 text-right">
<ul class="list-inline links">
<li><a href="my-account.html">Minha Conta</a></li>
<li><a href="checkout.html">Checkout</a></li>
<li><a href="wishlist.html">Lista de Desejos</a></li>
<li><a href="compare.html">Comparar</a></li>
<li><a href="signin.html">Logout</a></li>
</ul>
</div>
</div>
</div>
</div>
<hr id="hrlogotipo">
<!-- ==========================
HEADER - END
=========================== -->
<!-- ==========================
BREADCRUMB - START
=========================== -->
<?php
while($reg=mysqli_fetch_array($res)){
$sql_consulta=sprintf("select * from utilizadores where id=%s;",$reg['id']);
$res_consulta=mysqli_query($con,$sql_consulta);
$reg_consulta=mysqli_fetch_array($res_consulta);
?>
<section class="breadcrumb-wrapper">
<div class="container">
<div class="row">
<div class="col-xs-6">
<h2><?php echo $reg['tipoevento']; ?></h2>
<p><?php echo $reg['artista']; ?></p>
</div>
<div class="col-xs-6">
<ol class="breadcrumb">
<li><a href="index.php">Inicio</a></li>
<li class="active"><a href="eventoindividual.php"> <?php echo $reg['nome']; ?> </a></li>
</ol>
</div>
</div>
</div>
</section>
<!-- ==========================
BREADCRUMB - END
=========================== -->
<!-- ==========================
PRODUCTS - START
=========================== -->
<section class="content products">
<div class="container">
<article class="product-item product-single">
<div class="row">
<div class="col-xs-4">
<div class="product-carousel-wrapper">
<div>
<img src="<?php echo 'admin/documentos/'.$reg['nome_doc']; ?>" style="width: 370px;">
<br>
<br>
</div>
</div>
</div>
<div class="col-xs-8">
<div class="product-body">
<h2 style="color: #337ab7;"><b><?php echo $reg['nome']; ?></b></h2>
<hr id="nomeevento">
<span class="price">
<ins><span class="amount"><b><?php echo $reg['preco']; ?></b></span></ins>
</span>
<hr>
<ul class="list-unstyled product-info">
<li style="color: #337ab7;"><span style="color: black;"><b>ID</b></span><?php echo $reg['id']; ?></li>
<li style="color: #337ab7;"><span style="color: black;"><b>Classifica?�??o</b></span><?php echo $reg['classificacao']; ?></li>
<li style="color: #337ab7;"><span style="color: black;"><b>Sess?�es</b></span><?php echo $reg['data']; ?> - <?php echo $reg['hora']; ?></li>
<li style="color: #337ab7;"><span style="color: black;"><b>Disponibilidade</b></span><?php echo $reg['estado']; ?></li>
<li style="color: #337ab7;"><span style="color: black;"><b>Promotor</b></span><?php echo $reg['promotor']; ?></li>
</ul>
<hr>
<h3 style="color: black"><b><?php echo $reg['1titulodescricao']; ?></b></h3>
<p><?php echo $reg['primeiradescricao']; ?> </p>
<div class="product-form clearfix">
<div class="row row-no-padding">
<div class="col-md-3 col-sm-4">
<div class="product-quantity clearfix">
<a class="btn btn-default" id="qty-minus">-</a>
<input type="text" class="form-control" id="qty" value="1">
<a class="btn btn-default" id="qty-plus">+</a>
</div>
</div>
<div class="col-md-3 col-sm-4">
<div class="product-size">
<form class="form-inline">
<div class="form-group">
<label>Size:</label>
</div>
<div class="form-group">
<select class="form-control">
<option>XS</option>
<option>S</option>
<option selected="selected">M</option>
<option>L</option>
<option>XL</option>
<option>XXL</option>
</select>
</div>
</form>
</div>
</div>
<div class="col-md-3 col-sm-4">
<div class="product-color">
<form class="form-inline">
<div class="form-group">
<label>Color:</label>
</div>
<div class="form-group">
<select class="form-control">
<option selected="selected">Black</option>
<option>White</option>
<option>Red</option>
<option>Yellow</option>
</select>
</div>
</form>
</div>
</div>
<div class="col-md-3 col-sm-12">
<a href="" class="btn btn-primary add-to-cart"><i class="fa fa-shopping-cart"></i>Comprar</a>
</div>
</div>
</div>
<ul class="list-inline product-links">
<li><a href="#"><i class="fa fa-heart"></i>Add to wishlist</a></li>
<li><a href="#"><i class="fa fa-exchange"></i>Compare</a></li>
<li><a href="#"><i class="fa fa-envelope"></i>Email to friend</a></li>
</ul>
</div>
</div>
</div>
<div class="tabs product-tabs">
<ul class="nav nav-tabs" role="tablist">
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#description" role="tab" data-toggle="tab" aria-controls="description" aria-expanded="false">Descri?�??o</a></li>
<li role="presentation" class=""><a href="#video" role="tab" data-toggle="tab" aria-controls="video" aria-expanded="false">Video de apresenta?�??o</a></li>
</ul>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active in" id="description">
<h3><b><?php echo $reg['2titulodescricao']; ?></b></h3>
<p><?php echo $reg['segundadescricao']; ?> </p>
</div>
<div role="tabpanel" class="tab-pane" id="reviews">
<div class="comments">
<?php
}
?>
<div class="releated-products">
<h2>Eventos Relacionados</h2>
<div class="row grid" id="products">
<!-- PRODUCT - START -->
<div class="col-sm-3 col-xs-6">
<article class="product-item">
<div class="row">
<div class="col-sm-3">
<?php
$sqli=sprintf("SELECT * FROM eventos ORDER BY id DESC LIMIT 8");
$resu=mysqli_query($con,$sqli);
mysqli_set_charset($con, 'UTF8');
while($regi=mysqli_fetch_array($resu)){
$sqli_consulta=sprintf("select * from eventos where id=%d;",$regi['id']);
$resu_consulta=mysqli_query($con,$sqli_consulta);
$regi_consulta=mysqli_fetch_array($resu_consulta);
$linkk='eventoindividual.php?id='.$regi_consulta['id'];
?>
<div class="product-overlay">
<div class="product-mask"></div>
<a href="single-product.html" class="product-permalink"></a>
<img src="<?php echo 'admin/documentos/'.$regi['nome_doc']; ?>" style="width:100%">
</div>
</div>
<div class="col-sm-9">
<div class="product-body">
<h3><?php echo $regi['nome']; ?></h3>
<span class="price">
<ins><span class="amount"><?php echo $regi['preco']; ?></span></ins>
</span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut feugiat mauris eget magna egestas porta. Curabitur sagittis sagittis neque rutrum congue. Donec lobortis dui sagittis, ultrices nunc ornare, ultricies elit. Curabitur tristique felis pulvinar nibh porta. </p>
<div class="buttons buttons-simple">
<a href=""><i class="fa fa-exchange"></i></a>
<a href=""><i class="fa fa-shopping-cart"></i></a>
<a href=""><i class="fa fa-heart"></i></a>
</div>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
<?php
}
?>
</div>
i think that you are taking the wrong id in your " eventoindividual.php "
Replace the following line ( L.7 )
$sql=sprintf("select * from eventos where id = '".$_SESSION['idevento']."'");
By
$sql=sprintf("select * from eventos where id = '".$_GET['id']."'");
This way you take the correct id from the URL and not the SESSION
Have a nice day !
I just got it!!! It's not "idevento" but just "id". In the end, it was $_GET['id'];
Thanks for the help :D
I guess the problem is on this line :
$sql=sprintf("select * from eventos where id = '".$_SESSION['idevento']."'");
Because you did not send the data (idevento) by SESSION , but you actually sent it using GET method
The best solution is to replace '$_SESSION['idevento']' by '$_GET['idevento']'
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
JQuery is arguably the most popular JavaScript library with so many features for modern development. JQuery is a fast and concise JavaScript library created by John Resig in 2006. It is a cross-platform JavaScript library designed to simplify client-side HTML scripting. Over 19 million websites are currently using jQuery! Companies like WordPress, Facebook, Google, IBM and many more rely on jQuery to provide a kind of web browsing experience.
https://jquery.com/
DBMS is a database management system. It is designed to change, search, add and delete information in the database. There are many DBMSs designed for similar purposes with different features. One of the most popular is MySQL.
It is a software tool designed to work with relational SQL databases. It is easy to learn even for site owners who are not professional programmers or administrators. MySQL DBMS also allows you to export and import data, which is convenient when moving large amounts of information.
https://www.mysql.com/
CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.
https://www.w3.org/TR/CSS/#css
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
There are several libraries that do almost the same thing: add one or more animations to a specified element. The first such library to gain popularity in recent years was Dan Eden's Animate.css. This fun library contains dozens of built-in animations that shake, fade, slide, scale, and more.
https://animate.style/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.