Search Mysql record without using ? id=id in URL

Asked

Viewed 138 times

0

Guys, I’m trying not to use $_GET[] on the link, but I can’t find any way to make it happen. I mean, instead of "site.com/? post=name news" stay "site.com/name-news". I’ve already reviewed forums and Stack also looking for a solution, but I can’t find anything without it disappears "? post=" from the URL. The current code is this:

<?php
if(!@mysql_connect("localhost","root",""))
{
    die('ERRO NA CONEXÃO! --> '.mysql_error());
}
if(!mysql_select_db("site_novo"))
{
    die('NOME DB ERRADO--> '.mysql_error());
}
$video = $_GET['video'] ;
$videoId = $video;
$video_select = "SELECT * FROM video WHERE `id_video`='$video_select'";
$query = @mysql_query($video_select) or die (mysql_error());

if (mysql_num_rows($query) <= 0) {
    echo 'ESSE VÍDEO NÃO EXISTE AINDA';
}else{
    $vd = mysql_fetch_assoc($query);
    include_once "../assets/include/head_video.php";
}?>

RESOLUTION

<?php 
if(!@mysql_connect("localhost","root",""))
{
    die('ERRO NA CONEXÃO! --> '.mysql_error());
}
if(!mysql_select_db("site_novo"))
{
    die('NOME DB ERRADO--> '.mysql_error());
}
$video = $_SERVER['PATH_INFO'];
$muda_path = explode('/', $video );
foreach( $muda_path as $video_link )
{
    $videoID = $video_link;
    $video_select = "SELECT * FROM video WHERE `id_video`='$videoID'";
    $query = @mysql_query($video_select) or die (mysql_error());
}?>
  • What is the code of head_video.php ?

  • What you need is to implement the friendly URL system. URL Friendly concept and a more complete example. Full example

  • <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title><? php echo $Vd['titulo_video']; ? > - Player </title> <link rel="stylesheet" media="screen" href=".. /Assets/css/external_embed.css? v=2.25.5" /> </head>

  • Follow this link of Stack en-us that has been fixed. http://stackoverflow.com/questions/11722711/url-routing-regex-php

  • I actually said wrong, instead of the code you put in, which code, the link, that lead you to start these includes ?

  • Without using parameters, you can use $_SERVER["REQUEST_URI"] and $_SERVER["PATH_INFO"] variables depending on the context. This returns the path of the request. The only care is to have any path met by the same PHP, to process the information. Alternatively, if you use this syntax, you don’t even have to do anything complex: example.com/news.php/eneadactilo-e-preso-tentando-sair-do-pais , then all you need is one of the variables mentioned.

  • @Magichat is what I intend to use on multiple pages, and getting add the same head on each page does not help if you need to add or take out some css. That’s just the "embed page".

  • @Bacco, is there an example I can rely on?

  • the example is you save a file like news.php just with this line: <?php echo $_SERVER['PATH_INFO']; and access it as a.com/news.php/newsnumber-twelve address, to see how the variable behaves. Once you understand how it is filled in, then you make the logic for your select.

  • @Bacco I am exploring the $_SERVER['PATH_INFO']; here, I created a php called "test" and changed $video = $_GET['video'] ; for $video = $_SERVER['PATH_INFO'];, but it’s returning "/" together, I’ll try to blow up the "/" to get only the ID.

  • @Bacco, @Magichat, went like this <?php &#xA;if(!@mysql_connect("localhost","root",""))&#xA;{&#xA; die('oops connection problem ! --> '.mysql_error());&#xA;}&#xA;if(!mysql_select_db("site_novo"))&#xA;{&#xA; die('oops database selection problem ! --> '.mysql_error());&#xA;}&#xA;$video = $_SERVER['PATH_INFO'];&#xA;$palavras = explode('/', $video );&#xA;foreach( $palavras as $video_link )&#xA;{&#xA; $videoId = $video_link;&#xA; $leitura = "SELECT * FROM video WHERE id_video='$videoId'";&#xA; $query = @mysql_query($leitura) or die (mysql_error());&#xA;}&#xA;?> thanks a lot guys!!

  • https://answall.com/a/77846/28632

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.