Jump to content

Recommended Posts

Does anything look out of place with my code??

[code]?php require_once('Connections/MySQL_tick.php'); ?>
<?php
if (!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) or
die(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 corresponds
to your MySQL server version for the right syntax to use near '' at
line 1
Link to comment
https://forums.phpfreaks.com/topic/35077-unknown-generic-error-debug-suggestions/
Share on other sites

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]
<?php
echo $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.
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 instead
b) use an ELSE between your IF's
c) 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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.