PHP / MySQL - PHP Nasıl PHP kullanarak bir web sayfasındaki metni herhangi bir yerde üretilen görüntülemek için?

1 Cevap php

Ben herhangi bir şey onlar sunulan kullanıcı anlatmak için metin oluşturur web sayfasında nerede yazısının bir bölümünü görüntülemek isteyebilirsiniz.

Nasıl benim komut dosyası içinde sipariş bunu düzeltebilirim? Ve benim kodun hangi parçası değiştirilmesi gerekir?

Burada bir web sayfasında herhangi bir yerde görüntülemek istediğiniz komut dosyasının parçasıdır.

if (count($tags) == 1){
		echo $tags[0] . " has been entered";
} else {
		echo implode(", ", $tags) . " have been entered";			
}

İşte tam yazısıdır.

<?php
if (isset($_POST['submitted'])) {
	$mysqli = new mysqli("localhost", "root", "", "sitename");
	$dbc = mysqli_query($mysqli,"SELECT questions_tags.*, tags.* FROM questions_tags, tags");
	if (!$dbc) {
		print mysqli_error($mysqli);
	}

	$page = '3';

	$tag = mysqli_real_escape_string($mysqli, $_POST['tag']);

	$mysqli = new mysqli("localhost", "root", "", "sitename");
	$dbc = mysqli_query($mysqli,"SELECT questions_tags.*, tags.* FROM questions_tags INNER JOIN tags ON tags.id = questions_tags.tag_id WHERE questions_tags.users_questions_id='$page'");

	if(mysqli_num_rows($dbc) >= 0){

		if (isset($_POST['tag'])) {
				$tags = explode(",", $_POST['tag']);

				for ($x = 0; $x < count($tags); $x++){
						$mysqli = new mysqli("localhost", "root", "", "sitename");
						$clean_url = mysqli_real_escape_string($mysqli, $page);

						$query1 = "INSERT INTO tags (tag) VALUES ('" . $tags[$x] . "')";

						if (!mysqli_query($mysqli, $query1)) {
								print mysqli_error($mysqli);
								return;
						}

						$mysqli = new mysqli("localhost", "root", "", "sitename");
						$dbc = mysqli_query($mysqli,"SELECT id FROM tags WHERE tag='" . $tags[$x] . "'");


						if (!$dbc) {
								print mysqli_error($mysqli);
						}  else {
								while($row = mysqli_fetch_array($dbc)){
										$id = $row["id"];
								}
						}
						$query2 = "INSERT INTO questions_tags (tag_id, users_questions_id) VALUES ('$id', '$page')";

						if (!mysqli_query($mysqli, $query2)) {
								print mysqli_error($mysqli);
								return;
						}
				}

						if (count($tags) == 1){
								echo $tags[0] . " has been entered";
						} else {
								echo implode(", ", $tags) . " have been entered";

						}
		}

		if (!$dbc) {
				print mysqli_error($mysqli);
		}
	}
	mysqli_close($mysqli);
}
?>

1 Cevap

Sürece sayfa PHP gibi açılış ve kapanış etiketleri herhangi bir sayıda olabilir:

<?php
$count = count($tags);
if ($count == 0) {
   $str = 'No tags have been entered.';
else if ($count == 1) {
    $str = htmlentities($tags[0]) . " has been entered";
} else {
    $str = htmlentities(implode(", ", $tags)) . " have been entered";                       
}
?>

<p>HTML code here</p>
<?php echo $str; ?>
<p>More HTML</p>

Eğer kullanıcı tarafından oluşturulan herhangi bir sayfa filtre çıkış önlemler almalıdır (cross-site scripting) engellemek için güvenlik amaçlı olduğunu unutmayınız. htmlentities at üzerinde hızlı bir bakış atın.