very intersting Variable question

1 replies
Hi... I'm wondering if you can help me create a function which will allow me to insert data into a MySQL table.

The function calls one variable, which then needs to be placed inside other Session variables to be useful. Dig it >>
--------



function new_sql($object) {

$scratch_id = get_scratch();
$section = $object . "s";

$sql = "INSERT INTO $_SESSION[schema_table]
(
user_id, scratch_id,
entry_type,
content_type, content_subtype, content_label,
urlpath, pagename, section,
title, content, content_format,
collection_array,
order_pref, status
)

VALUES

(
'69', '$scratch_id',
'collection', 'article', '$object', '$_SESSION[new_{$object}_label]',
'$_SESSION[new_{$object}_urlpath]', '$_SESSION[new_{$object}_label]', '$section',
'$_SESSION[new_{$object}_title]', 'TO BE ADDED', 'plain',
'$_SESSION[brand_new_collection_array]',
'title', 'public'
)
";

mysql_query($sql) or die(mysql_error());

} // end function




I'm getting a parse error, for what should be obvious reasons... but do you get the gist of where I need to go with this?

An $object = "issue" or $object = "article" something like that...
#intersting #question #variable
  • Profile picture of the author stinkbug
    Banned
    [DELETED]
    {{ DiscussionBoard.errors[988845].message }}
    • Profile picture of the author Steve Diamond
      Last time I looked, PHP didn't allow anything that complex inside a double-quoted string. If you want it to be automatically parsed and the value included, it can't be any more than a simple variable. So your code would have to look more like this:

      PHP Code:
      $sql "INSERT INTO "$_SESSION[schema_table] .
      "(
      user_id, scratch_id,
      entry_type,
      content_type, content_subtype, content_label,
      urlpath, pagename, section, 
      title, content, content_format,
      collection_array,
      order_pref, status
      )

      VALUES

      (
      '69', '
      $scratch_id', 
      'collection', 'article', '
      $object', '" $_SESSION[new_{$object}_label] . "',
      '" 
      $_SESSION[new_{$object}_urlpath] . "', '" $_SESSION[new_{$object}_label] . "', '$section',
      '" 
      $_SESSION[new_{$object}_title] . "', 'TO BE ADDED', 'plain', 
      '" 
      $_SESSION[brand_new_collection_array] . "',
      'title', 'public'
      )
      "

      I hope this helps.

      Steve
      Signature
      Mindfulness training & coaching online
      Reduce stress | Stay focused | Keep positive and balanced
      {{ DiscussionBoard.errors[988893].message }}

Trending Topics