liam1412 Posted January 31, 2007 Share Posted January 31, 2007 Hey up People Well I have this little script that took me ages. Basically it's an image upload but I want people to be able to Select the picture they are uploading as there default so It will appear on there profile. Its been working for the last few days, but just gone on to show my mate today and no matter if the box is checked or not its setting the default flag ??? Any way here is my code <input class="input" type="checkbox" name="default" value="default" /> And the PHP it posts to. I must have just deleted summat by mistake but can't I chuffin spot it <?php session_start(); $username = $_SESSION['username']; $userid = $_GET['userid']; $img_cap = $_POST['caption']; $default = '0'; $host = 'localhost'; $db_username = 'root'; $db_password = ''; $db_name = 'klubdeutsch'; mysql_connect("$host" , "$db_username" , "$db_password")or die("Cannot Connect to Server"); mysql_select_db("$db_name")or die("Cannot connect to Database"); if(isset($_POST['default'])){ if($_POST['default'] == 'default'){ $default = '1'; } } if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)){ $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg") && ($_FILES["uploaded_file"]["size"] < 350000)){ $newname = dirname(__FILE__).'/images/profilepics/'.$username.$filename; if (!file_exists($newname)){ if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))){ if($default = '1'){ $def_img_query = "SELECT * FROM images WHERE user_id='$userid' AND def_img='1'"; $query = mysql_query($def_img_query); $num_rows = mysql_num_rows($query); if($num_rows != 0){ $array = mysql_fetch_array($query); $img_id = $array['img_id']; $remove_def_flag = mysql_query("UPDATE images SET def_img = 0 WHERE img_id='$img_id'"); } } $sql_update_images = mysql_query("INSERT INTO images (user_id, img_src, img_cap, def_img) VALUES ('$userid', '$username$filename', '$img_cap', '$default')")or die(mysql_error()); { header("location:profile_test.php?userid=$userid"); } } else { echo "Error: A problem occurred during file upload!"; } } else { echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists"; } } else { echo "Error: Only .jpg images under 350Kb are accepted for upload"; } } else { echo "Error: No file uploaded"; } ?> Anyways hope you all have a good evening and happy hunting. I been looking at it for over an hour!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/36560-solved-mmmmm-my-upload-script-that-did-just-what-i-wanted-it-to-till-now/ Share on other sites More sharing options...
HuggieBear Posted January 31, 2007 Share Posted January 31, 2007 Search for this code... if($default = '1'){ And replace it with this... if($default == '1'){ Notice the two == signs. Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36560-solved-mmmmm-my-upload-script-that-did-just-what-i-wanted-it-to-till-now/#findComment-174099 Share on other sites More sharing options...
liam1412 Posted February 1, 2007 Author Share Posted February 1, 2007 GEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEENIOUS!!!!! I ******** hate it when it is summat that small. Sometimes just takes a 2nd pair of eyes. Thanks Mate Quote Link to comment https://forums.phpfreaks.com/topic/36560-solved-mmmmm-my-upload-script-that-did-just-what-i-wanted-it-to-till-now/#findComment-174107 Share on other sites More sharing options...
HuggieBear Posted February 1, 2007 Share Posted February 1, 2007 Your welcome. I really must get myself a name badge with 'Genius' written on it. You're about the third person today to call me that Anyway, glad it worked. Huggie Quote Link to comment https://forums.phpfreaks.com/topic/36560-solved-mmmmm-my-upload-script-that-did-just-what-i-wanted-it-to-till-now/#findComment-174109 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.