nashsaint Posted February 6, 2009 Share Posted February 6, 2009 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 More sharing options...
gizmola Posted February 6, 2009 Share Posted February 6, 2009 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 https://forums.phpfreaks.com/topic/144032-how-to-insert-defined-variable-into-sql/#findComment-755745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.