cool.works Posted October 22, 2010 Share Posted October 22, 2010 hi for all am trying to insert $_SESSION['SESS_MEMBER_ID'] in a mysql table called file. All other parameters can be sent to database only this variable this is my code : <?php // Check if a file has been uploaded if(isset($_FILES['uploaded'])) { // Make sure the file was sent without errors if($_FILES['uploaded']['error'] == 0) { // Connect to the database $dbLink = new mysqli('localhost', 'root', '', 'myfile'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Gather all required data $name = $dbLink->real_escape_string($_FILES['uploaded']['name']); $mime = $dbLink->real_escape_string($_FILES['uploaded']['type']); $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded']['tmp_name'])); $size = intval($_FILES['uploaded']['size']); // Create the SQL query $query = " INSERT INTO `file` ( `name`, `mime`, `size`, `data`, `created`,`login` ) VALUES ( '{$name}', '{$mime}', {$size}, '{$data}' , NOW(),'".$_SESSION['SESS_MEMBER_ID']."' )"; // Execute the query $result = $dbLink->query($query); // Check if it was successfull if($result) { echo 'Success! Your file was successfully added!'; } else { echo 'Error! Failed to insert the file' . "<pre>{$dbLink->error}</pre>"; } } else { echo 'An error accured while the file was being uploaded. ' . 'Error code: '. intval($_FILES['uploaded_file']['error']); } // Close the mysql connection $dbLink->close(); } else { echo 'Error! A file was not sent!'; } // Echo a link back to the main page echo '<p>Click <a href="upload.php">here</a> to go back</p>'; //move to file section $target = "uploads/"; $target = $target . basename( $_FILES['uploaded']['name']) ; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } ?> The $_SESSION['SESS_MEMBER_ID'] is the result of query and this is the code : <?php //Start session session_start(); //Include database connection details require_once('config.php'); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['login']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: login-form.php"); exit(); } //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; $_SESSION['SESS_FIRST_NAME'] = $member['firstname']; $_SESSION['SESS_LAST_NAME'] = $member['lastname']; $_SESSION['SESS_LOGIN'] = $member['login']; session_write_close(); header("location: member-index.php"); //echo $_SESSION['SESS_MEMBER_ID']; //session_id($_SESSION['SESS_MEMBER_ID']); exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/216546-can-any-one-fix-this/ Share on other sites More sharing options...
trq Posted October 22, 2010 Share Posted October 22, 2010 I don't see any call to session_start. Quote Link to comment https://forums.phpfreaks.com/topic/216546-can-any-one-fix-this/#findComment-1125152 Share on other sites More sharing options...
cool.works Posted October 22, 2010 Author Share Posted October 22, 2010 there are a login form any way you can check my code in the attachment please help it made me carzy [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/216546-can-any-one-fix-this/#findComment-1125154 Share on other sites More sharing options...
trq Posted October 22, 2010 Share Posted October 22, 2010 You need to call session_start() within the same scope as any code using the $_SESSION array. Quote Link to comment https://forums.phpfreaks.com/topic/216546-can-any-one-fix-this/#findComment-1125159 Share on other sites More sharing options...
cool.works Posted October 22, 2010 Author Share Posted October 22, 2010 did you check my code please fix it cause am not familiar with session Quote Link to comment https://forums.phpfreaks.com/topic/216546-can-any-one-fix-this/#findComment-1125160 Share on other sites More sharing options...
cool.works Posted October 22, 2010 Author Share Posted October 22, 2010 all is ok i fix it thankx Quote Link to comment https://forums.phpfreaks.com/topic/216546-can-any-one-fix-this/#findComment-1125190 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.