0
누군가가 태그를 입력 할 때 거의 모든 것을 모두 내 mysql 테이블에서 업데이트 할 수 있습니다. 사용자가 태그를 입력 할 때 q_tags 테이블의 tag_id 값에 태그 테이블 id 값을 추가하는 방법을 모릅니다.PHP/MySQL 테이블 문제가 있습니까?
나는이 부분을 설명했으면 좋겠다.
누군가 나를 도와 줄 수 있습니까?
다음은 MySQL 테이블입니다.
CREATE TABLE q_tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag_id INT UNSIGNED NOT NULL, //This value should be same as the tags table id
users_q_id INT UNSIGNED NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE tags (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
tag VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
다음은 아래 스크립트입니다.
<?php
require_once ('./mysqli_connect.php');
if (isset($_POST['submitted'])) {
$mysqli = new mysqli("localhost", "root", "", "sitename");
$dbc = mysqli_query($mysqli,"SELECT q_tags.*, tags.* FROM q_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 q_tags.*, tags.* FROM q_tags INNER JOIN tags ON tags.id = q_tags.tag_id WHERE q_tags.users_q_id=3");
if(!mysqli_num_rows($dbc)){
$mysqli = new mysqli("localhost", "root", "", "sitename");
$clean_url = mysqli_real_escape_string($mysqli, $page);
$query1 = "INSERT INTO q_tags (tag_id, users_q_id) VALUES ('', '$page')";
$query2 = "INSERT INTO tags (tag) VALUES ('$tag')";
if (!mysqli_query($mysqli, $query1)) {
print mysqli_error($mysqli);
return;
}
if (!mysqli_query($mysqli, $query2)) {
print mysqli_error($mysqli);
return;
}
echo "$tag has been entered";
if (!$dbc) {
print mysqli_error($mysqli);
}
}
mysqli_close($mysqli);
}
?>
을 지금 경고 경고를 무엇 :( – tor
를 얻을 * 말 * – Piskvor
경고 :에 mysql_insert_id() [function.mysql-삽입-ID] 다음에 대한 링크 서버를 설정할 수 없습니다 – tor