Jump to content

script is not updating or inserting values into database


svgmx5

Recommended Posts

I'm having an interesting issue here. What i have is a form that uploads a file and a title into a database. The script checks to see if a row allready exists if it does then it just updates the current row, otherwise if no row exists in the database then it inserts a new one.

 

What's happening is that it runs the query, and inserts all the values, but the $logo_main  value. I've looked it over and over and i can't find the problem.

 

I've included the script that runs the form as well as the form itself, I hope its not too much code...

 

if(isset($_POST['upLogo1'])){
        $target = "../../images/"; // folder where image is stored on server
	$logo_main=($_FILES['main']['name']);
	$u_alt_logo_txt = $_POST['main_txt'];
	$dest = $target.$logo_main;

                //this checks to see if a row with the field logo_style allready exists
	$check_logo_tbl = "SELECT * FROM logo_tbl WHERE logo_style='main'";
	$check_logo_query = mysql_query($check_logo_tbl) or die(mysql_error());
	$check_rows = mysql_num_rows($check_logo_query);

	if($check_rows!=1){

                         //if it doesn't then it inserts a new row					
		$u_logo_query = "INSERT INTO logo_tbl (logo_url, logo_alt_txt, logo_style) VALUES('$logo_main', '$u_alt_logo_txt', 'main')";
		$u_run_query = mysql_query($u_logo_query) or die(mysql_error());

		if($u_run_query){
			$move_up_logo=move_uploaded_file($_FILES['main']['tmp_name'], $dest);
			if($move_up_logo){
				echo '
					<h1>Logo Has been uploaded</h1>
				';
				}else{
				echo'
					<h1>There was an error uploading the logo</h1>
				';
				}

			}
		}else{
                                //otherwise if a row allready exists then it just updates the current row
			$update_logo_tbl = "UPDATE logo_tbl SET logo_url='$logo_main', logo_alt_txt='$u_alt_logo_txt' WHERE logo_style='main'";
			$update_query = mysql_query($update_logo_tbl) or die(mysql_error());

			if($update_query){

				$move_up_logo=move_uploaded_file($_FILES['main']['tmp_name'], $dest);

				if($move_up_logo){
					echo '
						<h1>You have uploaded a new Logo</h1>
					';
				}
			}
		}
         }
?>

<form method="post" action="">
        <input name="main" type="file" /><br/>
        <input type="text" name="main_txt" /><br/>
        <input type="submit" name="upLogo1" value="Upload" />
</form>

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.