TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 09-14-2007, 03:40 PM   #1 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default Confused within forms

PHP Code:
while($row mysql_fetch_array($sql)){
    
$qID $row['id'];
    echo 
"<b>Question ID#</b>".$row['id']." - ".$row['question']."?";
    echo 
"<br><b>1st Choice:</b> $row[choice_1]";
    echo 
" - <b>2nd Choice:</b> $row[choice_2]";
    echo 
" - <b>3rd Choice:</b> $row[choice_3]";
    echo 
" - Edit Choices:<input type=\"radio\" name=\"edit_choices\" value=\"".$qID."\"><br/>";
    echo 
"Delete:<input type=\"checkbox\" name=\"selected_question_array[]\" value=\"".$qID."\">";
    echo 
" - Edit:<input type=\"radio\" name=\"selected_edit_question\" value=\"".$qID."\"><br/>";
    echo 
"<br />";
}
echo 
"<input type=\"submit\" name=\"delete\" value=\"Delete Question\">";
echo 
"<input type=\"submit\" name=\"edit\" value=\"Edit Question\">";
echo 
"<input type=\"submit\" name=\"edit_choice\" value=\"Edit Choice\">";
echo 
"</form>"
The above form renders like:

Question ID#1 - Question here
1st Choice: For - 2nd Choice: Against - 3rd Choice: No choice - Edit Choices:radiobox

Question ID#2 - Question here
1st Choice: For - 2nd Choice: Against - 3rd Choice: No choice - Edit Choices:radiobox

Question ID#3 - Question here
1st Choice: For - 2nd Choice: Against - 3rd Choice: No choice - Edit Choices:radiobox
Delete: checkbox - Edit: radiobox

Delete Button Edit Button Edit Choices Button

The delete button works perfectly. However when an question or a question choices are selected to be edited from the radio boxes. It doesn't shows the results in the end.

delete_edit_questions.php file:

PHP Code:
<?php

// Last Modified 18th August 2007

ob_start();
session_start();

include(
'templates/header.php'); // Header template
include('../config/config.php'); // Includes configuration files
include('../lib/functions.php'); // Load all functions from Library

if(!session_is_registered("username")){
header('Location: index.php');
exit();
}
else {

$submit_delete $_POST['delete'];
if(isset(
$submit_delete)){

$sql mysql_query('SELECT * FROM questions') or die(mysql_error());

$selected_question $_POST['selected_question_array'];
foreach (
$selected_question as $qID){
    
mysql_query("DELETE FROM questions WHERE id='$qID'") or die(mysql_error());
    
mysql_query("DELETE FROM answers WHERE question_id='$qID'") or die(mysql_error());
    echo 
"Questions <b>".$qID."</b> deleted!<br/>";
}

}

elseif(isset(
$_POST['edit_choice'])){
    
$edit_choice_qID $_POST['edit_choices'];
    echo 
"<form method=\"POST\" name=\"choices\">";
    echo 
"First Choice(Positive): <input type=\"text\" name=\"choice_1\"><br>";
    echo 
"Second Choice(Negative): <input type=\"text\" name=\"choice_2\"><br>";
    echo 
"Third Choice(Any): <input type=\"text\" name=\"choice_3\"><br>";
    echo 
"<input type=\"hidden\" value=\"".$edit_choice_qID."\" name=\"edit_choices_qID\">";
    echo 
"<input type=\"submit\" name=\"submit_new_choices\" value=\"Edit\">";
    echo 
"</form>";
    if(isset(
$_POST['submit_new_choices'])){
        echo 
$_POST['choice_1'];
    }
}

elseif(isset(
$_POST['edit'])) {
    
$submit_edit $_POST['edit'];
    
$edit_qID $_POST['selected_edit_question'];
    echo 
"<form method=\"POST\" name=\"questions\">";
    echo 
"Enter new question: <input type=\"text\" name=\"new_question\">";
    echo 
"<input type=\"hidden\" value=\"".$edit_qID."\" name=\"selected_edit_q\">";
    echo 
"<input type=\"submit\" name=\"submit_new_question\" value=\"Edit\">";
    echo 
"</form>";
    
$submit_new_question $_POST['submit_new_question'];
    
$new_question $_POST['new_question'];
    
$edit_ID $_POST['selected_edit_q'];
    if(isset(
$submit_new_question)){
        
mysql_query("UPDATE questions SET question='$new_question' WHERE id='$edit_ID'") or die(mysql_error());
        echo 
"Question successfully changed to ".$new_question;
    }
}

include(
'templates/footer.php'); // Footer Template

}

?>
I think I'm lost between the forms, please help. I think I'm wrong with the elseif conditional statements.
Haris is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:40 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design