darkstoine3 Posted October 28, 2010 Share Posted October 28, 2010 My code is a total failure. Any ideas? <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"] ["size"] < 4000000)) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />That means your picture is not right somehow...<br />"; } else { $i=1; while($i<=5000) { if (file_exists("./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]])) { $i++; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]); $i=5000; } } } else { echo "Invalid file... Only 4MB and jpeg/gifs allowed."; } $con = mysql_connect( 'localhost', 'root', 'password') if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("submition", $con) $sql = "INSERT INTO 'submition' ('fname','lname','address1','address2','city','stat_prov_reg','postal_zip','country','email','newsletter') VALUES ('"$POST['element_1_1']."' , '"$POST['element_1_2']."' , '"$POST['element_2_1']."' , '"$POST['element_2_2']."' , '"$POST['element_2_3']."' , '"$POST['element_2_4']."' , '"$POST['element_2_5']."' , '"$POST['element_2_6']."' , '"$POST['element_3']."' , '"$POST['element_7']."')"; mysql_query($sql) or die('Bad Query'); mysql_close($con); ?> <div align="center"> - <a href="http://apps.facebook.com/fourxfourexperience/'>Go Back</a> - </div> Link to comment https://forums.phpfreaks.com/topic/217143-total-php-failure/ Share on other sites More sharing options...
Maq Posted October 28, 2010 Share Posted October 28, 2010 Please be a little more descriptive of why it's a 'failure'... Link to comment https://forums.phpfreaks.com/topic/217143-total-php-failure/#findComment-1127748 Share on other sites More sharing options...
Pikachu2000 Posted October 28, 2010 Share Posted October 28, 2010 You have several syntax errors such as improper string concatenation, using $POST instead of $_POST, and extra/missing brackets. Link to comment https://forums.phpfreaks.com/topic/217143-total-php-failure/#findComment-1127758 Share on other sites More sharing options...
Maq Posted October 28, 2010 Share Posted October 28, 2010 You have several syntax errors such as improper string concatenation, using $POST instead of $_POST, and extra/missing brackets. And to detect all fatal syntax errors set error reporting to max. Link to comment https://forums.phpfreaks.com/topic/217143-total-php-failure/#findComment-1127761 Share on other sites More sharing options...
darkstoine3 Posted November 2, 2010 Author Share Posted November 2, 2010 Awesome. Thanks guys. So so sorry I didn't speciry. Won't happen in future. Link to comment https://forums.phpfreaks.com/topic/217143-total-php-failure/#findComment-1129607 Share on other sites More sharing options...
Maq Posted November 2, 2010 Share Posted November 2, 2010 Awesome. Thanks guys. So so sorry I didn't speciry. Won't happen in future. No problem, just trying to make everyones' lives easier Link to comment https://forums.phpfreaks.com/topic/217143-total-php-failure/#findComment-1129612 Share on other sites More sharing options...
Anti-Moronic Posted November 2, 2010 Share Posted November 2, 2010 ..and your indentation. Change it. Also, you should construct variables where necessary. Like this: $i=1; while($i<=5000) { if (file_exists("./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]])) { $i++; } else { ..... } Should be far cleaner and simpler: $i=1; while($i <= 5000){ $filename = "./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]; if(file_exists($filename)){ $i++ }else{ ..... } } note: not checked for syntax issues. You should use the above structure because your code will be highly unmaintainable as you develop it and it becomes more complex. Link to comment https://forums.phpfreaks.com/topic/217143-total-php-failure/#findComment-1129634 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.