Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编辑php文件仅显示错误_Php_Mysql - Fatal编程技术网

编辑php文件仅显示错误

编辑php文件仅显示错误,php,mysql,Php,Mysql,我已经制作了一个edit.php文件,它似乎可以工作,但它只显示回显行(行的末尾)的错误。我似乎找不到我在哪里输入了错误或没有输入编码 我该怎么做才能解决这个问题 <?php /* EDIT.PHP Allows user to edit specific entry in database */ // creates the edit record form // since this form is used multiple times in this file, I have m

我已经制作了一个edit.php文件,它似乎可以工作,但它只显示回显行(行的末尾)的错误。我似乎找不到我在哪里输入了错误或没有输入编码

我该怎么做才能解决这个问题

<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable

 function renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error)

{

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>

  <head>

    <title>Edit Record</title>

  </head>

  <body>

  <?php

    // if there are any errors, display them

    if ($error != '')

    {

      echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';

    }

   ?>

    <form action="" method="post">

     <input type="hidden" name="songid" value="<?php echo $songid; ?>"/>

      <table style="margin-left:auto; margin-right:auto; width:400px;">
       <tbody>
         <tr style="text-align:center">
         <td colspan="2"><h2 style="color:#00008b;">Edit song into Music Database</h2><label style="color:#FF0000;"></label></td>
         </tr>

    <tr>
    <td>Title<label style="color:#FF0000;"></label></td>
    <td><input type="text" name="title"></td>
    </tr>
    <tr>
    <td>Artist<label style="color:#FF0000;"></label></td>
    <td><input type="text" name="artist"></td>
    </tr>
    <tr>
    <td>Genre<label style="color:#FF0000;"></label></td>
    <td><input type="text" name="genre"></td>
    </tr>
    <tr>
    <td>Language<label style="#FF0000;"></label></td>
    <td><input type="text" name="language"></td>
    </tr>
    <tr>
    <td>Lyrics: <label style="#FF0000;"></label></td>
    <td><textarea name="lyrics" rows="5" cols="50"></textarea></td>
    </tr>

    <tr style="text-align:center">
    <td colspan="2"><input type="submit" name="submit" value="Submit"></td>
    </tr>

    <input type="submit" name="submit" value="Submit">



 </form>

 </body>

 </html>

 <?php

  } // continue end of function of renderform 


 // connect to the database

  include('connect-db.php');


  // check if the form has been submitted. If it has, process the form and save it to the database

  if (isset($_POST['submit']))

  {

// confirm that the 'id' value is a valid integer before getting the form data

 if (is_numeric($_POST['songid']))

 {

 // get form data, making sure it is valid

        $songid = (isset($_POST['songid']) ? $_POST['songid'] : null);

        $title = (isset($_POST['title']) ? $_POST['title'] : null);
        $artist = (isset($_POST['artist']) ? $_POST['artist'] : null);
        $genre = (isset($_POST['genre']) ? $_POST['genre'] : null);
        $lyrics = (isset($_POST['lyrics']) ? $_POST['lyrics'] : null);
        $language = (isset($_POST['language']) ? $_POST['language'] : null);



   // check that firstname/lastname fields are both filled in

   if ($title == '' || $artist == '' || $genre == '' || $lyrics == '' || $language == '')

   {

   // generate error message

    $error = 'ERROR: Please fill in all required fields!';

   //error, display form

    renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error);

    }

   else

   {

    // save the data to the database

    mysql_query("UPDATE players SET title='$title', artist='$artist', genre='$genre', lyrics='$lyrics', language='$language' WHERE songid='$songid'")

    or die(mysql_error());

   // once saved, redirect back to the view page

    header("Location: view.php");

    }

}

else

{

// if the 'id' isn't valid, display an error

 echo 'Error!';

}

 }

  else

 // if the form hasn't been submitted, get the data from the db and display the form
  {

  // get the 'songid' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)

if (isset($_GET['songid']) && is_numeric($_GET['songid']) && $_GET['songid'] > 0)

{

 // query db

 $songid = $_GET['songid'];

$result = mysql_query("SELECT * FROM songs WHERE songid=$songid")
 or die(mysql_error());

$row = mysql_fetch_array($result);

 // check that the 'id' matches up with a row in the databse

     if($row)

    {



        // get data from db

        $title = $row['title'];

        $artist = $row['artist'];

        $genre = $row['genre'];

        $lyrics = $row['lyrics'];

        $language= $row['language'];


        // show form

        renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error);

    }

else

    // if no match, display result

{

    echo "No results!";

}

}

else

// if the 'songid' in the URL isn't valid, or if there is no 'songid' value, display an error

{

echo 'Error!';

}

}

?>

编辑记录

很可能您定义了函数,但没有执行。请核对:

