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
https://forums.phpfreaks.com/topic/144032-how-to-insert-defined-variable-into-sql/
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")),

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.