svgmx5 Posted March 19, 2010 Share Posted March 19, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/195811-script-is-not-updating-or-inserting-values-into-database/ Share on other sites More sharing options...
skurai Posted March 19, 2010 Share Posted March 19, 2010 can you print out $logo_main to see what exactly it is trying to store? Quote Link to comment https://forums.phpfreaks.com/topic/195811-script-is-not-updating-or-inserting-values-into-database/#findComment-1028620 Share on other sites More sharing options...
svgmx5 Posted March 19, 2010 Author Share Posted March 19, 2010 Thats the thing..nothing is being stored...i checked the name of the field, and it matches. So the url of the image its just not being stored at all. Quote Link to comment https://forums.phpfreaks.com/topic/195811-script-is-not-updating-or-inserting-values-into-database/#findComment-1028623 Share on other sites More sharing options...
skurai Posted March 19, 2010 Share Posted March 19, 2010 so if you print out on a page the variable $logo_main to the page (comment out the query), it comes out blank? Quote Link to comment https://forums.phpfreaks.com/topic/195811-script-is-not-updating-or-inserting-values-into-database/#findComment-1028625 Share on other sites More sharing options...
PFMaBiSmAd Posted March 19, 2010 Share Posted March 19, 2010 Your <form tag does not have the necessary enctype for an upload to work - http://us.php.net/manual/en/features.file-upload.php Quote Link to comment https://forums.phpfreaks.com/topic/195811-script-is-not-updating-or-inserting-values-into-database/#findComment-1028626 Share on other sites More sharing options...
svgmx5 Posted March 19, 2010 Author Share Posted March 19, 2010 damn...i can't believe i overlooked that...thanks that's what was missing Quote Link to comment https://forums.phpfreaks.com/topic/195811-script-is-not-updating-or-inserting-values-into-database/#findComment-1028627 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.