/    Sign up×
Community /Pin to ProfileBookmark

problem grabbing from post

admin “pics.php” admin page:

[code=php]<?php
/*************************
* Created By Parker Phinney
* Version 0.0
* I PWN you
* yeah…
*************************/
$admin = 1;
require(“../header.php”);
$album = $_GET[‘album’];
?>

<div class=”album”>
<div class=”album_wrapper”>
<form method=”post” action=”main.php”>
<p>
<input type=”hidden” name=”pics_admin” value=”1″ />
<input type=”hidden” name=”album” value=”<?php echo $album ?>” />
<?php
echo ‘<div class=”album_title”>’ . $album . ‘</div>’ . “n”;

$result = mysql_query(“SELECT * FROM `pics` WHERE `album` = ‘$album'”)
or die(‘Error retrieving the pictures from the database, MySQL said: ‘ . mysql_error());

while($pic = mysql_fetch_array($result)){

echo(
‘<div class=”album_image”>’ .
‘<a href=”…/’ . $pic[path] . ‘/’ . $pic[name] . ‘”>’ .
‘<img src=”../thumbs/’ . $pic[name] . ‘” alt=”album image”/></a>’ .
‘<br />’ .
‘<input type=”text” name=”caption_’ . $pic[name] . ‘” value=”‘ . $pic . ‘” />’ .
‘<br/>’ .
‘dlt’ .
‘<input type=”checkbox” name=”dlt_’ . $pic[name] . ‘” value=”1″ />’ .
‘</div>’ .
“n”
);

}
echo ‘</div>’ . “n” . ‘</div>’ . “n”;
?>

<input type=”submit” value=”Submit” />
</p>
</form>
<?php
require(“../footer.php”);
?>[/code]

“main.php” , where the data gets sent.

[code=php]
if($_POST[‘pics_admin’]){
$ok = 0;
$num = 0;
$album = $_POST[‘album’];
$result = mysql_query(“SELECT * FROM `pics` WHERE `album` = ‘$album'”);
while($pic = mysql_fetch_array($result, MYSQL_ASSOC)){
$picname = $pic[name];
if($_POST[‘dlt_’ . $picname]){
$num += 1;
if(dltpic_db($picname)){
if(dltpic_svr($picname)){
$ok += 1;
}
else{
$response = $response . $errormsg . “n”;
}
}
else{
$response = $response . $errormsg . “n”;
}
}
}
$response = $response . “$ok of the requested $num pics have been successfully deleted” . “n”;
$ok = 0;
$num = 0;
while($pic = mysql_fetch_array($result)){
if($caption = $_POST[“caption_$pics[name]”]){
if(mysql_query(“UPDATE `pics` SET `caption` = ‘$caption’ WHERE `name` = ‘$pics[name]'”) && mysql_affect_rows() != 0){
$ok += 1;
}
$num += 1;
}
}
$response = $response . “$ok of the requested $num captions have been successfully updated” . “n”;
}
[/code]

edit: lol, forgot to say, the problem is that the script that handles the stuff “main.php” doesn’t seem to be getting the dlt_ stuff from post, though it is getting the album name and stuff. i run this and the response is 0 of the requested 0 pics have been successfully deleted 0 of the requested 0 captions have been successfully updated

ive tried this syntax to grab the post with a variable in the post name and it seemed to work, i dont know what could be wrong. suggestions?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 18.2005 — In main.php, I think you need a [font=courier new][b]mysql_data_seek($result, 0);[/b][/font] before you do your second [font=courier new][b]while($pic = mysql_fetch_array($result)){[/b][/font]
Copy linkTweet thisAlerts:
@gameguy43authorJul 19.2005 — ok... i guess ill try that, but that isnt going to help with the current problem of grabbing the post stuff. ive even tried echoing the elements of the result array in the while statement, and they are all the pics of the correct album. maybe something to do with the syntax of my post statement? or that fact that is is in a while or something?

edit: even if that second while statement totally crapped out, it doesnt matter, ive been mostly playing with the delete functions.

here they are:

(though if there are errors in them thescript should return the correct "out of" number anyway)

[code=php]

//FUNCTION TO DELETE A PIC FROM THE SERVER
function dltpic_svr($name){
global $errormsg;

if($result = mysql_query("SELECT * FROM pics WHERE name = '$name'")){;
$array = mysql_fetch_array($result, MYSQL_ASSOC);
if(unlink("../" . $array[path] . $array[name]) && unlink("../thumbs/" . $array[name])){
return TRUE;
}
else{
$errormsg = "There was a problem deleting the pictures from the server";
return FALSE;
}
}
else{
$errormsg = "There was a problem getting the pictures' info from the database, MySQL said: " . mysql_error();
return FALSE;
}
}

//FUNCTION TO DELETE A PIC FROM THE DATABASE
function dltpic_db($name){
global $errormsg;

if(mysql_query("DELETE FROM pics WHERE name = '$name'")){
return TRUE;
}
else{
$errormsg = "There was a problem deleting the picture(s) from the database, MySQL said: " . mysql_error();
return FALSE;
}
}
[/code]
×

Success!

Help @gameguy43 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...