Jump to content

[SOLVED] can somebody give me a hint?


ionnnnutz

Recommended Posts

i'm not sure if this query is really ok:

$data = mysql_query("SELECT * FROM comp WHERE comp_am_id='.$user[id].' AND $field LIKE'%$find%'");

 

<?php
require("includes/connect.php");
require ("includes/checklogin.php");
include ('includes/header.php');

if ($logged_in == 0)
{
echo "Nu esti logat! ";
echo '<a href="login.php">Login</a>';
exit;
}

?>



<?php include ('includes/sidenav.php'); ?>
<div style="font-family: 'trebuchet ms'; font-size: 12px; color: #ffffff;">
<form name="search" method="post" action="<?=$PHP_SELF?>">
Cauta: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="comp_nume">Nume companie</option>
<Option VALUE="comp_adresa_sediu_localitate">Adresa sediu localitate</option>
<Option VALUE="comp_domeniu">Domeniu</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="cauta!" />
</form>
<?php

if ($searching =="yes")
{
echo "Rezultate <br>";


if ($find == "")
{
echo "Nu ai introdus termenul de cautat";
exit;
}



$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);




[color=red]$user3=("SELECT* FROM user WHERE user_username='".$_SESSION[username]."' ");
    	$user2=mysql_query($user3);
    	$user=mysql_fetch_array($user3);






$data = mysql_query("SELECT * FROM comp WHERE comp_am_id='.$user[id].' AND $field LIKE'%$find%'");
[/color]

while($result = mysql_fetch_array( $data ))
{
echo $result['comp_nume'];
echo " ";
echo $result['comp_adresa_sediu_localitate'];
echo " ";
echo $result['info'];
echo "<a href='detalii.php?ID=$result[comp_id]'>$result[comp_nume]</a>";
echo "<br>";
}


$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Nu am gasit termenul cautat!</div>";
}
}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/47700-solved-can-somebody-give-me-a-hint/
Share on other sites

i have 2 tables in database: one is "user" and the other is "comp". the link between these 2 tables is comp.comp_am_id = user.id .

when i want to search the database, is this php querry correct?

<form name="search" method="post" action="<?=$PHP_SELF?>">
Cauta: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="comp_nume">Nume companie</option>
<Option VALUE="comp_adresa_sediu_localitate">Adresa sediu localitate</option>
<Option VALUE="comp_domeniu">Domeniu</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="cauta!" />
</form>
<?php
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "Rezultate <br>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "Nu ai introdus termenul de cautat";
exit;
}



$user3=("SELECT* FROM user WHERE user_username='".$_SESSION[username]."' ");
    	$user2=mysql_query($user3);
    	$user=mysql_fetch_array($user3);
      	//this goes through all the entries that you selected





$data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% ");

<form name="search" method="post" action="<?=$PHP_SELF?>">
Cauta: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="comp_nume">Nume companie</option>
<Option VALUE="comp_adresa_sediu_localitate">Adresa sediu localitate</option>
<Option VALUE="comp_domeniu">Domeniu</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="cauta!" />
</form>
<?php
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "Rezultate <br>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "Nu ai introdus termenul de cautat";
exit;
}



$user3=("SELECT* FROM user WHERE user_username='".$_SESSION[username]."' ");
    	$user2=mysql_query($user3);
    	$user=mysql_fetch_array($user3);
      	//this goes through all the entries that you selected





$data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% ");

 

 

$data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% ");

try this  instead of the above:

$data = mysql_query("SELECT comp.comp_nume, comp.comp_am_id, user.id FROM comp, user WHERE comp.comp_am_id = user.id AND $field LIKE %$find% ") or error("Error executing query [$data]: " . mysql_error());

 

It will show the error.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.