Question: create.php: Create function toggleDatePicker() { var radio1 = document.getElementById(option1); var radio2 = document.getElementById(option2); var datepickerContainer = document.getElementById(datepicker-container); // If End Date is selected, show the
create.php:
function toggleDatePicker() {
var radio1 = document.getElementById("option1");
var radio2 = document.getElementById("option2");
var datepickerContainer = document.getElementById("datepicker-container");
// If "End Date" is selected, show the date picker
if (radio2.checked) {
datepickerContainer.style.display = "block";
}
// Otherwise, if "Manually" is selected, hide the date picker
else if (radio1.checked) {
datepickerContainer.style.display = "none";
}
}
$uid="0";
if(isset($_GET['uid']))
$uid=$_GET['uid'];
?>
$usid = "0";
$usid = $_GET['uid'];
echo "
//page header
echo "
//Check if the user is logged in
require('connection.php');
$sql = "SELECT name FROM users WHERE uid = :usid";
$stmt = $db->prepare($sql);
$stmt->bindParam(':usid', $usid);
$stmt->execute();
//If the user is logged in, display "Welcome username"
if ($row = $stmt->fetch()) {
$username = $row['name'];
echo "$username!";
}
//If the user is not logged in, display "Welcome User not found"
else {
echo "User not found.";
}
echo "
";
?>
Start Creating A New Poll
Complete the below fields to create your poll
"?>
Save_data.php:
$uid = $_GET['uid'];
try {
require 'connection.php';
$uid="0";
if(isset($_GET['uid']))
$uid=$_GET['uid'];
if(isset($_POST['submit'])) {
$Ptitle = $_POST['Ptitle'];
$question = $_POST['question'];
$endby=$_POST['option'];
//$endtype="0";
$statues="open";
$options = array();
if($endby==0){
$endtype="manually";
$statues="open";
$stmt = $db->prepare("INSERT INTO poll (uid, title, question, end_by, statues) VALUES (:uid, :title, :question, :endtype, :statues)");
$stmt->bindParam(':uid', $uid);
$stmt->bindParam(':title', $Ptitle );
$stmt->bindParam(':question', $question);
$stmt->bindParam(':endtype', $endtype);
$stmt->bindParam(':statues', $statues);
$stmt->execute();
}
else{
$endtype="date";
$enddate=$_POST['enddate'];
$stmt = $db->prepare("INSERT INTO poll (uid, title, question, end_by, end_date, statues) VALUES (:uid, :title, :question, :endtype, :end_date, :statues)");
$stmt->bindParam(':uid', $uid);
$stmt->bindParam(':title', $Ptitle );
$stmt->bindParam(':question', $question);
$stmt->bindParam(':endtype', $endtype);
$stmt->bindParam(':end_date', $enddate);
$stmt->bindParam(':statues', $statues);
$stmt->execute();
}
$pollID= $db -> lastinsertid();
foreach ($_POST as $key => $value) {
if (strpos($key, 'input') === 0) {
// Add the option to the options array
$options[] = $value;
}
}
$optionStmt = $db->prepare("INSERT INTO polloptions (pid, `option text`) VALUES (:pid, :opText)");
foreach ($options as $optionID => $optionText) {
// Insert the option into the options table with the poll ID as the foreign key
$optionStmt->execute(array(':pid' => $pollID, ':opText' => $optionText));
}
{$cssStyles = 'color: black; align-items:center; text-align:center; font-size: 30px; margin-top: 150px';
echo '
poll created successfully
';echo "
}
}
$db = null;
}
catch (PDOException $exc) {
echo $exc->getMessage ();
exit () ;
}
?>
I want you to add a stop button in the created poll so the owner of the poll can end the poll at any time by clicking on the stop button ( stop button will appear at every created poll) in my code there is one way to end the poll which is by choosing a date to close it the stop button is missing add it please and check if end date that ends the poll by date works well if not fix it also
CREATE TABLE `poll` (
`pid` int(11) NOT NULL,
`uid` int(11) NOT NULL,
`title` varchar(200) NOT NULL,
`question` text NOT NULL,
`end_by` varchar(200) NOT NULL,
`end_date` varchar(200) DEFAULT NULL,
`statues` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
