|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I am accessing a Mysql database with php scripting
This first version works ok $cykdag_collers='SELECT * FROM cykdag WHERE cykdag_num = 79'; $cykdagers_tbd=mysql_query($cykdag_collers); echo mysql_error(); But 79 is a variable so I tried this $cykdag_collers='SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers'; $cykdagers_tbd=mysql_query($cykdag_collers); echo mysql_error(); And got this error Unknown column '$cykdag_ers' in 'where clause' So I tried this $cykdag_collers="SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers"; $cykdagers_tbd=mysql_query($cykdag_collers); .......which seems to work ok as far as I can tell. But when adding "echo mysql_error()" to the same code like this $cykdag_collers="SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers"; $cykdagers_tbd=mysql_query($cykdag_collers); echo mysql_error(); it reports this 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 '' at line 1 Can I ignore this? How can I do this without getting an error? The error will confuse my users but I want to use echo mysql_error() in case it reports other errors. Any apreciated Garry Jones Sweden |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Thu, 14 Feb 2008 19:18:09 +0100, GarryJones <morack@algonet.se> wrote:
> I am accessing a Mysql database with php scripting > > This first version works ok > $cykdag_collers='SELECT * FROM cykdag WHERE cykdag_num = 79'; > $cykdagers_tbd=mysql_query($cykdag_collers); > echo mysql_error(); > > But 79 is a variable so I tried this > > $cykdag_collers='SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers'; > $cykdagers_tbd=mysql_query($cykdag_collers); > echo mysql_error(); > > And got this error > Unknown column '$cykdag_ers' in 'where clause' > > So I tried this > $cykdag_collers="SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers"; > $cykdagers_tbd=mysql_query($cykdag_collers); > ......which seems to work ok as far as I can tell. But when adding > "echo mysql_error()" to the same code > like this > $cykdag_collers="SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers"; > $cykdagers_tbd=mysql_query($cykdag_collers); > echo mysql_error(); > > it reports this 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 '' at line 1 > > Can I ignore this? How can I do this without getting an error? The > error will confuse my users but I want to use echo mysql_error() in > case it reports other errors. Don't display an error, log an error, just base your further actions on the fact wether there is en error... Here you go: $cykdag_collers='SELECT * FROM cykdag WHERE cykdag_num = '.intval($cykdag_ers); $cykdagers_tbd=mysql_query($cykdag_collers); if(!$cykdagers){ trigger_error(mysql_error()); echo 'Sorry, something went wrong'; } //..rest of code -- Rik Wasmus |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
GarryJones wrote:
> I am accessing a Mysql database with php scripting > > This first version works ok > $cykdag_collers='SELECT * FROM cykdag WHERE cykdag_num = 79'; > $cykdagers_tbd=mysql_query($cykdag_collers); > echo mysql_error(); > > But 79 is a variable so I tried this > > $cykdag_collers='SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers'; > $cykdagers_tbd=mysql_query($cykdag_collers); > echo mysql_error(); > > And got this error > Unknown column '$cykdag_ers' in 'where clause' > > So I tried this > $cykdag_collers="SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers"; > $cykdagers_tbd=mysql_query($cykdag_collers); > ......which seems to work ok as far as I can tell. But when adding > "echo mysql_error()" to the same code > like this > $cykdag_collers="SELECT * FROM cykdag WHERE cykdag_num = $cykdag_ers"; > $cykdagers_tbd=mysql_query($cykdag_collers); > echo mysql_error(); > > it reports this 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 '' at line 1 > > Can I ignore this? How can I do this without getting an error? The > error will confuse my users but I want to use echo mysql_error() in > case it reports other errors. > > Any apreciated > > Garry Jones > Sweden > Always check the result of a mysql command. If it is false, THEN check the error message. I don't believe it is guaranteed to be valid if no error is returned. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
![]() |
| Outils de la discussion | |
|
|