尝试将文本链接到自动创建的.php页面

时间:2017-09-16 00:09:46

标签: php mysqli hyperlink reference

嘿所以我设置网站的方式是让用户可以提交表单。然后将此表单条目发送到mysql数据库,并在默认目录中自动创建新的.php。

每次用户提交表单时,都会创建一个新的.php文件。新文件是template.php文件的复制版本。它还预先在表格中输入所有信息。我也有搜索引擎。

我想要做的是当用户搜索并找到每个结果的结果以链接到相应的新创建的.php文件时,他们可以点击它并将它们带到新的.php页面。我该怎么做?

以下是与此问题相关的代码。所有3段代码都来自不同的.php文件。

表格代码:

            <input type="text" name="artistbox">
            <p>Featured Artists:</p>
            <input type="text" name="featuresbox">
            <p>Title:</p>
            <input type="text" name="songbox">
            <p>Album:</p>
            <input type="text" name="albumbox">
            <p>Choose a genre:</p>
            <select name="genre"> 
                <option value="Pop">Pop</option>
                <option value="Hip-hop">Hip-hop</option>
                <option value="RnB">RnB</option>
                <option value="EDM">Electronic Dance Music</option>
                <option value="Jazz">Jazz</option>
                <option value="Blues">Blues</option>
                <option value="Rock">Rock</option>
                <option value="Punk-rock">Punk-rock</option>
                <option value="Reggae">Reggae</option>
                <option value="Classic">Classic</option>
                <option value="Funk">Funk</option>
                <option value="Soul">Soul</option>
            </select>
            <p>Rating:</p>
            <select name="rating">
                <option value="0.5">0.5</option>
                <option value="1.0">1.0</option>
                <option value="1.5">1.5</option>
                <option value="2.0">2.0</option>
                <option value="2.5">2.5</option>
                <option value="3.0">3.0</option>
                <option value="3.5">3.5</option>
                <option value="4.0">4.0</option>
                <option value="4.5">4.5</option>
                <option value="5.0">5.0</option>
            </select>
            <p>Comments (1000 character limit):</p>
            <textarea name="commentsbox" cols="60" rows="7"></textarea>
            <br>
            <input class="submitbutton" type="submit" value="Submit">

发送数据和创建新文件代码:

$artistbox = $_POST['artistbox'];
$featuresbox = $_POST['featuresbox'];
$songbox = $_POST['songbox'];
$albumbox = $_POST['albumbox'];
$genre = $_POST['genre'];
$rating = $_POST['rating'];
$commentsbox = $_POST['commentsbox'];
date_default_timezone_set('NZ');
$time = date('Y/m/d H:i:s');

$queryartist = "INSERT INTO `artist` (`ArtistsName`)
          VALUES ('{$artistbox}')";
$queryfeatures = "INSERT INTO `features` (`Features`)
          VALUES ('{$featuresbox}')";
$querysong = "INSERT INTO `SongName` (`SongName`)
          VALUES ('{$songbox}')";
$queryalbum = "INSERT INTO `album` (`Album`)
          VALUES ('{$albumbox}')";
$querygenre = "INSERT INTO `genre` (`Genre`)
          VALUES ('{$genre}')";
$queryrating = "INSERT INTO `rating` (`Rating`)
          VALUES ('{$rating}')";
$querycomments = "INSERT INTO `comments` (`Comments`)
          VALUES ('{$commentsbox}')";
$querydate = "INSERT INTO `DateReviewed` (`DateReviewed`)
          VALUES ('{$time}')";

$conn->query($queryartist);
$conn->query($queryfeatures);
$conn->query($queryalbum);
$conn->query($querygenre);
$conn->query($queryrating);
$conn->query($querycomments);
$conn->query($querydate);

if ($conn->query($querysong) === TRUE) 
{
    $last_id = $conn->insert_id;
}   
else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$newpage = fopen("form_$last_id.php", "w+");
header("location: form_$last_id.php");
unset ($_POST);

copy ('template.php', "form_$last_id.php");
session_start();
$_SESSION['artistbox'] = $artistbox;
$_SESSION['featuresbox'] = $featuresbox;
$_SESSION['songbox'] = $songbox;
$_SESSION['albumbox'] = $albumbox;
$_SESSION['genre'] = $genre;
$_SESSION['rating'] = $rating;
$_SESSION['commentsbox'] = $commentsbox;
$_SESSION['date'] = $time;
exit ();

搜索结果代码:

  if(isset($_GET['q']) && $_GET['q'] !== ' ') {
            $searchq = $_GET['q'];

            $q = mysqli_query($conn, "
            SELECT album.Album, 
            artist.ArtistsName, 
            comments.Comments, 
            datereviewed.DateReviewed, 
            features.Features, 
            genre.Genre, 
            rating.Rating, 
            songname.SongName 
            FROM songname 
            INNER JOIN album ON album.ID = songname.ID 
            INNER JOIN artist ON artist.ID = songname.ID
            INNER JOIN comments ON comments.ID = songname.ID
            INNER JOIN datereviewed ON datereviewed.ID = songname.ID
            INNER JOIN features ON features.ID = songname.ID
            INNER JOIN genre ON genre.ID = songname.ID
            INNER JOIN rating ON rating.ID = songname.ID
            WHERE ArtistsName LIKE '%$searchq%' OR  
            SongName LIKE '%$searchq%' OR 
            Album LIKE '%$searchq%'") or die(mysqli_error());
            $c = mysqli_num_rows($q);
            if($c == 0){
                $output = 'No search results for <b>"' .$searchq. '"</b>';
            } 
         else {
                while($row = mysqli_fetch_array($q)) 
                {
                    $id = $row['ID'];
                    $album = $row['Album']; 
                    $artist = $row['ArtistsName']; 
                    $comments = $row['Comments']; 
                    $date = $row['DateReviewed']; 
                    $features = $row['Features'];
                    $genre = $row['Genre'];
                    $rating = $row['Rating'];
                    $title = $row['SongName'];

                    $output .= '<p> Title:  '.$title.' </p>
                                <p> Artist: '.$artist.' </p>
                                <p> Album: '.$album.' </p>';
                }
                } 
        } 
        else {
            header ("location: ./");

0 个答案:

没有答案