writing a session value to file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toedipper

    writing a session value to file

    Hello,

    windows xp, apache, php and my sql and dreamweaver mx

    I have the code below. And it does'nt work! Basically the code below
    is the workings behind the scene that inserts a record to a table and it
    gets most of it's value from a form. There's alot more to the code such
    as the bindings to text boxes etc but I don't think I need to show you
    that, just the basics.

    Most of the values come from text box bindings but one of them is a
    hidden value $custid Basically a user has logged in prior to the insert
    page and then I set a session with their userid. When they then want to
    insert a record I don't insert the userid but the customer id ($custid)
    and I have a bit of code that supposedly grabs the custid from a
    customers table doing a join on the userid.

    The insert code below works but it writes back nothing to the custid
    field in the table. The code below is a combination of dreamweaver mx
    generated code and my hand code.

    Any idea?

    Thanks,

    td

    <?
    session_start() ;
    if ($_SESSION[loggedin] != "yes") {
    header("Locatio n: http://127.0.0.1/custlogin.php") ;
    exit; }
    require_once('C onnections/local.php');


    // this bit gets the custid from the cutomers table and assigns it to
    the variable $thecustid
    $thecustid = "SELECT custid FROM customers WHERE userid='" .
    $_SESSION['MM_Username'] . "'";


    // dreamweaver created all this
    function GetSQLValueStri ng($theValue, $theType, $theDefinedValu e = "",
    $theNotDefinedV alue = "")
    {
    $theValue = (!get_magic_quo tes_gpc()) ? addslashes($the Value) :
    $theValue;

    switch ($theType) {
    case "text":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "long":
    case "int":
    $theValue = ($theValue != "") ? intval($theValu e) : "NULL";
    break;
    case "double":
    $theValue = ($theValue != "") ? "'" . doubleval($theV alue) . "'"
    : "NULL";
    break;
    case "date":
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    break;
    case "defined":
    $theValue = ($theValue != "") ? $theDefinedValu e :
    $theNotDefinedV alue;
    break;
    }
    return $theValue;
    }

    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_ SERVER['QUERY_STRING']);
    }

    // below is all the insert code, note how I have $custid but nothing is
    written back even though I have set it above
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "frmaddsw") ) {
    $insertSQL = sprintf("INSERT INTO software (title, shortdesc, `desc`,
    version, minreqs, wareid, catid, hpage, dllink, dlsize, triallength,
    price, keywords, submitdate, submittime, liveyn, custid) VALUES (%s, %s,
    %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, current_date(),
    current_time, 'N', '$thecustid')",
    GetSQLValueStri ng($_POST['title'], "text"),
    GetSQLValueStri ng($_POST['shortdesc'], "text"),
    GetSQLValueStri ng($_POST['desc'], "text"),
    GetSQLValueStri ng($_POST['version'], "text"),
    GetSQLValueStri ng($_POST['minreqs'], "text"),
    GetSQLValueStri ng($_POST['wareid'], "int"),
    GetSQLValueStri ng($_POST['catid'], "int"),
    GetSQLValueStri ng($_POST['hpage'], "text"),
    GetSQLValueStri ng($_POST['dllink'], "text"),
    GetSQLValueStri ng($_POST['dlsize'], "text"),
    GetSQLValueStri ng($_POST['triallength'], "text"),
    GetSQLValueStri ng($_POST['price'], "double"),
    GetSQLValueStri ng($_POST['keywords'], "text"));

    mysql_select_db ($database_loca l, $local);
    $Result1 = mysql_query($in sertSQL, $local) or die(mysql_error ());
    }
Working...