gpt4 book ai didi

php - 编辑php文件仅显示错误

转载 作者:行者123 更新时间:2023-11-29 19:36:24 24 4
gpt4 key购买 nike

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

This is what it shows.

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

<?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!';

}

}

?>

最佳答案

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

尝试将id更改为songid,例如localhost/songdb/edit.php?songid=14

关于php - 编辑php文件仅显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41543472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com