andrew_ww Posted January 21, 2007 Share Posted January 21, 2007 Does anything look out of place with my code??[code]?php require_once('Connections/MySQL_tick.php'); ?><?phpif (!function_exists("GetSQLValueString")) {function GetSQLValueString($theValue, $theType, $theDefinedValue = "",$theNotDefinedValue = ""){ $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) :$theValue; $theValue = function_exists("mysql_real_escape_string") ?mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'": "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue :$theNotDefinedValue; break; } return $theValue;}}mysql_select_db($database_MySQL_tick, $MySQL_tick);$query_rs_insert = "SELECT * FROM tbl_table1";$rs_insert = mysql_query($query_rs_insert, $MySQL_tick) ordie(mysql_error());$row_rs_insert = mysql_fetch_assoc($rs_insert);$totalRows_rs_insert = mysql_num_rows($rs_insert);$editFormAction = $_SERVER['PHP_SELF'];if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);}//mysql_select_db($database_MySQL_tick, $MySQL_tick);//Build the query$query = 'INSERT INTO tbl_table1 (review_type) VALUES ';$query_insert = array();if (!empty($_POST['checkbox'])) { $query_insert[] = '("tests")';}if (!empty($_POST['checkbox2'])) { $query_insert[] = '("ispsdjfsdf")';}//Continue the series of if clauses to populate the array.$query .= implode(',', $query_insert);//Now, run the query!$Result1 = mysql_query($query, $MySQL_tick) or die(mysql_error());?> [/code]I'm getting the following error when running it:You have an error in your SQL syntax; check the manual that correspondsto your MySQL server version for the right syntax to use near '' atline 1 Quote Link to comment https://forums.phpfreaks.com/topic/35077-unknown-generic-error-debug-suggestions/ Share on other sites More sharing options...
redbullmarky Posted January 21, 2007 Share Posted January 21, 2007 as for debug suggestions, just put an 'echo' before your last line so you know what query is being run. all of the hardcoded queries look fine, though the last one is formed in a different way:[code]<?phpecho $query;$Result1 = mysql_query($query, $MySQL_tick) or die(mysql_error());?>[/code]you dont have any checks for the result that BOTH checkboxes are unticked, and also - if both ARE ticked, then you're gonna get something a little weird. Quote Link to comment https://forums.phpfreaks.com/topic/35077-unknown-generic-error-debug-suggestions/#findComment-165540 Share on other sites More sharing options...
andrew_ww Posted January 21, 2007 Author Share Posted January 21, 2007 What do you think would occur if both are ticked ? Quote Link to comment https://forums.phpfreaks.com/topic/35077-unknown-generic-error-debug-suggestions/#findComment-165542 Share on other sites More sharing options...
redbullmarky Posted January 21, 2007 Share Posted January 21, 2007 try the 'echo' line i suggested and see, but from what i can understand, you'll get $query_insert with two values, ("tests") and ("ispsdjfsdf") which when imploded will make ("tests"),("ispsdjfsdf"). then your query will look like:[code]INSERT INTO tbl_table1 (review_type) VALUES ("tests"),("ispsdjfsdf")[/code]if you only need to allow ONE box to be ticked, then consider:a) using a radio button on your form insteadb) use an ELSE between your IF'sc) removing the implode/use of an array, and just use a variable.if you can explain better exactly what you're trying to do, then we should be able to help a little more.cheers Quote Link to comment https://forums.phpfreaks.com/topic/35077-unknown-generic-error-debug-suggestions/#findComment-165546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.