【问题标题】:how to post textarea value into database如何将 textarea 值发布到数据库中
【发布时间】:2018-01-01 09:30:37
【问题描述】:

我在发布输入到 textarea 的值时遇到问题。其他一切都很好,知道如何让它工作吗?

HTML

<form id="formData2" action="artistuploader.php" method="post" 
enctype="multipart/form-data">

        <input type="hidden" name="size" value="1000000"></input>
        <br/>
        <input id="inputField" type="text" name="actname" placeholder="Act Name" >
        <br>
        <input id="inputField" type="text" name="fullname" placeholder="Full Name" >
        <br>
        <input id="inputField" type="text" name="genre" placeholder="Genre" >
        <br>
        <textarea id="inputField" name="biography" form="formData2" placeholder="Biography"<?php echo $biography; ?>></textarea>
        <br>
        <input id="inputField" type="file" name="artistImage" placeholder="Artwork" >
        <br>
        <input id="inputField" type="text" name="imagepath" placeholder="Image path URL" >
        <br>
        <input id="submitButton" type="submit" name="uploadArtist" value="Register Artist">

    </form>

PHP

<?php

$msg = "";

//if Upload button is pressed
if (isset($_POST['uploadArtist'])){
    $target = "uploads/artistPics".basename($_FILES['artistImage']['name']);


    //connecting to our database
    $db = mysqli_connect("127.0.0.1", "user", "pass", "tablename");
    $tmp_name = $_FILES['artistImage']['tmp_name'];
    $name = $_FILES['artistImage']['name'];
    //getting the submitted form data
    $ActName = $_POST['actname'];
    $FullName = $_POST['fullname'];
    $Genre = $_POST['genre'];
    $ArtistPhoto = $_FILES['artistImage']['name'];
    $imageURLpath = $_POST['imagepath'];
    $Biography = $_POST['biography'];//having problem with this line here

    //saving submitted data into database table songsDB
    $sql = "INSERT INTO  artistsdb (ActName,FullName,Genre,ArtistPhoto,Biography,imageURLpath) VALUES ('$ActName','$FullName','$Genre','$ArtistPhoto','$Biography','$imageURLpath')";
    mysqli_query($db, $sql); //stores the submitted data into table

    //now moving the uploaded image to uploads folder
    if(move_uploaded_file($_FILES['artistImage']['tmp_name'], $target)){
        $msg = "Uploaded Successful";
    }else{
        $msg = "There was a problem uploading Data";
    }
}

//header("refresh:1; url=index.php"); ?>

【问题讨论】:

  • 显示artistuploader.php。因为它发生在哪里。
  • 嗨,我的错,我粘贴了代码,请再次检查。谢谢
  • 你在哪里设置了你在 textarea 中输出的变量 $biography?
  • 我是 php 新手,这是我拼凑起来的尝试。那么我是否必须设置一个变量“传记”才能使其工作?我不知道从这里去哪里。
  • 那么请继续阅读一些关于它的教程。您的代码对SQL vulnerabilities 开放

标签: php mysql textarea


【解决方案1】:

将您的textarea 替换为

 <textarea id="inputField" name="biography" form="formData2" placeholder="Biography"><?php echo $biography; ?></textarea>

【讨论】:

  • 嗨,我更换了文本区域,问题仍然存在,
  • 浏览器说我的 PHP 中的这一行存在问题,$Biography = $_POST['biography'];
  • 我认为问题在于您在textarea 中输出的$biography 变量。将其替换为&lt;?php echo isset($biography) ? $biography : ''; ?&gt;
猜你喜欢
  • 2017-11-29
  • 1970-01-01
  • 1970-01-01
  • 2019-01-18
  • 2021-11-13
  • 2019-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多