GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 16-Apr-2007, 09:55
darkdante darkdante is offline
New Member
 
Join Date: Apr 2007
Posts: 2
darkdante is on a distinguished road
Post

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'


I am trying to build a string of code dynamically from the database so that when I update my database structure, I won't have to modify the addserver.php page. The part shown below should dynamically build the form portion of my page. Below this code is the static version of the code that I'm trying to mimic dynamically... PLEASE HELP!

PHP Code:

$dbtable="main";
mysql_select_db($dbname);
$querymain = mysql_query("select * from " . $dbtable);
$i=0;
$headers="";
$svalues="";
if (!$querymain) 
    {
    die("All Records Query in " . $dbtable . " failed: " . mysql_error());
    }

while ($i < mysql_num_fields($querymain)) 
    {
    $meta = mysql_fetch_field($querymain, $i);
    if ($meta->name <> "sid")
        {
        if ($i <> 0)
            {
            $headers=$headers . ", $meta->name";
            $svalues=$svalues . ", %s";
// =============================================
// The line immediately below this is the one giving me the error
// =============================================
            $sqlvalues=$sqlvalues . ", GetSQLValueString($_POST['$meta->name'], \"$meta->type\")";
            }
        else
            {
            $headers="$meta->name";
            $svalues="%s";
// ==============================================
// I assume the following line will do the same thing once it gets
// passed the line above.
// ==============================================
            $sqlvalues="GetSQLValueString($_POST['$meta->name'], \"$meta->type\")";
            }
        $i++;
        }
    else
        {
        $i++;
        }
    } 




Static version of the code...
PHP Code:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO main (sid, servername, manufacturer, model, type, cpuqty, cpuspeed, phymem, totaldisk, os, sp, builtby) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['sid'], "int"),
                       GetSQLValueString($_POST['servername'], "text"),
                       GetSQLValueString($_POST['manufacturer'], "text"),
                       GetSQLValueString($_POST['model'], "text"),
                       GetSQLValueString($_POST['type'], "text"),
                       GetSQLValueString($_POST['cpuqty'], "int"),
                       GetSQLValueString($_POST['cpuspeed'], "text"),
                       GetSQLValueString($_POST['phymem'], "text"),
                       GetSQLValueString($_POST['totaldisk'], "text"),
                       GetSQLValueString($_POST['os'], "text"),
                       GetSQLValueString($_POST['sp'], "text"),
                       GetSQLValueString($_POST['builtby'], "text")); 


  #2  
Old 17-Apr-2007, 17:08
darkdante darkdante is offline
New Member
 
Join Date: Apr 2007
Posts: 2
darkdante is on a distinguished road

Re: Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'


I figured out my own problem... I figured I'd post the answer to help anyone else looking for this issue


PHP Code:

// The following line didn't work because $_POST is a valid variable.
// Since I'm building the string as a text string only, I do not want 
// the $_POST to do anything.

// String with issue
$sqlvalues=$sqlvalues . ", GetSQLValueString($_POST['$meta->name'], \"$meta->type\")";

// Corrected String - Added a \ in front of $_POST
$sqlvalues=$sqlvalues . ", GetSQLValueString(\$_POST['$meta->name'], \"$meta->type\")"; 


 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:53.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.