Further help for PHP, SQL syntax, and register_globals

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ciao.
Ramil, Janet, Dan, and Matther thank you for your advice.
But problem still unsolved. Sorry for asking many questions.
My PHP-MySQL library database isnt working properly
(PHP and HTML scripts are the bottom of this message).

The problem seems to be "GO" (mySQL name)/"go" (PHP name),
because when I typed 100 in GO field in the HTML query page,
the following appeared in the result page:

Bad query: You have an error in your SQL syntax near 'and Tit like and Aut
like and Auty like ' at line 4

In contrast, when I typed 2000 in "dt" field ("ym" in MySQL), this appeared:

Bad query: You have an error in your SQL syntax near 'and ym like 2000 and
Tit like and Aut like and Auty like ' at line 3

The thing is Bad query doesnt say "GO like 100"!
As long as I see MySQL seems working correctly. I can do like "select * from
gen_table where id < 10"

Is this something related to the change of PHP 3 to 4?
I was given a database made by PHP3.0&MySQL3.23, and I upgraded it to PHP
4.3.
When I just used register_globals=ON, didnt use $_GET stuff, the database
worked perfectly,
but when I tried register_globals=OFF and use $_GET stuff, problem happens.

Any idea somebody, please??

-----------------------------------------
The script Im having a problem is here:

<html>
<body>
<TITLE>gen_search.php</TITLE>
<table border="1" align="center" BGCOLOR="#F2FEE0">
<tr>
<td align="right">ID</td>
<td align="center">Vol</td>
<td align="center">Date</td>
<td align="center">Title</td>
<td align="center">Author</td>
<td align="center">PageStart</td>
<td align="center">PageEnd</td>
<td align="center">Image</td>
</tr>

<?
mysql_connect(localhost,root,love);
mysql_select_db(gendai);
if (empty($_GET["go"]) &
    empty($_GET["dt"]) &
    empty($_GET["ti"]) &
    empty($_GET["au"]) &
    empty($_GET["ay"]))
{
 echo 'Type something';
}

elseif ($_GET["go"] == "%" |
        $_GET["dt"] == "%" |
        $_GET["ti"] == "%" |
        $_GET["au"] == "%" |
        $_GET["ay"] == "%")
{
 echo 'Not valid';
}

else {
  foreach ($_GET as $value) {
     if (empty($value)) $value = "%";
  }
$result = mysql_query("select * from gen_table
  where GO like ".$_GET["go"]."
    and ym like ".$_GET["dt"]."
   and Tit like ".$_GET["ti"]."
   and Aut like ".$_GET["au"]."
  and Auty like ".$_GET["ay"]."")
or die("Bad query: ".mysql_error());

$rows = mysql_num_rows($result);
echo $rows,"Records available<p>";

 while($row = mysql_fetch_array($result)){
  ?>
  <tr>
  <td align ="right"><A HREF = "gen_detail.php ?id=<? echo $row["ID"];
?>"><? echo $row["ID"]; ?></A></td>
  <td align ="right"><A HREF = "gen_search2.php ?go=<? echo $row["GO"];
?>"><? echo $row["GO"]; ?></A></td>
  <td><? echo $row["ym"];  ?></td>
  <td width="400"><? echo $row["Tit"]; ?></td>
  <td width="200"><? echo $row["Aut"]; ?></td>
  <td><? echo $row["sta"]; ?></td>
  <td><? echo $row["end"]; ?></td>
  <td>
    <?php   if($row["GO"] <= 500) {      ?>
      <A HREF="/momatlib/gendai/pdf/<? echo $row["GO"]; ?>.pdf">pdf</A>
    <?php   }    ?>
  </td>
  </tr>
  <?
   }
}
?>
</table>
</body>
</html>

-----------------------------------------------------------
And HTML here:
<html>
<body>

<TITLE>gen_menu.html</TITLE>
<BODY TEXT="#000000" LINK="#0000FF" VLINK="#008040" ALINK="#FF00FF">

<form action="gen_search2.php" method="get">
<table border="1" align="center" BGCOLOR="#F2FEE0">
<tr><td> Search</td><td align="center">Type</td><td
align="center">tips</td></tr>
<tr><td align="center">Volume</td><td><input type="text" name="go" size=
"10" maxlength= "10"></td><td></td></tr><p>
<tr><td align="center">Date</td><td><input type="text" name="dt" size= "10"
maxlength= "10"></td><td></td></tr><p>
<tr><td align="center">Title</td><td><input type="text" name="ti" size="60"
maxlength="60"></td><td></td></tr><p>
<tr><td align="center">Author</td><td><input type="text" name="au" size="60"
maxlength="60"></td><td></td></tr><p>
<tr><td align="center">Yomi</td><td><input type="text" name="ay" size="60"
maxlength="60"></td><td></td></tr><p>
<tr><td></td><td align="center"><a href="gen50.php">LINK</a></td><p>
</table><p>

<p align="center">
<input type="submit" value="Search">
<input type="reset"  value="Clear" ></P>

</form>
</body>
</html>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux