Salve a tutti,
ho un problema con uno script che mi permette di effettuare bene l'upload di più immagini (2), ma non appena provo a modificare altre variabili mysql, dal database vengono inesorabilmente cancellati i nomi delle due immagini caricate al momento dell'apertura dell'account. Immagino che il problema stia nello script che ho inserito nella sezione update...
Posto dunque il codice, sperando che qualcuno di voi possa aiutarmi...
1)
function addform($op,$vars) {
echo "<p align=center><b>Enter site information</b></p>";
echo "<form action=\"$_SERVER[PHP_SELF]?op=$op&d_op=save\" enctype=\"multipart/form-data\" method=POST>";
echo "<table border=0 align=center>";
if ($op != "update") {
echo "<tr><td>Username:</td><td><input type=text name=user_name value=\"$vars[user_name]\"></td></tr>";
echo "<tr><td>Password:</td><td><input type=password name=user_pass></td></tr>";
}
echo "<tr><td>Email:</td><td><input type=text name=user_email value=\"$vars[user_email]\"></td></tr>";
echo "<tr><td>Site name:</td><td><input name=site_name value=\"$vars[site_name]\"></td></tr>";
echo "<tr><td>Site url:</td><td><input name=site_url value=\"$vars[site_url]\"></td></tr>";
echo "<tr><td>
<b>Picture 1:</b>
</td><td><input
type=file name=site_picture_1 value=\"$vars[site_picture_1]\"></td></tr>";
echo "<tr><td>
<b>Picture 2:</b></td><td><input type=file name=site_picture_2 value=\"$vars[site_picture_2]\"></td></tr>";
echo "<tr><td colspan=2>Description:<br><textarea cols=50 rows=3 name=site_description>$vars[site_description]</textarea></td></tr>";
echo "<tr><td colspan=2><input type=submit value=\"Submit site\"></td></tr>";
echo "</table>";
echo "</form>";
}
function add() {
global $db,$siteconfig;
$user = addslashes_data($_POST[user_name]);
if ($_GET[d_op] == "") {
include("templates/lt_header.php");
echo "<br><hr noshade>$siteconfig[site_join_text]<hr noshade>";
echo "Your site will show up on the list once you start sending visitors<p>";
addform('join','');
} else if ($_GET[d_op] == "save") {
if ($_POST[site_name] == '' OR
$_POST[site_url] == '' OR
$_POST[site_description] == '' OR
$_POST[user_name] == "" OR
$_POST[user_pass] == "" OR
$_POST[user_email] == "") {
include("templates/lt_header.php");
errmsg(array("You did not fill in a required field"));
addform('join',$_POST);
} else {
if ($db->sql_numrows($db->sql_query("SELECT site_id FROM "._SITES_TABLE." WHERE LOWER(user_name) = '".strtolower($user)."'")) > 0) {
include("templates/lt_header.php");
errmsg(array('<p>There is already a user with that username. Please choose another one.<p>'));
} else {
setcookie('user',base64_encode("$_POST[user_name]:".md5($_POST[user_pass]).":".time()),NULL,'/','',0);
include("templates/lt_header.php");
$target_a = "images-1/";
$target_b = "images-2/";
$target_1 = $target_a . basename( $_FILES['site_picture_1']['name']);
$target_2 = $target_b . basename( $_FILES['site_picture_2']['name']);
if(move_uploaded_file($_FILES['site_picture_1']['tmp_name'], $target_1))
{
echo "The files ". basename( $_FILES['site_picture_1']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if(move_uploaded_file($_FILES['site_picture_2']['tmp_name'], $target_2
))
{
echo "The files ". basename( $_FILES['site_picture_2']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if($db->sql_query("INSERT INTO "._SITES_TABLE." VALUES (NULL, '$user', '".addslashes_data(md5($_POST[user_pass]))."', "
."'".addslashes_data($_POST[user_email])."', "
."'".time()."', "
."'".addslashes_data($_POST[site_name])."', "
."'".addslashes_data($_POST[site_url])."', "
."'".addslashes_data($_FILES[site_picture_1][name])."', "
."'".addslashes_data($_FILES[site_picture_2][name])."', "
."'".addslashes_data($_POST[site_description])."', '0','0','0','0')")){
echo "<p>Thank you for your submission! We will review it and add it soon! Be sure to put the <a href=\"$_SERVER[PHP_SELF]?op=code\">partner code</a> into your site.<p>";
} else {
errmsg($db->sql_error());
}
}
}
}
include("templates/lt_footer.php");
}
2) function update() {
global $db, $userconfig;
include('templates/lt_header.php');
echo "<p align=center><b>Update site</b></p>";
if (is_user($_COOKIE[user])) {
if ($_GET[d_op] != 'save') {
$site = $db->sql_fetchrow($db->sql_query("SELECT * FROM "._SITES_TABLE." WHERE LOWER(user_name) = '".strtolower($userconfig[user_name])."' LIMIT 1"));
addform('update',$site);
} else {
$target_a = "images-1/";
$target_b = "images-2/";
$target_1 = $target_a . basename( $_FILES['site_picture_1']['name']);
$target_2 = $target_b . basename( $_FILES['site_picture_2']['name']);
if(move_uploaded_file($_FILES['site_picture_1']['tmp_name'], $target_1))
{
echo "The files ". basename( $_FILES['site_picture_1']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if(move_uploaded_file($_FILES['site_picture_2']['tmp_name'], $target_2))
{
echo "The files ". basename( $_FILES['site_picture_2']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
$db->sql_query("UPDATE "._SITES_TABLE." SET site_name = '".addslashes_data($_POST[site_name])."',
site_url = '".addslashes_data($_POST[site_url])."',
site_picture_1 = '".addslashes_data($_FILES[site_picture_1][name])."',
site_picture_2 = '".addslashes_data($_FILES[site_picture_2][name])."',
site_description = '".addslashes_data($_POST[site_description])."', user_email = '".addslashes_data($_POST[user_email])."', site_isactive='0' WHERE LOWER(user_name) = '$userconfig[user_name]'") or errmsg($db->sql_error());
echo "<p>Your changes have been saved. Your site has been deactivated until we can approve the changes.<p>";
}
} else {
loginform(urlencode('op=update'));
}
include('templates/lt_footer.php');
}
ho un problema con uno script che mi permette di effettuare bene l'upload di più immagini (2), ma non appena provo a modificare altre variabili mysql, dal database vengono inesorabilmente cancellati i nomi delle due immagini caricate al momento dell'apertura dell'account. Immagino che il problema stia nello script che ho inserito nella sezione update...
Posto dunque il codice, sperando che qualcuno di voi possa aiutarmi...
1)
function addform($op,$vars) {
echo "<p align=center><b>Enter site information</b></p>";
echo "<form action=\"$_SERVER[PHP_SELF]?op=$op&d_op=save\" enctype=\"multipart/form-data\" method=POST>";
echo "<table border=0 align=center>";
if ($op != "update") {
echo "<tr><td>Username:</td><td><input type=text name=user_name value=\"$vars[user_name]\"></td></tr>";
echo "<tr><td>Password:</td><td><input type=password name=user_pass></td></tr>";
}
echo "<tr><td>Email:</td><td><input type=text name=user_email value=\"$vars[user_email]\"></td></tr>";
echo "<tr><td>Site name:</td><td><input name=site_name value=\"$vars[site_name]\"></td></tr>";
echo "<tr><td>Site url:</td><td><input name=site_url value=\"$vars[site_url]\"></td></tr>";
echo "<tr><td>
<b>Picture 1:</b>
</td><td><input
type=file name=site_picture_1 value=\"$vars[site_picture_1]\"></td></tr>";
echo "<tr><td>
<b>Picture 2:</b></td><td><input type=file name=site_picture_2 value=\"$vars[site_picture_2]\"></td></tr>";
echo "<tr><td colspan=2>Description:<br><textarea cols=50 rows=3 name=site_description>$vars[site_description]</textarea></td></tr>";
echo "<tr><td colspan=2><input type=submit value=\"Submit site\"></td></tr>";
echo "</table>";
echo "</form>";
}
function add() {
global $db,$siteconfig;
$user = addslashes_data($_POST[user_name]);
if ($_GET[d_op] == "") {
include("templates/lt_header.php");
echo "<br><hr noshade>$siteconfig[site_join_text]<hr noshade>";
echo "Your site will show up on the list once you start sending visitors<p>";
addform('join','');
} else if ($_GET[d_op] == "save") {
if ($_POST[site_name] == '' OR
$_POST[site_url] == '' OR
$_POST[site_description] == '' OR
$_POST[user_name] == "" OR
$_POST[user_pass] == "" OR
$_POST[user_email] == "") {
include("templates/lt_header.php");
errmsg(array("You did not fill in a required field"));
addform('join',$_POST);
} else {
if ($db->sql_numrows($db->sql_query("SELECT site_id FROM "._SITES_TABLE." WHERE LOWER(user_name) = '".strtolower($user)."'")) > 0) {
include("templates/lt_header.php");
errmsg(array('<p>There is already a user with that username. Please choose another one.<p>'));
} else {
setcookie('user',base64_encode("$_POST[user_name]:".md5($_POST[user_pass]).":".time()),NULL,'/','',0);
include("templates/lt_header.php");
$target_a = "images-1/";
$target_b = "images-2/";
$target_1 = $target_a . basename( $_FILES['site_picture_1']['name']);
$target_2 = $target_b . basename( $_FILES['site_picture_2']['name']);
if(move_uploaded_file($_FILES['site_picture_1']['tmp_name'], $target_1))
{
echo "The files ". basename( $_FILES['site_picture_1']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if(move_uploaded_file($_FILES['site_picture_2']['tmp_name'], $target_2
))
{
echo "The files ". basename( $_FILES['site_picture_2']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if($db->sql_query("INSERT INTO "._SITES_TABLE." VALUES (NULL, '$user', '".addslashes_data(md5($_POST[user_pass]))."', "
."'".addslashes_data($_POST[user_email])."', "
."'".time()."', "
."'".addslashes_data($_POST[site_name])."', "
."'".addslashes_data($_POST[site_url])."', "
."'".addslashes_data($_FILES[site_picture_1][name])."', "
."'".addslashes_data($_FILES[site_picture_2][name])."', "
."'".addslashes_data($_POST[site_description])."', '0','0','0','0')")){
echo "<p>Thank you for your submission! We will review it and add it soon! Be sure to put the <a href=\"$_SERVER[PHP_SELF]?op=code\">partner code</a> into your site.<p>";
} else {
errmsg($db->sql_error());
}
}
}
}
include("templates/lt_footer.php");
}
2) function update() {
global $db, $userconfig;
include('templates/lt_header.php');
echo "<p align=center><b>Update site</b></p>";
if (is_user($_COOKIE[user])) {
if ($_GET[d_op] != 'save') {
$site = $db->sql_fetchrow($db->sql_query("SELECT * FROM "._SITES_TABLE." WHERE LOWER(user_name) = '".strtolower($userconfig[user_name])."' LIMIT 1"));
addform('update',$site);
} else {
$target_a = "images-1/";
$target_b = "images-2/";
$target_1 = $target_a . basename( $_FILES['site_picture_1']['name']);
$target_2 = $target_b . basename( $_FILES['site_picture_2']['name']);
if(move_uploaded_file($_FILES['site_picture_1']['tmp_name'], $target_1))
{
echo "The files ". basename( $_FILES['site_picture_1']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
if(move_uploaded_file($_FILES['site_picture_2']['tmp_name'], $target_2))
{
echo "The files ". basename( $_FILES['site_picture_2']['name']). " has been uploaded.";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
$db->sql_query("UPDATE "._SITES_TABLE." SET site_name = '".addslashes_data($_POST[site_name])."',
site_url = '".addslashes_data($_POST[site_url])."',
site_picture_1 = '".addslashes_data($_FILES[site_picture_1][name])."',
site_picture_2 = '".addslashes_data($_FILES[site_picture_2][name])."',
site_description = '".addslashes_data($_POST[site_description])."', user_email = '".addslashes_data($_POST[user_email])."', site_isactive='0' WHERE LOWER(user_name) = '$userconfig[user_name]'") or errmsg($db->sql_error());
echo "<p>Your changes have been saved. Your site has been deactivated until we can approve the changes.<p>";
}
} else {
loginform(urlencode('op=update'));
}
include('templates/lt_footer.php');
}