-3

I made a search form to get the profile of people whom i search the name with, the form is down here and it works

form file is named search.php and output file is result.php so literally the way the output link must be shown like http://localhost/website/result.php?user=Name but what i'm getting is http://localhost/website/result.php

which causes not to copy the profile link and show it to to others or apparently it doesnt work when i go to the first link [result.php?user=Name], which directs me to index.php

search.php

<form method="post" action="test.php">
    <center><h3>YGG Live Player Stats</h3></center>
    <h5>Enter Player name :<h5> <br/><br/><input type="text" name="search" size=50 maxlength=50><br/><br/>
    <input type="Submit" name="Search" value="Search">
</form>

This is the result.php code down here, in which you could see index.php there is what it is actually taking me when i go to links like this http://localhost/website/result.php?user=Name

<?php
session_start();
if(isset($_POST['search']))
{
include "koneksi.php";
$query = $koneksi->prepare("SELECT * from `playerdata` where `user` = ?");
$query->execute(array($_POST['search']));
if($query->rowCount() > 0)
{
    $data = $query->fetch();
?>

//html code here

<?php
}
else
{
    go('index.php', 'Username not found!!!');
}
}
else
{
    header("Location:index.php");
}
?>

How can i fix it?

Prabin
  • 33
  • 7
  • The values won't be passed in the query string like you say, because the `
    ` is using the 'POST' method. The issue you're experiencing may be due to your SQL being incomplete without binding a value to the `user` field in the `WHERE` clause.. What is the 'koneksi.php' file and variable?
    – Callan Heard Sep 10 '15 at 16:53

3 Answers3

0

That's pretty basic stuff so you should definitely spend some more time with tutorials.

You are sending your form with POST so values will not be visible in URL. To change that simply use GET method and every value from form will appear in result URL.

Elon Than
  • 8,984
  • 4
  • 22
  • 37
0

You are using method="post" in the form.

If you want your url to be like http://localhost/website/result.php?user=Name then you must change method="post" to method="get" in search.php and use $_GET['search'] instead of $_POST['search'] in result.php.

For more informations: What is the difference between POST and GET?

Community
  • 1
  • 1
Fi Ras
  • 741
  • 9
  • 24
0

The values won't be passed in the query string like you say, because the <form> is using the 'POST' method. The issue you're experiencing may be due to your SQL being incomplete without binding a value to the user field in the 'WHERE' clause.. I realised 'koneksi.php' must be generating your connection object, so try adding:

$koneksi->bind_param("s", $_POST['id']);

before executing the query, and remove array($_POST['search']) from the execution call.

Callan Heard
  • 707
  • 8
  • 18