LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-29-2004, 10:59 PM   #1
Gerardoj
Member
 
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465

Rep: Reputation: 30
PHP Trouble Syntax


Hi, Im having troubles with the following script: Where could be the problem? is in line 1?Error:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'word' at line 1

PHP Code:
<?php
if(!isset($query) || empty($query))
   {
$query "select * from MatchData";}
   
$query=stripslashes($query);

mysql_connect("mysql","admin","admin") or
    die(
"No Se pudo conectar a la base de datos");
mysql_select_db ("Data") or
    die(
"No Se pudo seleccionar la base de datos");
$result mysql_query($query) or
    die( 
mysql_error() );
    
$number_cols mysql_num_fields($result);

echo 
"<b>query: $query</b>";
echo 
"<table border = 1>\n";
echo 
"<tr align=center>\n";

for (
$i=0$i<$number_cols$i++)
{
    echo 
"<th>" mysql_field_name($result$i). "</th>\n";
}
echo 
"</tr>\n";
while (
$row mysql_fetch_row($result))
{
    echo 
"<tr align=left>\n";
    for (
$i=0$i<$number_cols$i++)
    {
        echo 
"<td>";
        if (!isset(
$row[$i]))
        {echo 
"NULL";}
        else
        {echo 
$row[$i];}
        echo 
"</td>\n";
        }
        echo 
"</tr>\n";
        }
    echo 
"</table>";
    
        
?>

<form action="<?php echo $PHP_SELF?>" method="get">
    <input type="text" name="query" size="50"><br>
    <input type="submit">
</form>
 
Old 03-30-2004, 09:20 AM   #2
Ohmu
LQ Newbie
 
Registered: Jan 2004
Location: Estonia
Distribution: Gentoo
Posts: 20

Rep: Reputation: 0
Hi!

Well.. I fixed your code.. and AFAIK it works.. so look at things I have changed (not much)

PHP Code:
<?
$query 
= ($_GET['query'] == "")?"select * from MatchData":$_GET['query'];
$query = (get_magic_quotes_gpc())?stripslashes ($query):$query;

mysql_connect("mysql""admin""admin") or die(mysql_error ());
mysql_select_db ("Database") or die(mysql_error ());
$result mysql_query($query) or die( mysql_error() );

$number_cols mysql_num_fields($result);

echo 
"<b>query: $query</b>";
echo 
"<table border = 1>\n";
echo 
"<tr align=center>\n";

for (
$i=0$i<$number_cols$i++)
{
    echo 
"<th>" mysql_field_name($result$i). "</th>\n";
}
echo 
"</tr>\n";
while (
$row mysql_fetch_row($result))
{
   echo 
"<tr align=left>\n";
   for (
$i=0$i<$number_cols$i++)
   {
      echo 
"<td>";
      if (!isset(
$row[$i]))
         echo 
"NULL";
      else
         echo 
$row[$i];
      echo 
"</td>\n";
   }
   echo 
"</tr>\n";
}
echo 
"</table>";
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="get">
    <input type="text" name="query" size="50"><br>
    <input type="submit">
</form>
If the above code gives errors about <??> etc tags, you should update PHP..

Last edited by Ohmu; 03-30-2004 at 09:22 AM.
 
Old 03-30-2004, 10:10 PM   #3
Gerardoj
Member
 
Registered: May 2003
Location: Somewhere over the Rainbow
Distribution: Slackware 9.x, Knoppix, Damn Small Linux, RedHat.
Posts: 465

Original Poster
Rep: Reputation: 30
Hey Thanks a lot. Now it works me perfectly...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
syntax highlighting for php in emacs bm1 Linux - Software 2 04-15-2017 05:29 AM
PHP Trouble to get Array Gerardoj Programming 5 03-28-2005 08:14 AM
If Then PHP syntax helpme DropHit Programming 1 07-07-2004 12:27 AM
PHP Array Trouble Gerardoj Programming 2 05-30-2004 10:53 PM
Apache + PHP = Trouble??? craddy Linux - General 5 01-26-2004 06:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration