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());
// Start with the PHP code
$commonname = $scientificname = $class = $color = $controlcty = $wsdotrow = $prescription = "";
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>";
// databse post
$query = "INSERT INTO ivm_data(commonname, scientificname, class, color, controlcty, wsdotrow, prescription, name) VALUES('$commonname','$scientificname', '$class', '$color', '$controlcty', '$wsdotrow', '$prescription', '$name')";
$result = mysql_query($query);
exit;
}
// Now output the HTML and JavaScript code
echo <<<_END
<!-- The HTML section -->
<style>.signup { border: 1px solid #999999;
font: normal 14px helvetica; color:#444444; }</style>
<script type="text/javascript">
function validate(form)
{
fail = validatecommonname(form.commonname.value)
fail += validatescientificname(form.scientificname.value)
fail += validateclass(form.class.value)
fail += validatecolor(form.color.value)
fail += validatecontrolcty(form.controlcty.value)
fail += validatewsdotrow(form.wsdotrow.value)
if (fail == "") return true
else { alert(fail); return false }
}
</script></head>
<body>
<table class="signup" border="0" cellpadding="2"
cellspacing="5" bgcolor="#eeeeee">
<th colspan="2" align="center">Add Data to IVM Database</th>
<tr><td colspan="2"><br />
<p><font color=red size=1><i>$fail</i></font></p>
</td></tr>
<form method="post" action="ivmadd.php" enctype='multipart/form-data'>
<tr><td>Common Name</td><td><input type="text" maxlength="50"
name="commonname" value="$commonname" /></td>
</tr><tr><td>Scientific Name</td><td><input type="text" maxlength="50"
name="scientificname" value="$scientificname" /></td>
</tr><tr><td>Class</td><td><input type="text" maxlength="4"
name="class" value="$class" /></td><input type="text" maxlength="25"
name="color" value="$color" /></td>
</tr><tr><td>Required Control Counties</td><td><textarea name="controlcty" value="$controlcty" cols="50" rows="10" wrap="type"></textarea></td>
</tr><tr><td>On WSDOT ROW</td><td>Yes<input type="checkbox" name="wsdotrow" value="Yes" check="checked" />No<input type="checkbox" name="wsdotrow" value="No" /></td>
</tr><tr><td>Prescription</td><td><input type="text" maxlength="100"
name="prescription" value="$prescription" /></td>
</tr><tr><td>Image 1</td><td><input type='file' name='filename' size='50' />
<tr><td><input type="submit" value="Add" /></td>
</form></table>
<!-- The JavaScript section -->
<script type="text/javascript">
function validatecommonname(field) {
if (field == "") return "No Common Name was entered.\n"
return ""
}
</script></body></html>
_END;
echo "</body></html>";
//PHP functions
if ($_FILES)
{
$name = $_FILES['filename']['name'];
move_uploaded_file($_FILES['filename']['tmp_name'], $name);
echo "Uploaded image '$name'<br /><img src='$name' />";
}
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);
}
?>
Parsed in 0.122 seconds, using GeSHi 1.0.8.4
Concatenate two strings ???
I have string one $string1 and another $string2.How to concatenate (add) both of them $string1+" "+$string2 also check condition for the total string length not more than 100 characters
Check Date/Time in PHP
What I need the code to check is that $reQuest is 24 hours in the past then return a time based on how long ago that was in the past if 24 hours has not passed.if ($reQuest!=""){ if
Writing Windows Device Drivers with C
Yes: one of the nice features of C is void*. You can put anything there and get anything out. Very error prone but absolutely brilliant for device drivers.Try
Product categories for registration
Dear all,
Using two $_POST Function / Switch () statements, second does not work.
Hi all. I’m new to php and am having a problem getting $_POST Function / switch () to work. I am coding a registration form. I ask the user a Yes/No question. Depending on the answer I have an
LinkedList help
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a few issues:Here is the project. Create a lovely polynomial calculator, that takes the equation from
Getting PHP to ammended the selected in option field
Hey Guysthanks for everyones help so far. This site and its users are oozing awesomness.I am busy with a php script for editing users, of which 1 field is the TITLE of the person (mrs, miss, ms) and
first id from db not showing
I have a php script which displays the content of a mysql table as a html table with sorting, delete/update button, etc. the problem is I can't make it show the first value inserted in the db, it only
foreach result into a single variable
Hi,I have this code... Code: [Select]foreach ($_POST['Interests'] as $interest => $value) { echo "Interests: $interest; Value: $value";}How do I store the multiple results in a
preg-match with a string and numbers
Hi, I can't get the expression to work for my preg_match, what I'd like is for it to match the string, but only if it is accompanied by a letter, not a number. So if a string was found with a number