Jump to content

how to insert defined variable into sql


nashsaint

Recommended Posts

Hi,

 

am using dreamweaver to generate the code.  I manually added a variable which handles username session:

$u_uname = $_SESSION['MM_Username'];

 

Now i wanted to insert the value to sql into same table field name "uid".  Below is the code dreamweaver populated to insert data to sql.

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO job_details (job_id, job_no, country, eng_name, status, `date`,) VALUES (%s, %s, %s, %s, %s, %s,)",

                      GetSQLValueString($_POST['job_id'], "int"),

                      GetSQLValueString($_POST['job_no'], "text"),

                      GetSQLValueString($_POST['country'], "text"),

                      GetSQLValueString($_POST['eng_name'], "text"),

                      GetSQLValueString($_POST['status'], "text"),

                      GetSQLValueString($_POST['date'], "date")),

   

  mysql_select_db($database_perDB, $perDB);

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

 

  $insertGoTo = "recordlist.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

 

any help is much appreciated.

thanks.

Link to comment
Share on other sites

Did you try something like this?

 

$insertSQL = sprintf("INSERT INTO job_details (uid, job_id, job_no, country, eng_name, status, `date`,) VALUES (%s, %s, %s, %s, %s, %s, %s,)",
                       GetSQLValueString($u_uname, "text"),
                       GetSQLValueString($_POST['job_id'], "int"),
                       GetSQLValueString($_POST['job_no'], "text"),
                       GetSQLValueString($_POST['country'], "text"),
                       GetSQLValueString($_POST['eng_name'], "text"),
                       GetSQLValueString($_POST['status'], "text"),
                       GetSQLValueString($_POST['date'], "date")),

Link to comment
Share on other sites

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.