Hey all, I am building a database for work that will contain some minor data on plant species along with 4 images. I have developed the form and am able to add the data but due to my abilities and I am stuck trying to get the images to post properly. I am looking for some help or better ways of doing what I am trying to do. Here is my code: <?php // ivmdadd.php require_once 'ivmlogin.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " . mysql_error());
mysql_select_db($db_database, $db_server) or die("Unable to select database: " . mysql_error());
if (isset($_POST['commonname'])) $commonname = fix_string($_POST['commonname']); if (isset($_POST['scientificname'])) $scientificname = fix_string($_POST['scientificname']); if (isset($_POST['class'])) $class = fix_string($_POST['class']); if (isset($_POST['color'])) $color = fix_string($_POST['color']); if (isset($_POST['controlcty'])) $controlcty = fix_string($_POST['controlcty']); if (isset($_POST['wsdotrow'])) $wsdotrow = fix_string($_POST['wsdotrow']); if (isset($_POST['prescription'])) $prescription = fix_string($_POST['prescription']);
$fail = validate_commonname($commonname);
echo "<html><head><title>Add IVM Data</title>";
if ($fail == "") { echo "</head><body>IVM data successfully validated and added to the database: $commonname, $scientificname, $class, $color, $controlcty, $wsdotrow, $prescription, $name.</body></html>";
function validate_commonname($field) { if ($field == "") return "Please enter information<br />"; return ""; }
// function validate_scientificname($field) { // if ($field == "") return "No scientificname was entered<br />"; // return ""; // }
// function validate_class($field) { // if ($field == "") return "No class was entered<br />"; // else if (strlen($field) < 5) // return "classs must be at least 5 characters<br />"; // else if (preg_match("/[^a-zA-Z0-9_-]/", $field)) // return "Only letters, numbers, - and _ in classs<br />"; // return ""; // }
// function validate_color($field) { // if ($field == "") return "No color was entered<br />"; // else if (strlen($field) < 6) // return "colors must be at least 6 characters<br />"; // else if ( !preg_match("/[a-z]/", $field) || // !preg_match("/[A-Z]/", $field) || // !preg_match("/[0-9]/", $field)) // return "colors require 1 each of a-z, A-Z and 0-9<br />"; // return ""; // }
// function validate_controlcty($field) { // if ($field == "") return "No controlcty was entered<br />"; // else if ($field < 18 || $field > 110) // return "controlcty must be between 18 and 110<br />"; // return ""; // }
// function validate_wsdotrow($field) { // if ($field == "") return "No wsdotrow was entered<br />"; // else if (!((strpos($field, ".") > 0) && // (strpos($field, "@") > 0)) || // preg_match("/[^a-zA-Z0-9.@_-]/", $field)) // return "The wsdotrow address is invalid<br />"; // return ""; // }
function fix_string($string) { if (get_magic_quotes_gpc()) $string = stripslashes($string); return htmlentities ($string); }