SunQuest
           Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 15th, 2003, 02:01 PM
shinkicker shinkicker is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Pretoria, Gauteng, South Africa
Posts: 10 shinkicker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql_query error

I've got a query that I build in PHP and then call mysql_query on. The link to the database is active and working. But it gives me a SQL error: "You have an error in your SQL syntax near '' at line 1".

Problem is if I echo the query to the page and copy and paste the query into the mySQLAdmin page then it works just fine.

The query that I run is the following(there are no carraige returns in the text, it is just one long line):

SELECT S_NAME, S_DESCRIPTION, S_START_DATE, S_END_DATE, S_SEND_DATE, P_FIRST_NAME, P_LAST_NAME, P_CONTACT_NO, P_EMAIL, SQ_TEXT, CASE WHEN SQR_TEXT IS NULL THEN SR_TEXT ELSE SQR_TEXT END AS Q_TEXT, S.SURVEY_ID FROM SURVEYS S LEFT JOIN SURVEY_QUESTIONS SQ ON SQ.SURVEY_ID = S.SURVEY_ID LEFT JOIN SURVEY_RESPONSES SR ON SR.SURVEY_QUESTION_ID = SQ.SURVEY_QUESTION_ID LEFT JOIN SURVEY_QUESTION_RESPONSES SQR ON SQR.SURVEY_QUESTION_RESPONSE_ID = SR.SR_TEXT LEFT JOIN RECIPIENT_DETAILS RD ON RD.RECIPIENT_DETAIL_ID = SR.RECIPIENT_DETAIL_ID LEFT JOIN PERSON P ON P.PERSON_ID = RD.PERSON_ID WHERE S.SURVEY_ID = 5

Could anybody maybe know what the problem is.

Thanks

Reply With Quote
  #2  
Old September 15th, 2003, 02:09 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: mysql_query error

please post the code that is used to generate the sql statement that you posted.

Reply With Quote
  #3  
Old September 15th, 2003, 02:13 PM
shinkicker shinkicker is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Pretoria, Gauteng, South Africa
Posts: 10 shinkicker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: mysql_query error

while (list ($key, $val) = each ($field_list))
{
//check is value is total_recipients
if ( (int) $key == 5 )
{
$tot_recipients = 1;
$recipient_count = $count-1;
} else
{
//check if value is total_respondants
if ( (int) $key == 6 )
{
$tot_respondants = 1;
$respondant_count = $count-1;
} else
{
//this is nesassary for the text box questions
if ( (int) $key == 12 )
{
$sel_fields.=" CASE ";
$sel_fields.=" WHEN SQR_TEXT IS NULL THEN SR_TEXT ";
$sel_fields.=" ELSE SQR_TEXT END AS Q_TEXT";

$val="QUESTION_TEXT";

} else
{
//if not one of the above add field to select list
$sel_fields.="";
$sel_fields .= $val;
$sel_fields.="";
}

if ( $field_count != $count )
{
$sel_fields.=", ";
}
}
}

$file_list .= $val;

if ( $field_count != $count )
{
$file_list.="t";
}

$count++;
}

//LASTELY ADD THE SURVEY_ID this is important to find the value of the recipients and respondants
$sel_fields.= ", S.SURVEY_ID ";

$file_list .= "rn";

$query = "SELECT $sel_fields FROM SURVEYS S ";
$query.= " LEFT JOIN SURVEY_QUESTIONS SQ ON SQ.SURVEY_ID = S.SURVEY_ID ";
$query.= " LEFT JOIN SURVEY_RESPONSES SR ON SR.SURVEY_QUESTION_ID = SQ.SURVEY_QUESTION_ID ";
$query.= " LEFT JOIN SURVEY_QUESTION_RESPONSES SQR ON SQR.SURVEY_QUESTION_RESPONSE_ID = SR.SR_TEXT ";
$query.= " LEFT JOIN RECIPIENT_DETAILS RD ON RD.RECIPIENT_DETAIL_ID = SR.RECIPIENT_DETAIL_ID ";
$query.= " LEFT JOIN PERSON P ON P.PERSON_ID = RD.PERSON_ID ";
$query.= " WHERE S.SURVEY_ID = $svid;";

Reply With Quote
  #4  
Old September 15th, 2003, 02:23 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: mysql_query error

do me a favor and try taking the semicolon out after $svid but before the last double quote. I am wondering if something is being misinterpreted due to it.

example

WHERE S.SURVEY_ID = $svid";

not

WHERE S.SURVEY_ID = $svid;";

since I cant actually test it here, I need you to test it for me.

Reply With Quote
  #5  
Old September 15th, 2003, 02:27 PM
shinkicker shinkicker is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Pretoria, Gauteng, South Africa
Posts: 10 shinkicker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: mysql_query error

did that. Still gives the same error. Usually I don't include it but after a bit of RTFM in the php-docs it states that it needs one after the end of a query. So I added it and it made no deference. At the moment it is without it.

Reply With Quote
  #6  
Old September 15th, 2003, 02:42 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: mysql_query error

must admit I am stumped, I cant find anything wrong with the query. Post the code where you actually execute the query...Maybe that will help...

Reply With Quote
  #7  
Old September 15th, 2003, 02:46 PM
shinkicker shinkicker is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Pretoria, Gauteng, South Africa
Posts: 10 shinkicker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: mysql_query error

this code follows just below the previous code posted.

$connection = get_db_connection();

$result = mysql_query ( $query, $connection ) or die("Invalid query: " . mysql_error());


The get_db_connection() function connects to the db if the connection has been lost and returns the connection. This function is used in ALL the php files where I query the DB and it works 100%.

Reply With Quote
  #8  
Old September 16th, 2003, 07:16 AM
shinkicker shinkicker is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Pretoria, Gauteng, South Africa
Posts: 10 shinkicker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: mysql_query error

I can be really stupid if I have the time. That query works fine. The value of one of the functions that is in another php file was incorrect and thus the SQL in that function read "WHERE SURVEY_ID = ". The survey_id parameter was empty. Anyway thanks for the trouble. I amaze myself with stupidity sometimes.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > mysql_query error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway