不知怎的,我无法使用php将内容写入我的数据库。我使用代码编写前一个并且它工作但不知何故它不与表thread_db。我可以连接到表(我通过回显$ num_rows [计算表行 - >我没有任何东西]来测试它)。请帮我!这是代码:
<?php
include_once 'dbconnection.php';
include 'auth.php';
$id=($_SESSION['logedin']);
$abfrage = "SELECT * FROM login WHERE id = '$id'";
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))
{
$from = ($row->username);
$title = $_POST["thread_title"];
$content = $_POST["thread_content"];
$result12 = mysql_query("SELECT * FROM thread_db");
$num_rows = mysql_num_rows($result12); //counting all rows in table thread_db
$num_rows = (int)$num_rows; //converting result into int
$fileid = $num_rows + 1; // make the result +1
if($from == "" OR $title == "" OR $content == "")
{
echo "Input error. Please fill in all fields. <a href=\"create.php\">go back</a>";
exit;
}
else{
$insertvalues = "INSERT INTO thread_db (from, title, content) VALUES ('$from', '$title', '$content')"; //doesn't seem to work
$successfull = mysql_query($insertvalues);
if($successfull = true)
{
//set some basic html content
$ch1 = file_get_contents('./create/create_header1.txt');
$ch2 = file_get_contents('./create/create_header2.txt');
$c1 = file_get_contents('./create/create_content1.txt');
$c2 = file_get_contents('./create/create_content2.txt');
$c3 = file_get_contents('./create/create_content3.txt');
$c4 = file_get_contents('./create/create_content4.txt');
$sHTML_Header = ($ch1.$title.$ch2);
$sHTML_Content = ($c1.$title.$c2.$content.$c3.$row->username.$c4);
$sHTML_Footer = file_get_contents('./create/create_footer.txt');
$filename = $fileid.".php"; // name the file -> id + 1 + ending *.php
// creation of the file as writeable and readable file
IF (!$handle = FOPEN($filename, 'x+')) {
ECHO "Cannot open file (".$filename.")";
EXIT;
}
// Write $somecontent to created file.
IF (FWRITE($handle, $sHTML_Header) === FALSE) {
ECHO "Cannot write to file (".$filename.")";
EXIT;
}ELSE{
//file is ok so write the other elements to it
FWRITE($handle, $sHTML_Content);
FWRITE($handle, $sHTML_Footer);
}
FCLOSE($handle);
//if created you can edit it now // file will be renamed and will get its own dir
if (file_exists($filename)){
$old = $filename;
mkdir("./projects/".$fileid, 0700);
mkdir("./projects/".$fileid."/images", 0700);
$new = 'projects'. DIRECTORY_SEPARATOR . $fileid . DIRECTORY_SEPARATOR .'index.php';
rename($old , $new);
echo "Your page was successfully created, go and <a href='".$new."'>edit it now.</a>";
}
else{
echo "<br>There was an error creating the thread.";
}
}
else{
echo "<br>There was an error creating the thread.";
}
}
}
?>