inserting some data in the database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pleigh
Forum Contributor
Posts: 445
Joined: Wed Jan 19, 2005 4:26 am

inserting some data in the database

Post by pleigh »

hi, i have this code for upload and it will successfully upload the file remotely, however, i cant make it to work when it comes to posting some data in the database.

Code: Select all

if (isset($_POST['upload'])) {
	$target = "../uploads/";	
	$target .= $_FILES['uploaded']['name'];
	$ok=1;
	if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
	{
		
		
		$query = "SELECT a.UserKey, a.UserRightsKey, b.level_key, b.level_description
				  FROM ext_Users a 
				  INNER JOIN ext_UserRights b ON (a.UserRightsKey = b.level_key)
				  WHERE a.UserKey = '" . $_SESSION['UserKey'] . "'";
		$result = mysql_query($query) or die(mysql_error());
		
		if ($result) {
			while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
				
				if ($row[3] == "Developer") {
					$query1 = "INSERT INTO ext_WebReleases(Description) 
								VALUES('sample text')";
					$result1 = mysql_query($query1) or die(mysql_error());
					
					if ($result1) {
						
						echo "<b>Successfully uploaded the application.</b><br/>";
						
						
					} else {
						echo "<b>Could not upload the application.</b>";
					}
				} 
			}
		}
		
		echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
		
	}
	else if(!$_FILES['uploaded']) {
		echo "Sorry, there was a problem uploading your file.";
	}
	
}
when i test that code, the message will say "successfully uploaded the application" but the text inside the Description table will not appear. please help me. :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<?php
if ( isset($_POST['upload']) ) {
	$target = "../uploads/";       
	$target .= $_FILES['uploaded']['name'];
	$ok=1;
	if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
	{
		$query = "SELECT a.UserKey, a.UserRightsKey, b.level_key, b.level_description
			FROM ext_Users a
			INNER JOIN ext_UserRights b ON (a.UserRightsKey = b.level_key)
			WHERE a.UserKey = '" . $_SESSION['UserKey'] . "'";
		echo '<div>Debug: ', htmlentities($query), "</div>\n";
		$result = mysql_query($query) or die(mysql_error());

		if ($result) {
			echo '<div>Debug: ', mysql_num_rows($result), " row(s) found</div>\n";
			while ($row = mysql_fetch_array($result, MYSQL_NUM)) {

			if ($row[3] == "Developer") {
				$query1 = 'SELECT Count(*) FROM ext_WebReleases';
				$result1 = mysql_query($query1) or die(mysql_error());
				echo '<div>Debug: ', mysql_result($result1, 0), " rows in ext_WebReleases before INSERT</div>";
				mysql_free_result($result1);
				
				$query1 = "INSERT INTO ext_WebReleases(Description)
					VALUES('sample text')";
				echo '<div>Debug: ', htmlentities($query1), "</div>\n";
				$result1 = mysql_query($query1) or die(mysql_error());
				if ($result1) {
					echo '<div>Debug: ', mysql_affected_rows(), " row(s) affected</div>\n";
					echo "<b>Successfully uploaded the application.</b><br/>";
					
					$query1 = 'SELECT Count(*) FROM ext_WebReleases';
					$result1 = mysql_query($query1) or die(mysql_error());
					echo '<div>Debug: ', mysql_result($result1, 0), " rows in ext_WebReleases after INSERT</div>";
					mysql_free_result($result1);
					
				} else {
					echo "<b>Could not upload the application.</b>";
				}
			}
		}
	}
	echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
}
else if(!$_FILES['uploaded']) {
	echo "Sorry, there was a problem uploading your file.";
}

}
Post Reply