Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query 1

Status
Not open for further replies.

murushanmugham

IS-IT--Management
Jan 2, 2003
33
0
0
Hello

I have a table with a field name as course and another as subject

the field contains data like this

Record 1
Course='M.D.-PHARMACY'
Subject='APPLIED SCIENCES'

Record 2
Course='M.S.-GENERAL SURGERY'
Subject='APPLIED BASIC SCIENCE'

I use the following

select * from tablename where fname='".$xcourse."' and subject='".$xsub."' order by year desc;


Where I have a course with two words ie. 'M.S.-GENERAL SURGERY' , no records are selected.

Whereas for course ='M.D.-PHARMACY' works fine.

How do I solve this please help

This query works fine in mysql and not when used in a PHP script

 
Can we see the rest of your script, or at least enough that shows the problem?

If you echo the query before the executing it, does it look right?

Do you have error checking on you mysql function calls?

Ken
 
are the values passed through a form ?? in that case you need to urlencode the variable first

otherwise you get something like
'M.S.-GENERAL%20SURGERY'
 
Here is code which i am using


$connection=mysql_connect("","","")
or die("A connection to the Server could not be established !");

$createdb=mysql_select_db("quesbank")or die("database could not be created");

$cou=$_REQUEST['txtcourse'];
$sub=$_REQUEST['subject'];

$sqlquery="select * from qb where fname='".$cou."' and subject='".$sub."' order by year desc";

$queryresult=mysql_query($sqlquery,$connection);
$nrows=mysql_num_rows($queryresult);

if($nrows==0)
{
echo "<script>alert(\"Not a existing project\");
history.back();
</script>";
}if ($nrows!=0)
{
?>

<table bgcolor=white width="75%">
<tr>
<td width=25%><FONT SIZE="4" COLOR="black"><b>Course</b></font> : <b><? print $cou; ?></b> </td>
<td width=50%><FONT SIZE="4" COLOR="black"><b>Subject</b></font> : <b><? print $sub; ?></b>
</td></tr>


 
try this and post back what you get:

Code:
...
$sqlquery="select * from qb where fname='".$cou."' and subject='".$sub."' order by year desc";  
[red]echo $sqlquery;[/red]
...

Tell us what the red line produces.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top