Jump to content

[SOLVED] where am i going wrong


jkkenzie

Recommended Posts

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$insertSQL = sprintf("INSERT INTO content (id, title, shortdesc, longdesc, pic, group, date, author, active) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",GetSQLValueString($_POST['id'], "int"),GetSQLValueString($_POST['Teasertitle'], "text"),GetSQLValueString($_POST['Teasertxt'], "text"),GetSQLValueString($_POST['Brief'], "text"),GetSQLValueString($_POST['Highres'],"text"),GetSQLValueString($_POST['Keywords'], "text"),GetSQLValueString($_POST['Startdate'], "date"),GetSQLValueString($_POST['Author'], "text"),GetSQLValueString(isset($_POST['Active']) ? "true" : "", "defined","1","0"));
  
echo $insertSQL;
  mysql_select_db($database_app_conn, $app_conn);

  $Result1 = mysql_query($insertSQL, $app_conn) or die(mysql_error());

 

the code above give me the below error:

INSERT INTO content (id, title, shortdesc, longdesc, pic, group, date, author, active) VALUES (NULL, 'gfhgfhgf', '
gfhgfhgfhgfhgfh

', '
fghfghjhhfghgf

', 'default.jpg', 'dfhggfh', '2008-12-31', 'fghgfhfg', 1)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 'group, date, author, active) VALUES (NULL, 'gfhgfhgf', '
gfhgfhgfhgfhgfh

',' at line 1

where am going wrong?

SURPRISINGLY THE ONE BELOW WORK ON ANOTHER PAGE:


function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}

$insertSQL = sprintf("INSERT INTO events (id, Teasertitle, Teasertxt, Brief, Speaker, Information, Caption, Highres,Venue, Keywords, Enddate, Startdate, Author, Active, Category) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['Teasertitle'], "text"),
                       GetSQLValueString($_POST['Teasertxt'], "text"),
                       GetSQLValueString($_POST['Brief'], "text"),
                       GetSQLValueString($_POST['Speaker'], "text"),
                       GetSQLValueString($_POST['Information'], "text"),
                       GetSQLValueString($_POST['Caption'], "text"),
                       GetSQLValueString($_POST['Highres'],"text"),
				   GetSQLValueString($_POST['Venue'], "text"),
                       GetSQLValueString($_POST['Keywords'], "text"),
                       GetSQLValueString($_POST['Enddate'], "date"),
                       GetSQLValueString($_POST['Startdate'], "date"),
				   GetSQLValueString($_POST['Author'], "text"),
                       GetSQLValueString(isset($_POST['Active']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['Category'], "text"));
  mysql_select_db($database_app_conn, $app_conn);

  $Result1 = mysql_query($insertSQL, $app_conn) or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/138974-solved-where-am-i-going-wrong/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.