Ich arbeite an einem CMS mit PHP OOP. In diesem Projekt gibt es eine Funktion für Benutzer, um einen neuen Telegrammkanal hinzuzufügen. Für diese Funktion habe ich diese Form, die auch die Aktionscodes enthält:Wie füge ich mehrere Radio Button Werte mit PHP OOP
<?php
if(isset($_POST['submit'])){
$token = $_POST['token'];
$cat = $_POST['cat'];
$ads = $_POST['ads'];
$key = $_POST['keyboard'];
$tel = new Telegram();
$notice = $tel->AddNew($token,$cat,$ads,$key);
}
?>
<div class='content-wrapper'>
<section class='content-header'>
<h1>
Add New Telegram Account
<small>You can add a new Telegram channel here</small>
</h1>
<ol class='breadcrumb'>
<li class='active'>telegram.php</li>
</ol>
</section>
<?php
if($dataSet->GetLevel()==1)
{ echo "
<section class='content'>
<div class='row'>
<div class='col-md-6'>
<div class='box box-primary'>
<div class='box-header with-border'>
<h3 class='box-title'>Required Information</h3>
</div>
";
if(isset($notice['success_message'])){
echo "
<div class='alert alert-success'>
<strong>Hey!</strong> ".$notice['success_message'].".
</div>
";
}
echo "
<form role='form' method='POST' action=''>
<div class='box-body'>
<div class='form-group'>
<label>Token Number</label>
<input type='text' class='form-control' placeholder='Enter token' name='token' required>
<a href='#' style='color:purple;'>Having problem while getting token</a>
</div>
<div class='form-group'>
<label>Select Category</label>
<select name='cat' class='form-control'>
<option value='empty'>---</option>
<option value='technology'>Technology</option>
<option value='4fun'>Game & Fun</option>
<option value='news'>News</option>
<option value='tools'>Tools</option>
<option value='learning'>Learning</option>
<option value='traditional'>Traditional</option>
<option value='media'>Media</option>
</select>
</div>
<div class='form-group'>
<div class='radio'>
<label>
<input type='radio' name='ads' id='optionsRadios1' value='on' checked>
Set ads on</br>
<input type='radio' name='ads' id='optionsRadios1' value='off'>
Set ads off
</label>
</div>
</div>
<div class='form-group'>
<div class='checkbox'>
<label>
<input type='checkbox' name='keyboard' value='with_keyboard'>
Use dedicated keyboard for this bot
</label></br>
<label>
<input type='checkbox' name='keyboard' value='without_keyboard'>
Show keyboard at groups
</label></br>
<label>
<input type='checkbox' name='answer' value='answer_messages_chats' checked>
In private chats, just anwser the pre defined messages
</label></br>
<label>
<input type='checkbox' name='answer' value='answer_messages_groups' checked>
In groups, just answer the pre defined messages
</label>
</div>
</div>
</div>
<div class='box-footer'>
Visit <a href='https://zite.pouyavagefi.com/documentation/telegram.php'>Telegram</a> Social Media Documentation.
</div>
<div class='box-footer'>
<button name='submit' type='submit' class='btn btn-primary'>Submit</button>
</div>
</form>
</div>
</div>
</div>
</section> ";
}else{
echo "
<section class='content'>
<div class='alert alert-warning'>
<strong>Access Denied!</strong> You don\'t have permission to access this page.
</div>
</section> ";
}
?>
</div>
Wie Sie an der Spitze kann, habe ich eine Klasse genannt, die Telegram.class.php
genannt wird und diese Klasse geht so:
<?php
class Telegram
{
protected $notice = array();
private $db;
public function __construct()
{
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function AddNew($token,$cat,$ads,$key)
{
if(!empty($token)&&!empty($cat)&&!empty($ads))
{
for ($i=0;$i<sizeof($ads);$i++)
{
for ($i=0;$i<sizeof($key);$i++)
{
$new = $this->db->prepare("INSERT INTO channels (token_number, category_name, ads_set, keyboard_status) VALUES (?, ?, "/*.$ads[$i].*/", "/*.$key[$i].*/")");
$new->bindParam(1,$token);
$new->bindParam(2,$cat);
$new->bindParam(3,$ads);
$new->bindParam(4,$key);
$new->execute();
$notice['success_message'] = "New Telegram Channel was successfully added";
return $this->notice;
}
}
}
}
public function getNotice()
{
return $this->notice;
}
}
?>
Da ich mehrere Kontrollkästchen in Tabelle hinzugefügt werden soll, verwendet für diese I-Schleife innerhalb des Verfahrens Add_New (Gemäß diesem qeustion):
for ($i=0;$i<sizeof($ads);$i++)
{
for ($i=0;$i<sizeof($key);$i++)
{
$new = $this->db->prepare("INSERT INTO channels (token_number, category_name, ads_set, keyboard_status) VALUES (?, ?, "/*.$ads[$i].*/", "/*.$key[$i].*/")");
$new->bindParam(1,$token);
$new->bindParam(2,$cat);
$new->bindParam(3,$ads);
$new->bindParam(4,$key);
$new->execute();
$notice['success_message'] = "New Telegram Channel was successfully added";
return $this->notice;
}
}
Ich weiß es nicht richtig ist, aber ich weiß nicht, den richtigen Weg, um diese $ Anzeigen [$ i] und $ key [$ i] Variablen in die Einsatz Anweisung hinzufügen ...
Also, wenn Sie wissen, wie man das in der richtigen Reihenfolge macht, lassen Sie es mich bitte wissen .. danke!
Was ist dann mit der Klasse, keine Änderung in der Klassendatei? – wrephebiajou
Ja Klasse wird geändert. Es ist nicht erforderlich, ein Array zu durchlaufen, wenn der Wert in eine Zeichenfolge konvertiert wurde. Antwort aktualisiert – Star