|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
RE: mysql_query error
please post the code that is used to generate the sql statement that you posted.
|
|
#3
|
|||
|
|||
|
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;"; |
|
#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. |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
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...
|
|
#7
|
|||
|
|||
|
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%. |
|
#8
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > mysql_query error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|