Ask a Question related to PHP Development, Design and Development.
-
ian justice #1
"Select" & "Order By" OK- ''WHERE'' Does'nt Work !
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've reduced my form request to a simple text string
entry, instead of my desired optional parameters. As i have been stuck
with a single unfathomable glitch for over a year.
Basically, if i enter queries such as ;
"select * from table" "select * from table order by artist",
it works perfectly. However if i introduce the 'where' option, as in
"select * from table where artist like whatever". It comes back with
"could not execute query". This happens even if i append "order by" to
it.
I'll post all the various codes if anyone can please help.
ian justice Guest
-
Proj cannot run on LCDS 2.6 ES due to "Unable to resolveresource bundle "datamanagement" for locale "en_US"
hi, all, We have developped an application on Flex Build 3 (run successfully), but failed when we try to deploy it on Tomcat with LCDS 2.5 ES... -
CFINPUT type="radio" w/ "value" requires "label"
On a Flash form, when you specify type='radio' and value='whatever', the value of the 'value' attribute will be displayed as a label if no 'label'... -
FScommand("Exec","myapplication.exe") doesnot work on Trial version MX?
i think projector in this case is meant to be a .exe file not a test.swf like you mentioned. goto File, Publish Settings... and there under the... -
"Start" "Program" "Menu" list is empty
For what ever reason my list of installed programs in my "Start" "Programs" menu is empty. Anyone know how to restore the list. Thanks for your... -
How to make the "search text" feature work with non "txt" file
On Fri, 27 Jun 2003 07:19:23 -0700, "Juergen" <anhorn@bktel.com> wrote: See MVP Doug Knox' comments and fix here:... -
Tom Thackrey #2
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
On 31-Oct-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
I teach students how to program. Almost every student is convinced, at one> Before i post actual code, as i need a speedyish reply.
> Can i first ask if anyone knows off the top of their head, if there is
> a likely obvious cause to the following problem.
> For the moment i've reduced my form request to a simple text string
> entry, instead of my desired optional parameters. As i have been stuck
> with a single unfathomable glitch for over a year.
> Basically, if i enter queries such as ;
> "select * from table" "select * from table order by artist",
> it works perfectly. However if i introduce the 'where' option, as in
> "select * from table where artist like whatever". It comes back with
> "could not execute query". This happens even if i append "order by" to
> it.
> I'll post all the various codes if anyone can please help.
time or another, that they have found a bug in the compiler, operating
system or hardware. In every case it's a problem with the student's code.
You are suggesting that somehow the SQL select where order by is broken for
some unspecified database system. The odds are about the same as my winning
the lottery without buying a ticket.
assuming the table and columns are correctly defined and the connection is
open and the database is selected and I haven't made a typo, the following
will work
"select * from sometable where somecolumn like 'somevalue%' order by
somecolumn"
If you want to help yourself
1) echo the actual SQL statement
2) add error capture code (e.g. 'or die(mysql_error())') to your connect,
dbselect and query calls
If you want more help here
1) show us the actual code including the echoed sql statement and error
message if any
2) show us the table definition
3) tell us which database you are using and what version
4) tell us the version of PHP and if it's in safe mode
--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest
-
Matthias Esken #3
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
[email]i.justice@onmail.co.uk[/email] (ian justice) schrieb:
Are you sure that youre query string looks like> Before i post actual code, as i need a speedyish reply.
> Can i first ask if anyone knows off the top of their head, if there is
> a likely obvious cause to the following problem.
> For the moment i've reduced my form request to a simple text string
> entry, instead of my desired optional parameters. As i have been stuck
> with a single unfathomable glitch for over a year.
> Basically, if i enter queries such as ;
> "select * from table" "select * from table order by artist",
> it works perfectly. However if i introduce the 'where' option, as in
> "select * from table where artist like whatever". It comes back with
> "could not execute query". This happens even if i append "order by" to
> it.
select id from table order by id
and not like
select id from tableorder by id
?
Please give us the version of PHP, the name of the DBMS that you're
using and some small example code.
Regards,
Matthias
Matthias Esken Guest
-
-
ian justice #5
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
Matthias Esken <muelleimer2003nospam@usenetverwaltung.org> wrote in message news:<bnur1r.11s.1@usenet.esken.de>...
Yes>
> Are you sure that youre query string looks like
> select id from table order by id
> and not like
> select id from tableorder by id
> ?
I'm writing this via web tv, however come Sunday i should be able to access a PC
and i'll post all the scripts.
I'm using;> Please give us the version of PHP, the name of the DBMS that you're
> using and some small example code.
>
> Regards,
> Matthias
PHP4u Version 3.0 Based on PHP-4.3.2
MySQL 3.23.52
Thanks for your time so far.
ian justice Guest
-
ian justice #6
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
>
Correction MySQL 3.23.56>I'm using;
>PHP4u Version 3.0 Based on PHP-4.3.2
>MySQL 3.23.52
>Thanks for your time so far.
ian justice Guest
-
ian justice #7
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
"Tom Thackrey" <use.signature@nospam.com> wrote in message news:<rcBob.8442$e73.8118@newssvr14.news.prodigy.c om>...
I'm presuming it is my fault>
> I teach students how to program. Almost every student is convinced, at one
> time or another, that they have found a bug in the compiler, operating
> system or hardware. In every case it's a problem with the student's code.
Honestly not remotely suggesting such a thing :)> You are suggesting that somehow the SQL select where order by is broken for
> some unspecified database system. The odds are about the same as my winning
> the lottery without buying a ticket.
I'm replying to this via webtv, so unfortunately the rest of your
message can't be quoted as it doesn't show up on the reply form.
However, hopefully on Sunday i will be able to access a PC again. I
will then post the scripts.
I had already tried the syntax you suggested without success. The
database and MySQL connection are fine, as they select, sort and
display the results of a query such as "select * from table order by
column".
The versions i am using are as follows;
PHP4u Version 3.0 Based on 4.3.2
MySQL 3.23.56
Many thanks for your time and help so far, it's very much appreciated.
ian justice Guest
-
Tom Thackrey #8
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
On 31-Oct-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
What error message did you get when you executed the query?> I had already tried the syntax you suggested without success. The
> database and MySQL connection are fine, as they select, sort and
> display the results of a query such as "select * from table order by
> column".
>
> The versions i am using are as follows;
> PHP4u Version 3.0 Based on 4.3.2
> MySQL 3.23.56
> Many thanks for your time and help so far, it's very much appreciated.
Are you sure there are records in the table that match your pattern?
If the syntax is correct, then the problem is probably with the table or
column names. Are you using reserved words for either of these? Do they
exist?
--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest
-
ian justice #9
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
"Tom Thackrey" <use.signature@nospam.com> wrote in message news:<FWHob.11451$OS5.8313@newssvr14.news.prodigy. com>...
The error message was "could not execute query". This is my own error> What error message did you get when you executed the query?
> Are you sure there are records in the table that match your pattern?
> If the syntax is correct, then the problem is probably with the table or
> column names. Are you using reserved words for either of these? Do they
> exist?
message as in
$rs=mysql_query($sql, $conn) or die ("could not execute query");
The records do exist i deliberately used simple one-word requests as
well. I also
checked i got the same error message by typing in a load of random
letters in the
text field.
The table is called 'music' and the columns are headed 'song' 'folder'
format' 'artist'.
Whether it's relevant to solving the puzzle, i don't know. But, i
stress again that i am
successfully connected to mysql and the database. As, it does
correctly sort and display
the result by the chosen 'order by' command, be it song, folder,
format or artist.
ian justice Guest
-
Tom Thackrey #10
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
On 1-Nov-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
change it to> "Tom Thackrey" <use.signature@nospam.com> wrote in message
> news:<FWHob.11451$OS5.8313@newssvr14.news.prodigy. com>...
>>> > What error message did you get when you executed the query?
> > Are you sure there are records in the table that match your pattern?
> > If the syntax is correct, then the problem is probably with the table or
> > column names. Are you using reserved words for either of these? Do they
> > exist?
> The error message was "could not execute query". This is my own error
> message as in
> $rs=mysql_query($sql, $conn) or die ("could not execute query");
$rs=mysql_query($sql, $conn) or die ("could not execute query because
".mysql_error());
You'd save us all a lot of time if you'd just post the sql statement that's>
> The records do exist i deliberately used simple one-word requests as
> well. I also
> checked i got the same error message by typing in a load of random
> letters in the
> text field.
> The table is called 'music' and the columns are headed 'song' 'folder'
> format' 'artist'.
>
> Whether it's relevant to solving the puzzle, i don't know. But, i
> stress again that i am
> successfully connected to mysql and the database. As, it does
> correctly sort and display
> the result by the chosen 'order by' command, be it song, folder,
> format or artist.
failing along with the mysql error message.
--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest
-
ian justice #11
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
"Tom Thackrey" <use.signature@nospam.com> wrote in message news:<FWHob.11451$OS5.8313@newssvr14.news.prodigy. com>...
> On 31-Oct-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
>> > The versions i am using are as follows;
> > PHP4u Version 3.0 Based on 4.3.2
> > MySQL 3.23.56I'm relatively new to computers, so this may be a ludricous> If the syntax is correct
suggestion. As in it would
leave my Database open to malicious destruction. However, if it
would'nt, ( i simply do
not know ). I could give you the URL of a copy of the Form that i'm
using and the PHP
script URL. Although presumably, that i not necessary as the Form has
that as the 'action'
and you can't view the PHP code.
I will still post the PHP code tomorrow.
ian justice Guest
-
ian justice #12
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
"Tom Thackrey" <use.signature@nospam.com> wrote in message news:<x%Wob.939$vn3.605@newssvr29.news.prodigy.com >...
that's failling> On 1-Nov-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
>> > "Tom Thackrey" <use.signature@nospam.com> wrote in message
> > news:<FWHob.11451$OS5.8313@newssvr14.news.prodigy. com>...
>> You'd save us all a lot of time if you'd just post the sql messageSorry, i will paste the whole script on Tuesday at the latest. I'll>>along with the error message.
keep quiet
until then. Although i do know i kept it as basic as could be.
For instance the working parts of the HTML Form were,
<form action="page_name.php" method="POST"> I also tried "GET" with
exactly the same outcome.
<input type="text" name="write">
The 'crucial' ? part of the PHP Script was simply
"$sql=$write". Which works fine without the where option.
ian justice Guest
-
Tom Thackrey #13
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
On 1-Nov-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
I gather you are entering the sql in an <input field. You do know that if> "Tom Thackrey" <use.signature@nospam.com> wrote in message
> news:<x%Wob.939$vn3.605@newssvr29.news.prodigy.com >...> that's failling> > On 1-Nov-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
> >> > > "Tom Thackrey" <use.signature@nospam.com> wrote in message
> > > news:<FWHob.11451$OS5.8313@newssvr14.news.prodigy. com>...
> >> You'd save us all a lot of time if you'd just post the sql message>> >>along with the error message.
> Sorry, i will paste the whole script on Tuesday at the latest. I'll
> keep quiet
> until then. Although i do know i kept it as basic as could be.
> For instance the working parts of the HTML Form were,
> <form action="page_name.php" method="POST"> I also tried "GET" with
> exactly the same outcome.
> <input type="text" name="write">
> The 'crucial' ? part of the PHP Script was simply
> "$sql=$write". Which works fine without the where option.
you have magic quotes on your input will be escaped with back slashes
automatically which would transform "select * from table where col like
'something'" to "select * from table where col like \'something\'" causing a
mysql syntax error.
I suggest that you code in such a way that these type of errors become
obvious, for example:
$result = mysql_query($sql) or die("Error: $sql failed because
".mysql_error());
--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest
-
Geoff Berrow #14
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
I noticed that Message-ID:
<Pq0pb.980$Kn5.626@newssvr29.news.prodigy.com> from Tom Thackrey
contained the following:
And use>I gather you are entering the sql in an <input field. You do know that if
>you have magic quotes on your input will be escaped with back slashes
>automatically which would transform "select * from table where col like
>'something'" to "select * from table where col like \'something\'" causing a
>mysql syntax error.
$sql =stripslashes($write);
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
Geoff Berrow Guest
-
ian justice #15
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
"Tom Thackrey" <use.signature@nospam.com> wrote in message news:<x%Wob.939$vn3.605@newssvr29.news.prodigy.com >...
statement that's> On 1-Nov-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
>> > "Tom Thackrey" <use.signature@nospam.com> wrote in message
> > news:<FWHob.11451$OS5.8313@newssvr14.news.prodigy. com>...
>> You'd save us all a lot of time if you'd just post the sqlThe basic and simple form and scripts are given below.>>> failing along with the mysql error message.
#######SHORT FORM########
<form method="get" action="file_name.php">
Write In Here <input type="textarea" name="write" rows="1"
cols="400"><br><br>
<input type="submit" value="SEARCH">
<input type="reset" value="RESET">
######SHORT SCRIPT########
<?php
$conn=@mysql_connect("localhost", "user_name", "password") or
die("could not connect");
$rs=@mysql_select_db("database_name", $conn) or die("could not connect
to database");
$sql="$write";
$rs=mysql_query($sql, $conn) or die("could not execute query");
$list="<table border=\"1\" cellpadding=\"2\">";
$list.="<tr><th>SONG</th>";
$list.="<th>FOLDER</th>";
$list.="<th>FORMAT</th>";
$list.="<th>ARTIST</th></tr>";
while($row=mysql_fetch_array($rs))
{
$list.="<tr>";
$list.="<td>".$row["SONG"]."</td>";
$list.="<td>".$row["FOLDER"]."</td>";
$list.="<td>".$row["FORMAT"]."</td>";
$list.="<td>".$row["ARTIST"]."</td>";
$list.="</tr>";
}
$list.="</table>";
echo($list);
?>
################################################## #############################
BE A GOD----SEND ME TO HEAVEN
If you want to have a great time and loads of fun. Please feel free to
tackle the problem with my 'Utopian script', which would send me
soaring to Heaven, emotionally, that is.
It produces the following parse error "Parse error: parse error in
/data/members/paid/x/x/user_name/htdocs/directory_name/file_name.php
on line 9"
###LONG SCRIPT#######
<?php
$conn=@mysql_connect("localhost", "user_name", "password") or
die("could not connect");
$rs=@mysql_select_db("database_name", $conn) or die("could not connect
to database");
$sql="select * from table_name where";
if(isset($song)){
$sql.="song="$song" and"
}
if(isset($folder)){
$sql.="folder="$folder" and"
}
if(isset($format)){
$sql.="format="$format" and"
}
if(isset($artist)){
$sql.="artist="$artist" and"
}
$sql=ereg_replace("and", "", "$sql");
if(isset($order)){
$sql.="order="$order"
}
$rs=mysql_query($sql, $conn) or die("could not execute query");
$list="<table border=\"1\" cellpadding=\"2\">";
$list.="<tr><th>SONG</th>";
$list.="<th>FOLDER</th>";
$list.="<th>FORMAT</th>";
$list.="<th>ARTIST</th></tr>";
while($row=mysql_fetch_array($rs))
{
$list.="<tr>";
$list.="<td>".$row["song"]."</td>";
$list.="<td>".$row["folder"]."</td>";
$list.="<td>".$row["format"]."</td>";
$list.="<td>".$row["artist"]."</td>";
$list.="</tr>";
}
$list.="</table>";
echo($list);
?>
######LONG FORM#######
<form action="form_name.php" method="GET">
<b>SONG</b><br>
<input type="text" name="song" size="50"><br>
<b>FOLDER</b><br>
<input type="text" name="folder" size="2"><br>
<b>FORMAT</b><br>
<input type="text" name="format" size="20"><br>
<b>ARTIST</b><br>
<input type="text" name="artist" size="40"><br>
The percent sign can be used as a wildcard. You can place it at the
start, end or both ends with appropiate results.<br>
<b>ORDER RESULTS BY;</b><br>
<input type="radio" name="order" value="order by song"
checked><b>SONG</b><br>
<input type="radio" name="order" value="order by
folder"><b>FOLDER</b><br>
<input type="radio" name="order" value="order by
artist"><b>ARTIST</b> 
<input type="submit" value="SEARCH"><input type="reset"
value="RESET"><br><br>
</form>
ian justice Guest
-
Tom Thackrey #16
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
On 4-Nov-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
Unless you have register globals on you need to code the above as> The basic and simple form and scripts are given below.
> #######SHORT FORM########
> <form method="get" action="file_name.php">
> Write In Here <input type="textarea" name="write" rows="1"
> cols="400"><br><br>
> <input type="submit" value="SEARCH">
> <input type="reset" value="RESET">
>
> ######SHORT SCRIPT########
> <?php
> $conn=@mysql_connect("localhost", "user_name", "password") or
> die("could not connect");
> $rs=@mysql_select_db("database_name", $conn) or die("could not connect
> to database");
> $sql="$write";
$sql = $_POST['write'];
This would be more useful as> $rs=mysql_query($sql, $conn) or die("could not execute query");
$rs=mysql_query($sql, $conn) or die("could not execute query [$sql] because
".mysql_error());
The above has unescaped quotes and no ;, it also needs a space after the> $list="<table border=\"1\" cellpadding=\"2\">";
> $list.="<tr><th>SONG</th>";
> $list.="<th>FOLDER</th>";
> $list.="<th>FORMAT</th>";
> $list.="<th>ARTIST</th></tr>";
> while($row=mysql_fetch_array($rs))
> {
> $list.="<tr>";
> $list.="<td>".$row["SONG"]."</td>";
> $list.="<td>".$row["FOLDER"]."</td>";
> $list.="<td>".$row["FORMAT"]."</td>";
> $list.="<td>".$row["ARTIST"]."</td>";
> $list.="</tr>";
> }
> $list.="</table>";
> echo($list);
> ?>
>
> ################################################## #############################
> BE A GOD----SEND ME TO HEAVEN
> If you want to have a great time and loads of fun. Please feel free to
> tackle the problem with my 'Utopian script', which would send me
> soaring to Heaven, emotionally, that is.
> It produces the following parse error "Parse error: parse error in
> /data/members/paid/x/x/user_name/htdocs/directory_name/file_name.php
> on line 9"
>
>
>
> ###LONG SCRIPT#######
>
> <?php
> $conn=@mysql_connect("localhost", "user_name", "password") or
> die("could not connect");
> $rs=@mysql_select_db("database_name", $conn) or die("could not connect
> to database");
> $sql="select * from table_name where";
> if(isset($song)){
> $sql.="song="$song" and"
'and' or you will end up with '... andfolder=...'
it should be
$sql.="song=\"$song\" and ";
the rest of these have the same problem
Huh? take the above out and replace it with> }
> if(isset($folder)){
> $sql.="folder="$folder" and"
> }
> if(isset($format)){
> $sql.="format="$format" and"
> }
> if(isset($artist)){
> $sql.="artist="$artist" and"
> }
> $sql=ereg_replace("and", "", "$sql");
$sql .= ' 1 ';
should be> if(isset($order)){
> $sql.="order="$order"
$sql .= "order=\"$order\"";
see earlier comment about mysql_error()> }
> $rs=mysql_query($sql, $conn) or die("could not execute query");
It's always useful to display your sql statements especially when you build> $list="<table border=\"1\" cellpadding=\"2\">";
> $list.="<tr><th>SONG</th>";
> $list.="<th>FOLDER</th>";
> $list.="<th>FORMAT</th>";
> $list.="<th>ARTIST</th></tr>";
> while($row=mysql_fetch_array($rs))
> {
> $list.="<tr>";
> $list.="<td>".$row["song"]."</td>";
> $list.="<td>".$row["folder"]."</td>";
> $list.="<td>".$row["format"]."</td>";
> $list.="<td>".$row["artist"]."</td>";
> $list.="</tr>";
> }
> $list.="</table>";
> echo($list);
> ?>
>
>
>
> ######LONG FORM#######
>
> <form action="form_name.php" method="GET">
>
> <b>SONG</b><br>
> <input type="text" name="song" size="50"><br>
> <b>FOLDER</b><br>
> <input type="text" name="folder" size="2"><br>
> <b>FORMAT</b><br>
> <input type="text" name="format" size="20"><br>
> <b>ARTIST</b><br>
> <input type="text" name="artist" size="40"><br>
>
> The percent sign can be used as a wildcard. You can place it at the
> start, end or both ends with appropiate results.<br>
>
> <b>ORDER RESULTS BY;</b><br>
> <input type="radio" name="order" value="order by song"
> checked><b>SONG</b><br>
> <input type="radio" name="order" value="order by
> folder"><b>FOLDER</b><br>
> <input type="radio" name="order" value="order by
> artist"><b>ARTIST</b> 
>
> <input type="submit" value="SEARCH"><input type="reset"
> value="RESET"><br><br>
> </form>
them in parts. That's why using the or die() to display the sql and the
error message is way more helpful than just displaying "i have an error,
guess what it is"
--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest
-
ian justice #17
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
"Tom Thackrey" <use.signature@nospam.com> wrote in message news:<n_Rpb.492$GH.50501888@newssvr21.news.prodigy .com>...
They are turned on as far as i know. If it's of any help or>
> Unless you have register globals on you need to code the above as
> $sql = $_POST['write'];
>
assistance, all the specifications are contained in this link
"http://www.php4u.info/phpinfo.php"I had since added that extension, with very interesting results. There>> > $rs=mysql_query($sql, $conn) or die("could not execute query");
> This would be more useful as
> $rs=mysql_query($sql, $conn) or die("could not execute query [$sql] because
> ".mysql_error());
is a possibility, that 'stripslashes' are involved. I'll have to go
and learn what they are first. I am very new to computers, never ever
haven even touched one until about eighteen months ago.The 'and' mention looks to be a spectaculary thick oversight on my>> > <?php
> > $conn=@mysql_connect("localhost", "user_name", "password") or
> > die("could not connect");
> > $rs=@mysql_select_db("database_name", $conn) or die("could not connect
> > to database");
> > $sql="select * from table_name where";
> > if(isset($song)){
> > $sql.="song="$song" and"
> The above has unescaped quotes and no ;, it also needs a space after the
> 'and' or you will end up with '... andfolder=...'
> it should be
> $sql.="song=\"$song\" and ";
> the rest of these have the same problem
part.
I'll have to look into this in detail. So much of the problems could
be that, ( i'm not removing blame from my scripting ), server specific
syntax. For example in the vast amount of reading i've done on php (
yes, apparently fruitless ), i had never seen mention of where, as in
my simple html form. One can enter a query successfully without using
any quotes or capitals.
Incidentally, if it would be of any help, i could publish here the
URL'S of my forms on nmy website. As, i'm sure the error messages now
being detailed would mean far more to yourself than me. I obviously
don't wish to leave my database open to malicious attack. Bearing in
mind it's an open text field entry. Presumably some bright spark could
easily drop the whole thing ???.
This ereg_replace 'thing' was something i found recommended in a forum>> > $sql=ereg_replace("and", "", "$sql");
> Huh? take the above out and replace it with
>
> $sql .= ' 1 ';
>
once. :) sorry. I'm very interested in your quoting of the '1'. As in
my database interface from my website provider, that is sometimes in
their syntax. Incidentally, they show the syntax of a request upon
successful ( or otherwise ) completion. However, if i copy and paste
it into their text field and run it, it astoundingly always says
syntax error !!!. Again, allowing for me being uneducated in computer
matters, i wonder if this is a result of 'stripslashes' etc. ?.Taken on board.>
> It's always useful to display your sql statements especially when you build
> them in parts. That's why using the or die() to display the sql and the
> error message is way more helpful than just displaying "i have an error,
> guess what it is"
ian justice Guest
-
ian justice #18
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
Geoff Berrow <blthecat@ckdog.co.uk> wrote in message news:<qhd9qv48i825i3hqsrtbouedhnndfi9oie@4ax.com>. ..
APOLOGIES IF THIS IS NOT PROTOCOL. BUT, SOME THINGS IN LIFE HAVE TO BE> I noticed that Message-ID:
> <Pq0pb.980$Kn5.626@newssvr29.news.prodigy.com> from Tom Thackrey
> contained the following:
>>> >I gather you are entering the sql in an <input field. You do know that if
> >you have magic quotes on your input will be escaped with back slashes
> >automatically which would transform "select * from table where col like
> >'something'" to "select * from table where col like \'something\'" causing a
> >mysql syntax error.
> And use
> $sql =stripslashes($write);
IN BIG BLOCK LETTERS. I HAVE JUST ADDED THE 'STRIPSLASHES' TO MY
SIMPLE TEST FORM. EVERYTHING WORKS. SO, IF ONLY I CAN WORK IT INTO MY
LONG VERSION. ALTHOUGH, I FEAR I HAVE MANY MORE MISTAKES LURKING
WITHIN THAT SCRIPT. HOWEVER, FOR NOW, MANY, MANY SINCERE THANKS. I'M
ABSOLUTELY STUNNED.
ian justice Guest
-
Geoff Berrow #19
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
I noticed that Message-ID:
<f6c8e066.0311050630.29199968@posting.google.com > from ian justice
contained the following:
Yeah, I get like that when my scripts run. %-)>HOWEVER, FOR NOW, MANY, MANY SINCERE THANKS. I'M
>ABSOLUTELY STUNNED.
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs [url]http://www.ckdog.co.uk/rfdmaker/[/url]
Geoff Berrow Guest
-
Tom Thackrey #20
Re: "Select" & "Order By" OK- ''WHERE'' Does'nt Work !
On 5-Nov-2003, [email]i.justice@onmail.co.uk[/email] (ian justice) wrote:
In looking at your phpinfo() I see that you have register_globals On,> "Tom Thackrey" <use.signature@nospam.com> wrote in message
> news:<n_Rpb.492$GH.50501888@newssvr21.news.prodigy .com>...> They are turned on as far as i know. If it's of any help or> >
> > Unless you have register globals on you need to code the above as
> > $sql = $_POST['write'];
> >
> assistance, all the specifications are contained in this link
> "http://www.php4u.info/phpinfo.php"> I had since added that extension, with very interesting results. There> >> > > $rs=mysql_query($sql, $conn) or die("could not execute query");
> > This would be more useful as
> > $rs=mysql_query($sql, $conn) or die("could not execute query [$sql]
> > because
> > ".mysql_error());
> is a possibility, that 'stripslashes' are involved. I'll have to go
> and learn what they are first. I am very new to computers, never ever
> haven even touched one until about eighteen months ago.>> >> > > <?php
> > > $conn=@mysql_connect("localhost", "user_name", "password") or
> > > die("could not connect");
> > > $rs=@mysql_select_db("database_name", $conn) or die("could not connect
> > > to database");
> > > $sql="select * from table_name where";
> > > if(isset($song)){
> > > $sql.="song="$song" and"
> > The above has unescaped quotes and no ;, it also needs a space after the
> > 'and' or you will end up with '... andfolder=...'
> > it should be
> > $sql.="song=\"$song\" and ";
> > the rest of these have the same problem
> The 'and' mention looks to be a spectaculary thick oversight on my
> part.
> I'll have to look into this in detail. So much of the problems could
> be that, ( i'm not removing blame from my scripting ), server specific
> syntax. For example in the vast amount of reading i've done on php (
> yes, apparently fruitless ), i had never seen mention of where, as in
> my simple html form. One can enter a query successfully without using
> any quotes or capitals.
> Incidentally, if it would be of any help, i could publish here the
> URL'S of my forms on nmy website. As, i'm sure the error messages now
> being detailed would mean far more to yourself than me. I obviously
> don't wish to leave my database open to malicious attack. Bearing in
> mind it's an open text field entry. Presumably some bright spark could
> easily drop the whole thing ???.
>> This ereg_replace 'thing' was something i found recommended in a forum> >> > > $sql=ereg_replace("and", "", "$sql");
> > Huh? take the above out and replace it with
> >
> > $sql .= ' 1 ';
> >
> once. :) sorry. I'm very interested in your quoting of the '1'. As in
> my database interface from my website provider, that is sometimes in
> their syntax. Incidentally, they show the syntax of a request upon
> successful ( or otherwise ) completion. However, if i copy and paste
> it into their text field and run it, it astoundingly always says
> syntax error !!!. Again, allowing for me being uneducated in computer
> matters, i wonder if this is a result of 'stripslashes' etc. ?.> Taken on board.> >
> > It's always useful to display your sql statements especially when you
> > build
> > them in parts. That's why using the or die() to display the sql and the
> > error message is way more helpful than just displaying "i have an error,
> > guess what it is"
safe_mode On, and magic_quotes On.
Register Globals On means that you do not have to use $_POST[] and $_GET[]
to retrieve values from the previous page. The values will be available
directly as global variables. (It's still a good idea to use $_POST etc.
it's safer and doesn't rely on register globals being On.)
Safe Mode On restricts the things you can do, like where you can create or
read files, etc.
Magic Quotes On causes any input from the user to be escaped with slashes.
If the user enters "Don't feed the bears.", the string will appear in your
PHP program as "Don\'t feed the bears." this is suitable for entering as
data in a database, but could cause problems if you are trying to pass whole
sql statements. Use stripslashes() to remove these escapes.
The $str .= ' 1 '; I suggested was to compensate for the ' and ' you put
after each argument. Doing it your way would result in something like
select * from table where song='cherish' and order by somename
adding the 1 makes it legal syntax
select * from table where song='cherish' and 1 order by somename
it also works when no field is specified
select * from table where 1 order by somename
--
Tom Thackrey
[url]www.creative-light.com[/url]
tom (at) creative (dash) light (dot) com
do NOT send email to [email]jamesbutler@willglen.net[/email] (it's reserved for spammers)
Tom Thackrey Guest



Reply With Quote

