0

I want create php file that show a db all row's, i look at the internet but there "$" is syntax error, and other variable i didn't find.

Here's my php code :

    if(isset($_POST['search'])) {
$searchq = $_POST['search']; };


$query = 'SELECT * FROM serviss WHERE pasutijuma_nummurs =$searchq ';

I tried put in

$query = 'SELECT * FROM serviss WHERE pasutijuma_nummurs ='·$searchq' ';

But query didn't work at all.

And here's my HTML form:

<form action="search.php" method="POST">
 Meklēt pēc pasūtijuma nummura  <input type="text" name="search ">
 <input type="submit" value="Search"/>
</form>

I hope someone can help me.

Fixed that problem :

$result = pg_query($db, "SELECT * FROM serviss where pasutijuma_nummurs = '$_POST[search]'");
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

2 Answers2

3

Remove ; at the end of if statement. And double quote your query.

if (isset($_POST['search'])) {
    $searchq = $_POST['search'];

    $query = "SELECT * FROM serviss WHERE pasutijuma_nummurs = '$searchq'";
}

Do not forget to use prepared statements.

N'Bayramberdiyev
  • 5,936
  • 7
  • 27
  • 47
0

You can try this:

$query = "SELECT * FROM serviss WHERE pasutijuma_nummurs = '{$searchq}'";

But first you need validate your data. Hope help you.

Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42