use*_*034 -1 php forms wordpress upgrade
我的主机供应商刚刚将PHP从5.3升级到5.4,所以我不确定这是否影响了我网站上的任何表格,因为它上周工作正常.
这是我的表格
<form action="insert.php" method="post">
<label for="artist">1. Artist Name: </label><input id="artist" name="artist" type="text" />
<label for="song">2. Song Name: </label><input id="song" name="song" type="text" />
<label for="label">3. Label: </label><input id="label" name="label" type="text" />
<label for="genre">4. Genre: </label>
<select name="genre"><option value="RnB">RnB</option></select>
<select name="genre"><option value="Hip Hop">Hip Hop</option></select>
<select name="genre"><option value="Reggae">Reggae</option></select>
<select name="genre"><option value="Gospel">Gospel</option></select>
<select name="genre"><option value="Dance">Dance</option></select>
<select name="genre"><option value="Jazz">Jazz</option></select>
<select name="genre"><option value="Afrobeats">Afrobeats</option></select>
<select name="genre"><option value="Soul">Soul</option></select>
<label for="genre">5. Country/Area: </label>
<select name="country"><optgroup label="Country"><option value="UK">UK</option> </optgroup></select>
<select name="country"><optgroup label="Country"><option value="US">US</option></optgroup></select>
<select name="country"><optgroup label="Country"><option value="CANADA">CANADA</option> </optgroup></select>
<select name="country"><optgroup label="Country"><option value="JAMAICA">JAMAICA</option></optgroup></select>
<select name="country"><optgroup label="Area"><option value="CARIBBEAN">CARIBBEAN</option></optgroup></select>
<select name="country"><optgroup label="Area"><option value="S.AMERICA">S.AMERICA</option></optgroup></select>
<select name="country"><optgroup label="Area"><option value="AFRICA">AFRICA</option></optgroup></select>
<select name="country"><optgroup label="Area"><option value="EUROPE">EUROPE</option></optgroup></select>
<select name="country"><optgroup label="Area"><option value="AUS">AUS</option></optgroup></select>
<select name="country"><optgroup label="Area"><option value="ASIA">ASIA</option></optgroup></select>
<label for="songlink">6. Song Link (Youtube Only): </label><input id="songlink" name="songlink" size="50" type="text" />
<label for="artistphoto">7. Artist Photo Link (Square): </label><input id="artistphoto" name="photolink" size="35" type="text" />
<label for="email">8. Email Address: </label><input id="email" name="email" type="text" />
<input type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的insert.php文件的大部分内容
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form
$Artist=$_POST['artist'];
$Song=$_POST['song'];
$Label=$_POST['label'];
$Genre=$_POST['genre'];
$Country=$_POST['country'];
$SongLink=$_POST['songlink'];
$PhotoLink=$_POST['photolink'];
$Email=$_POST['email'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(artistname, songname, label, genre, country, songlink, photolink, email)VALUES('$artist','$song','$label','$genre','$country','$songlink','$photolink','$email')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='index.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
<?php
// close connection
mysql_close();
?>
Run Code Online (Sandbox Code Playgroud)
当我提交表单时,它在我的sql数据库中显示为空.
您的POST变量的letter-cases与您的值不匹配.
$Artist=$_POST['artist'];
$Song=$_POST['song'];
$Label=$_POST['label'];
$Genre=$_POST['genre'];
$Country=$_POST['country'];
$SongLink=$_POST['songlink'];
$PhotoLink=$_POST['photolink'];
$Email=$_POST['email'];
Run Code Online (Sandbox Code Playgroud)
和你的价值观
('$artist','$song','$label','$genre','$country','$songlink','$photolink','$email')
Run Code Online (Sandbox Code Playgroud)
不匹配.他们区分大小写.
将其更改为:
('$Artist','$Song','$Label','$Genre','$Country','$SongLink','$PhotoLink','$Email')
Run Code Online (Sandbox Code Playgroud)
脚注:
将错误报告添加到文件的顶部
error_reporting(E_ALL); 在开发中.
ini_set('display_errors', 1);
mysql_* 功能弃用通知:
http://www.php.net/manual/en/intro.mysql.php
此扩展自PHP 5.5.0起不推荐使用,不建议用于编写新代码,因为将来会删除它.相反,应该使用mysqli或PDO_MySQL扩展.另请参阅MySQL API概述,以便在选择MySQL API时获得进一步的帮助.
这些函数允许您访问MySQL数据库服务器.有关MySQL的更多信息,请访问» http://www.mysql.com/.
有关MySQL的文档,请访问» http://dev.mysql.com/doc/.