Trouble editing member information w/o erasing pic in db
Posted: Mon Oct 24, 2005 11:51 pm
I am working on building a website for my fraternity. The Section I am working on now is going to be a memebrs section that will include all the members information and a picture of them. I will then store this info into a table. I have all of it figured out how to input the data, how to edit the data, and how to upload the pictures. When i go to edit the members section i have a form that has all the information in formation in it for the user to change if they want and at the bottom is an empty file input.
Now my idea was that when i went to process the form, i would just use check to see if the form returned an empty value and if it did, it would not need to register a new picture in the database.
Having said that I will post the relevent code.
This is the form that displays the member information for the user to edit.
This is the file that processes the said form and inputs it into the mysql database
Currently the when the code is run, i can input a picture but when I try to change the data without changing the picture, it will put '' in the database wehre the uniqid used to be for the picture.
This is my first post so let me know if you need any more info.
Thanks in advance.
Now my idea was that when i went to process the form, i would just use check to see if the form returned an empty value and if it did, it would not need to register a new picture in the database.
Having said that I will post the relevent code.
This is the form that displays the member information for the user to edit.
Code: Select all
<?php
$name = $_POST[name];
$conn = include("library/open_conn_db.php");
$sql = "SELECT * FROM members_page WHERE name = '{$name}';";
$result = mysql_query($sql, $conn) or die(mysql_error());
if (!$result) {
echo "could not do the search ($sql) from db: ".mysql_error();
echo "<br> tell Rayn about this";
}
if (mysql_num_rows($result) == 0) {
echo "No results for that name, try using the full name<br>";
}
print "<form enctype=multipart/form-data action=edit_member_submit.php method=post>";
while ($newArray = mysql_fetch_assoc($result)){
$roll_number = $newArray['roll_number'];
$name = $newArray['name'];
$classification = $newArray['classification'];
$major = $newArray['major'];
$interests = $newArray['interests'];
$birthday = $newArray['birthday'];
$email = $newArray['email'];
$position = $newArray['position'];
$picture = $newArray['picture'];
print "<b>Name:</b><input type=text name=name size=20 value='$name'> <br>";
print "<b>Roll Number:</b> GT<input type=text name=roll_no size=5 value='$roll_number'> <br>";
print "<b>Class: </b><input type=text name=classif value='$classification'><br>";
print "<b>Major:</b><input type=text name=major value='$major'><br>";
print "<b>Interests:</b><input type=text size=30 name=interests value='$interests'> <br>";
print "<b>Email:</b><input type=text size=30 name=email value='$email'><br>";
print "<b>Position:</b><input type=text name=position value='$position'><br><br>";
print "Current picture:<br><img src=library/pictures/$picture><br><input type=hidden name=picture value='picture'>";
print "<b>New Picture:</b><input type=file name=fileupload><br>";
print "Leave blank to keep current picture.<br>";
print "<input type=submit name=\"Submit\" value=\"Edit This Member\">";
}
print "</form>";
?>This is the file that processes the said form and inputs it into the mysql database
Code: Select all
$rollnumber = $_POST[roll_no];
$name = $_POST[name];
$classification = $_POST[classif];
$major = $_POST[major];
$interests = $_POST[interests];
$birthday= $_POST[birthday];
$email = $_POST[email];
$position = $_POST[position];
$picture = $_POST[picture];
$conn = include("library/open_conn_db.php");
$file_dir = "htdocs\library\pictures";
$uniq = uniqid("");
foreach($_FILES as $file_name => $file_array) {
if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'], "$file_dir\\$uniq") or die("could not upload");
print "file was uploaded<br><br>";
}
}
if(empty($file_array['name'])){
$sql = "replace into members_page values ('$name', '$rollnumber', '$classification', '$major', '$interests', '$birthday', '$email', '$position', '$picture');";
print "empty";
}else{
$sql = "replace into members_page values ('$name', '$rollnumber', '$classification', '$major', '$interests', '$birthday', '$email', '$position', '$uniq');";
}
//execute SQL statemnt;
$result = mysql_query($sql, $conn) or die(mysql_error());
//echo the result;
if ($result = 1) {
print "Edit Successful <br>";
print "<a href=index.html>Return to Administration Panel</a>";
}else{
print " Error, Try and repeat problem and report to Ryan";
print "<a href=index.html>Return to Administration Panel</a>";
}
?>Currently the when the code is run, i can input a picture but when I try to change the data without changing the picture, it will put '' in the database wehre the uniqid used to be for the picture.
This is my first post so let me know if you need any more info.
Thanks in advance.