<?php
/*
EDIT.PHP
Allows user to edit specific entry in database
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable

renderForm();

 function renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error)

{...}

根据您的第一个屏幕截图,您在URL中使用
id
,而不是
songid


尝试将
id
更改为
songid
,就像

你的代码有一些语法错误,但我也修复了它。需要注意的是,我整理了你的代码并移动了一些东西。我还注意到,当MySQL被弃用时,你正在使用MySQL,所以我将其改为MySQLI,并为你提供了连接到数据库的方法。当更改头位置时,建议你放exit();然后停止其余PHP代码的运行



编辑记录

您是否在URL中添加了
songid
参数?它是一个有效的数字(
是数字)并且高于0吗?浏览器控制台中是否有任何错误?@Frank M是的,我添加了它,是的,它高于00@SinghPiyush没有。显示的错误来自此代码的回音“error”。伤害。我的。眼球@Zirah请尝试对代码进行更多的结构和组织,这样会更清楚地知道您的问题所在。首先,正确地缩进它。然后,也许可以尝试摆脱嵌套的if-else-if-blurb,例如,可以将其中的代码转换为函数,这样我们就可以通过一次查看实际看到您在那里得到了什么样的条件树。这种(非)结构是调试的噩梦。。。重构快乐!
 <?php
include('connect-db.php');
function renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error){

}
if (isset($_POST['submit'])){
    if (is_numeric($_POST['songid'])){
        $songid = (isset($_POST['songid']) ? $_POST['songid'] : null);
        $title = (isset($_POST['title']) ? $_POST['title'] : null);
        $artist = (isset($_POST['artist']) ? $_POST['artist'] : null);
        $genre = (isset($_POST['genre']) ? $_POST['genre'] : null);
        $lyrics = (isset($_POST['lyrics']) ? $_POST['lyrics'] : null);
        $language = (isset($_POST['language']) ? $_POST['language'] : null);
        if ($title == null || $artist == null || $genre == null || $lyrics == null || $language == null){
            $error = 'ERROR: Please fill in all required fields!';
        } else {
            $conn = new mysqli('host', 'username', 'password', 'DB');// This will be located in your connect.php but the refrence variable("$conn") is important if you are going to use this php
            $conn->query("UPDATE players SET '$title', artist='$artist', genre='$genre', lyrics='$lyrics', language='$language' WHERE songid='$songid''");
            header("Location: view.php");
            exit();

        }
    } else {
        $error = "Song Id is not valid";
    }
}
if (isset($_GET['songid']) && is_numeric($_GET['songid']) && $_GET['songid'] > 0){
    $songid = $_GET['songid'];
    "SELECT * FROM songs WHERE songid=$songid"
    $result = $conn->query("UPDATE players SET '$title', artist='$artist', genre='$genre', lyrics='$lyrics', language='$language' WHERE songid='$songid''");
    $row = $result->fetch_assoc();
    if(mysqli_num_rows($result) > 0){
        $title = $row['title'];
        $artist = $row['artist'];
        $genre = $row['genre'];
        $lyrics = $row['lyrics'];
        $language= $row['language'];
        renderForm($songid, $title, $artist, $genre, $lyrics, $language, $error); // Still not quite sure what you are doing with this function because there is no function made on this current php script

    } else {
        $error = "No results!";
    }
} else {
    $error = "Song id in URL is not valid";
}
?>
<html>
  <head>
    <title>Edit Record</title>
  </head>
  <body>
  <?php
    if ($error){
      echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
    }
   ?>
    <form action="" method="post">
     <input type="hidden" name="songid" value="<?php echo $songid; ?>"/>
      <table style="margin-left:auto; margin-right:auto; width:400px;">
       <tbody>
         <tr style="text-align:center">
         <td colspan="2"><h2 style="color:#00008b;">Edit song into Music Database</h2><label style="color:#FF0000;"></label></td>
         </tr>
    <tr>
    <td>Title<label style="color:#FF0000;"></label></td>
    <td><input type="text" name="title"></td>
    </tr>
    <tr>
    <td>Artist<label style="color:#FF0000;"></label></td>
    <td><input type="text" name="artist"></td>
    </tr>
    <tr>
    <td>Genre<label style="color:#FF0000;"></label></td>
    <td><input type="text" name="genre"></td>
    </tr>
    <tr>
    <td>Language<label style="#FF0000;"></label></td>
    <td><input type="text" name="language"></td>
    </tr>
    <tr>
    <td>Lyrics: <label style="#FF0000;"></label></td>
    <td><textarea name="lyrics" rows="5" cols="50"></textarea></td>
    </tr>

    <tr style="text-align:center">
    <td colspan="2"><input type="submit" name="submit" value="Submit"></td>
    </tr>

    <input type="submit" name="submit" value="Submit">
 </form>
 </body>
 </html>