Chrisj Posted November 7, 2009 Share Posted November 7, 2009 I was provided this code for an Upload Form, but I need some help with "do some additional validation here to make sure the submitted data is correct" And "probably do more filtering here". Can you enlighten me on what would be required there? Thanks <?php try { if (false === isset($_POST) || false === isset($_POST['form_submit']) { throw new Exception('The form has not been submitted'); } // collect thge submitted data from $_POST array foreach ($_POST as $k => $v) { $$k = trim($v); // probably do more filtering here // maybe check that data isn't too short or too long etc } // do some additional validation here to make sure // the submitted data is correct $dsn = 'mysql:dbname=testdb;host=127.0.0.1'; $user = 'dbuser'; $password = 'dbpass'; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } // insert new row to the database $statement = $dbh->prepare('INSERT INTO table_name (number, word) VALUES (?, ?)'); $statement->bindParam(1, $number, PDO::PARAM_INT); $statement->bindParam(2, $word, PDO::PARAM_STR, strlen($word)); if (false === $statement->execute(array($number, $word))) { throw new Exception('Failed to insert row to database') } echo 'Everything went successfully '; } catch (Exception $e) { echo $e->getMessage(); } Link to comment https://forums.phpfreaks.com/topic/180640-help-with-upload-form-and-additional-validation/ Share on other sites More sharing options...
cags Posted November 7, 2009 Share Posted November 7, 2009 Frankly I think you've got things back to front. You would need to tell us what data you have and what validation you need based on requirements for length, character type, file type etc. Then we would help you achieve that validation. I don't see how we can help filter/validate when you didn't even stipulate what any of the fields are... Link to comment https://forums.phpfreaks.com/topic/180640-help-with-upload-form-and-additional-validation/#findComment-953074 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.