2 Replies - 427 Views - Last Post: 01 May 2010 - 04:16 PM Rate Topic: -----

#1 openinfinity  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 215
  • Joined: 25-March 09

Having trouble inserting this simple piece of data into mysql

Posted 01 May 2010 - 04:08 PM

This code uploads the file into the /uploads dir and the data into the pictures table in mysql
Everything seems to work but the user_id field in the pictures table populates with the numeric value 0
I test the session variable and it prints out exactly what it should so don't know what's going on.


any help appreciated,


<?php
	require_once('auth.php');


include("config.php");


$lname = $_SESSION['SESS_LAST_NAME'];
$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

   	//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");
	}

    
    $query = "INSERT INTO pictures (file_name, user_id, public, default_pic) VALUES ('$target_path', '$lname', 'yes', 'yes')";



      if (mysql_query($query)) {
          echo "inserted successfully <br> redirecting to results in (2) Seconds";
          echo "<meta http-equiv=Refresh content=2;url=edit-member.php>";


      } else {
          echo "Something went terribly wrong!! <br>redirecting to results in (2) Seconds " . mysql_error();
	//  echo "<meta http-equiv=Refresh content=2;url=edit-member.php>";


      }
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";


} else{
    echo "There was an error uploading the file, please try again!";
}


?>
//testing session variable data
<?php echo $lname;?>



Is This A Good Question/Topic? 0
  • +

Replies To: Having trouble inserting this simple piece of data into mysql

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5667
  • View blog
  • Posts: 22,509
  • Joined: 23-August 08

Re: Having trouble inserting this simple piece of data into mysql

Posted 01 May 2010 - 04:14 PM

Is $lname your user_id value? Is user_id a string, and not an integer?
Was This Post Helpful? 0
  • +
  • -

#3 openinfinity  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 215
  • Joined: 25-March 09

Re: Having trouble inserting this simple piece of data into mysql

Posted 01 May 2010 - 04:16 PM

Never mind found the problem

something similar an incorrect datatype :)

thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1