PHP Form不像上周那样工作

时间:2014-05-13 01:25:56

标签: php wordpress forms 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>

这是我的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();
?>

当我提交表单时,它在我的sql数据库中显示为空。

1 个答案:

答案 0 :(得分:6)

您的POST变量的字母大小写与您的值不符。

$Artist=$_POST['artist'];
$Song=$_POST['song'];
$Label=$_POST['label'];
$Genre=$_POST['genre'];
$Country=$_POST['country'];
$SongLink=$_POST['songlink'];
$PhotoLink=$_POST['photolink'];
$Email=$_POST['email'];

和你的价值观

('$artist','$song','$label','$genre','$country','$songlink','$photolink','$email')

不匹配。他们是区分大小写的。

将其更改为:

('$Artist','$Song','$Label','$Genre','$Country','$SongLink','$PhotoLink','$Email')

<强>脚注:

将错误报告添加到文件顶部

error_reporting(E_ALL);
ini_set('display_errors', 1);
正在开发中。

mysql_*函数弃用通知:

http://www.php.net/manual/en/intro.mysql.php

从PHP 5.5.0开始,不推荐使用此扩展,不建议用于编写新代码,因为将来会删除它。相反,应使用mysqliPDO_MySQL扩展名。在选择MySQL API时,另请参阅MySQL API Overview以获得进一步的帮助。

这些功能允许您访问MySQL数据库服务器。有关MySQL的更多信息,请访问»http://www.mysql.com/

可以在»http://dev.mysql.com/doc/找到MySQL的文档。