使用php / html格式插入到mysql中 - 不起作用 [英] Insert into mysql using php / html form - not working

查看:130
本文介绍了使用php / html格式插入到mysql中 - 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用php / html格式将数据输入到mysql数据库中,但它不起作用,我不知道为什么。该记录未插入,我在提交表单后只收到空白页。



谢谢,
eugenie



这是我的数据库此处输入图片说明



这是html表单:

 < form method =postaction = http://thesoundclinic.co.uk/site/modules/cjaycontent/index.php?id=28\"> 
< table class =outerborder =0cellpadding =2cellspacing =1align =center>
< tbody>

< tr>
< td> Uid(请参阅主选单)< / td>
< td>< input name =uidid =uidsize =3maxlength =10type =text>< / td>
< / tr>

< tr>
< td width =300>全名< / td>
< td>< input name =nameid =namesize =30maxlength =30type =text>< / td>
< / tr>

< tr>
< td width =300>位置< / td>
< td>< input name =locationid =locationsize =20maxlength =30type =text>< / td>
< / tr>

< tr>

< td>个人资料< / td>

< td>< textarea name =profileid =profilecols =25rows =5>关于你自己...< / textarea>< ; / TD>

< / tr>

< tr>

< td>首选流派< / td>

< td>
< table border =0cellpadding =5>
< tr>
< td>< input type =checkboxname =genres []id =genresvalue =Action> Action< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Adventure> Adventrue< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Horror> Horror< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Romance> Romance< / td>
< / tr>
< tr>
< td>< input type =checkboxname =genres []id =genresvalue =Drama> Drama< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Comedy> Comedy< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Thriller> Thriller< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Sci-fi> Sci-fi< / td>
< / tr>
< tr>
< td>< input type =checkboxname =genres []id =genresvalue =Crime> Crime< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Epic> Epic< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Western> Western< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Fantasy> Fantasy< / td>
< / tr>
< tr>
< td>< input type =checkboxname =genres []id =genresvalue =Period> Period< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Experimental> Experimental< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Documentary>纪录片< / td>
< td>< input type =checkboxname =genres []id =genresvalue =Animation> Animation< / td>
< / tr>

< / table>< / td>

< / tr>

< td width =300>用一个词来描述你的音乐的主要感受(例如史诗,怪异,忧郁等)< / td>

< td>< input name =styleid =stylesize =20maxlength =30type =text>< / td>

< / tr>
< tr>

< td>兴趣领域< / td>

< td>< textarea name =interestid =interestscols =25rows =5>任何特别的兴趣(动画,时期等)。 < / textarea的>< / TD>

< / tr>


< td>您通常为您的工作收取多少英镑?< / td>

< td>< textarea name =ratesid =ratescols =25rows =5>请解释...< / textarea>< / td>

< / tr>
< tr>

< td>每年我们都会为参加48小时电影挑战赛的3部电影提供免费音效设计。你会考虑免费提供你的工作吗? (这是一项比赛要求)。 < / TD>

< td>< input type =radioname =48hfilmid =48hfilmvalue =Yes>是

<输入类型=radioname =48hfilmid =48hfilmvalue =No>否< / td>

< / tr>
< tr>

< td width =300colspan =2align =center>

< strong>< br>粘贴您的youTube(嵌入)/ SoundCloud(小工具)< i> iFrame< / i>代码在以下字段中。您最多可以插入8个代码。< / strong>< br>

< / td>


< tr>

< td>< h3>剪辑1< / h>< / td>

< td>< input name =clip1id =clip1size =80maxlength =200type =text>< / td>

< / tr>

< tr>

< td>< h3> Clip 2< / h>< / td>

< td>< input name =clip2id =clip2size =80maxlength =200type =text>< / td>

< / tr>

< tr>

< td>< h3>剪辑3< / h>< / td>

< td>< input name =clip3id =clip3size =80maxlength =200

type =text> < / TD>

< / tr>

< td>< h3>剪辑4< / h>< / td>

< td>< input name =clip4id =clip4size =80maxlength =200

type =text> < / TD>

< / tr>

< td>< h3>剪辑5< / h>< / td>

< td>< input name =clip5id =clip5size =80maxlength =200

type =text> < / TD>

< / tr>

< td>< h3>剪辑6< / h>< / td>

< td>< input name =clip6id =clip6size =80maxlength =200

type =text> < / TD>

< / tr>

< td>< h3>剪辑7< / h>< / td>

< td>< input name =clip7id =clip7size =80maxlength =200

type =text> < / TD>

< / tr>

< td>< h3>剪辑8< / h>< / td>

< td>< input name =clip8id =clip8size =80maxlength =200type =text>< / td>

< / tr>

< tr>

< td> <峰; br>

< / td>

< td> < input name =addid =addvalue =Submittype =submit>< / td>

< / tr>

< / tbody>

< / table>

< / form>

这是php代码:

 <?php 

include(mainfile.php);
include(XOOPS_ROOT_PATH。/ header.php);

$ DBhost =localhost;
$ DBuser =------;
$ DBpass =----;
$ DBName =---;
$ table =--l;
mysql_connect($ DBhost,$ DBuser,$ DBpass)或死(无法连接到数据库);

@mysql_select_db($ DBName)或死(无法选择数据库$ DBName);

$ sqlquery =INSERT INTO $ table
VALUES('$ _ POST [id]','$ _ POST [uid]','$ _ POST [name]','$ _ POST [位置]','$ _POST [profile]','$ _POST [流派]','$ _POST [48hfilm]','$ _POST [clip1]','$ _POST [clip2]','$ _POST [clip3] ','$ _POST [clip4]','$ _POST [clip5]','$ _POST [clip6]','$ _POST [clip7]','$ _POST [clip8]','$ _POST [rates]', '$ _POST [style]','$ _POST [interest]');



$ results = mysql_query($ sqlquery);

{
打印< table class ='editor'>;
打印< tr>;
Print< th>名称:< / th>< td> $ _ POST [name]< / td>;
打印< tr>;
列印< th>位置:< / th>< td> $ _ POST [位置]< / td>;
打印< tr>;
列印< th>个人资料:< / th>< td> $ _ POST [个人资料]< / td>;
打印< tr>;
打印< th>流派:< / th>< td> $ _ POST [流派]< / td>;
打印< tr>;
打印第48小时电影挑战赛< / th>< td> $ _ POST [48hfilm]< / td>;
打印< tr>;
Print< th> Style:< / th>< td> $ _ POST [style]< / td>;
打印< tr>;
列印< th>兴趣:< / th>< td> $ _ POST [兴趣]< / td>;

}
打印< / table>;



?>

<?php
$ host =localhost; //主机名
$ username =----; // Mysql username
$ password =----; // Mysql密码
$ db_name = - c; //数据库名称
$ tbl_name =--- l; //表名

//连接服务器并选择数据库。
mysql_connect($ host,$ username,$ password)或die(无法连接);
mysql_select_db($ db_name)或死(无法选择DB);

//获取地址栏发送的id的值
$ uid = $ _ POST ['uid'];

$ sql =Select * from $ tbl_name WHERE uid ='$ uid';
$ result = mysql_query($ sql)或die(mysql_error());

$ b while($ row = mysql_fetch_array($ result)){

echo< h2>< / h>< br>< p> ;;
echo< div align ='center'>< h1> GALLERY< / h>< p>< br>< / div>;
echo< h2> Clip 1< / h>< p>< p>;

if($ row ['clip1']!=''){
echo< h2> Clip 1< / h>< p>< p>
echo< div align ='center'> 。 $ row ['clip1']。 < / DIV>< p为H.;<峰; br> 中;
}
if($ row ['clip2']!=''){
echo< h2> Clip 2< / h>< p>< p> ;
echo< div align ='center'> 。 $ row ['clip2']。 < / DIV> 中;
}
if($ row ['clip3']!=''){
echo< h2> Clip 3< / h>< p>< p> ;
echo< div align ='center'> 。 $ row ['clip3']。 < / DIV> 中;
}
if($ row ['clip4']!=''){
echo< h2> Clip 4< / h>< p>< p> ;
echo< div align ='center'> 。 $ row ['clip4']。 < / DIV> 中;
}
if($ row ['clip5']!=''){
echo< h2> Clip 5< / h>< p>< p> ;
echo< div align ='center'> 。 $ row ['clip5']。 < / DIV> 中;
}
if($ row ['clip6']!=''){
echo< h2> Clip 6< / h>< p>< p> ;
echo< div align ='center'> 。 $ row ['clip6']。 < / DIV> 中;
}
if($ row ['clip7']!=''){
echo< h2> Clip 7< / h>< p> p< p> ;
echo< div align ='center'> 。 $ row ['clip7']。 < / DIV> 中;
}
if($ row ['clip8']!=''){
echo< h2> Clip 8< / h>< p>< p> ;
echo< div align ='center'> 。 $ row ['clip8']。 < / DIV> 中;
}
}



?>


解决方案

表单字段名称不应以例如 name =48hfilm



经过一定量的测试后,我得到了用打印第48小时电影挑战?< / th>< td> $ _ POST [48hfilm]< / td>;

更改:

 < td>< input type = radioname =48hfilmid =48hfilmvalue =Yes>是

< input type =radioname =48hfilmid =48hfilmvalue =No >否LT; / TD>

收件人:

 < code< td>< input type =radioname =hfilm48id =hfilm48value =Yes>是

< input type =radio name =hfilm48id =hfilm48value =No>否< / td>

或以字母开头,例如 name =a_48hfilm code>


I'm trying to enter data into a mysql database using php / html form but it isn't working and I don't know why. The record is not inserted and I only get a blank page after I submit the form.

Thanks, eugenie

This is my databaseenter image description here

This is the html form:

<form method="post" action="http://thesoundclinic.co.uk/site/modules/cjaycontent/index.php?id=28">
<table class="outer" border="0" cellpadding="2" cellspacing="1" align="center">
<tbody>

<tr>
<td>Uid (See Main Menu) </td>
<td><input name="uid" id="uid" size="3" maxlength="10" type="text"></td>
</tr>

<tr>
<td width="300">Full Name</td>
<td><input name="name" id="name" size="30" maxlength="30" type="text"></td>
</tr>

<tr>
<td width="300">Location</td>
<td><input name="location" id="location" size="20" maxlength="30" type="text"></td>
</tr>

<tr>

<td>Profile</td>

<td><textarea name="profile" id="profile" cols="25" rows="5">A bit about yourself... </textarea></td>

</tr>

<tr>

<td>Prefered Genres</td>

<td>
<table border="0" cellpadding="5">
  <tr>
    <td><input type="checkbox" name="genres[]" id="genres" value="Action">Action</td>
    <td><input type="checkbox" name="genres[]" id="genres" value="Adventure">Adventrue</td>
    <td><input type="checkbox" name="genres[]" id="genres" value="Horror">Horror</td>
    <td><input type="checkbox" name="genres[]" id="genres" value="Romance">Romance</td>
  </tr>
  <tr>
<td><input type="checkbox" name="genres[]" id="genres" value="Drama">Drama</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Comedy">Comedy</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Thriller">Thriller</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Sci-fi">Sci-fi</td>
</tr>
<tr>
<td><input type="checkbox" name="genres[]" id="genres" value="Crime">Crime</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Epic">Epic</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Western">Western</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Fantasy">Fantasy</td>
</tr>
<tr>
<td><input type="checkbox" name="genres[]" id="genres" value="Period">Period</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Experimental">Experimental</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Documentary">Documentary</td>
<td><input type="checkbox" name="genres[]" id="genres" value="Animation">Animation</td>
</tr>

</table></td>

</tr>

<td width="300">Describe in one word the predominant feeling of your music (e.g. epic, bizarre, melancholic, etc)</td>

<td><input name="style" id="style" size="20" maxlength="30" type="text"></td>

</tr>
<tr>

<td>Areas of Interest</td>

<td><textarea name="interests" id="interests" cols="25" rows="5"> Any particular interest (animation, period, etc.). </textarea></td>

</tr>


<td>How much in GBP do you normally charge for your work?</td>

<td><textarea name="rates" id="rates" cols="25" rows="5"> Please explain... </textarea></td>

</tr>
<tr>

<td>Every year we offer free sound design to up to 3 films taking part in the 48 Hour Film Challenge. Would you consider contributing your work for free? (This is a competition requirement). </td>

<td><input type="radio" name="48hfilm" id="48hfilm" value="Yes">Yes

<input type="radio" name="48hfilm" id="48hfilm" value="No">No</td>

</tr>
<tr>

<td width="300" colspan="2" align="center">

<strong><br>Paste your youTube (embed) / SoundCloud (Widget) <i>iFrame</i> code in the following Fields. You can insert up to 8 codes.</strong><br>

</td>


<tr>

<td ><h3>Clip 1</h></td>

<td><input name="clip1" id="clip1" size="80" maxlength="200" type="text"></td>

</tr>

<tr>

<td ><h3>Clip 2</h></td>

<td><input name="clip2" id="clip2" size="80" maxlength="200" type="text"></td>

</tr>

<tr>

<td ><h3>Clip 3</h></td>

<td><input name="clip3" id="clip3" size="80" maxlength="200"

type="text"></td>

</tr>

<td ><h3>Clip 4</h></td>

<td><input name="clip4" id="clip4" size="80" maxlength="200"

type="text"></td>

</tr>

<td><h3>Clip 5</h></td>

<td><input name="clip5" id="clip5" size="80" maxlength="200"

type="text"></td>

</tr>

<td ><h3>Clip 6</h></td>

<td><input name="clip6" id="clip6" size="80" maxlength="200"

type="text"></td>

</tr>

<td ><h3>Clip 7</h></td>

<td><input name="clip7" id="clip7" size="80" maxlength="200"

type="text"></td>

</tr>

<td ><h3>Clip 8</h></td>

<td><input name="clip8" id="clip8" size="80" maxlength="200" type="text"></td>

</tr>

<tr>

<td > <br>

</td>

<td> <input name="add" id="add" value="Submit" type="submit"></td>

</tr>

</tbody>

</table>

</form>

And this is the php code:

<?php

include("mainfile.php"); 
include(XOOPS_ROOT_PATH."/header.php");

$DBhost = "localhost";
$DBuser = "------";
$DBpass = "----";
$DBName = "---";
$table = "--l";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select database $DBName");

$sqlquery = "INSERT INTO $table
VALUES('$_POST[id]','$_POST[uid]','$_POST[name]','$_POST[location]', '$_POST[profile]',             '$_POST[genres]', '$_POST[48hfilm]', '$_POST[clip1]', '$_POST[clip2]', '$_POST[clip3]', '$_POST[clip4]',     '$_POST[clip5]', '$_POST[clip6]', '$_POST[clip7]', '$_POST[clip8]', '$_POST[rates]', '$_POST[style]', '$_POST[interests]')";



$results = mysql_query($sqlquery); 

 { 
 Print "<table class='editor'>"; 
 Print "<tr>"; 
 Print "<th>Name:</th> <td>$_POST[name]</td> ";
 Print "<tr>"; 
 Print "<th>Location:</th> <td>$_POST[location]</td> "; 
 Print "<tr>"; 
 Print "<th>Profile:</th> <td>$_POST[profile]</td> "; 
Print "<tr>"; 
 Print "<th>Genres:</th> <td>$_POST[genres]</td> "; 
Print "<tr>"; 
 Print "<th>48h Film Challenge?</th> <td>$_POST[48hfilm]</td> "; 
Print "<tr>"; 
 Print "<th>Style:</th> <td>$_POST[style]</td> "; 
Print "<tr>"; 
 Print "<th>Interests:</th> <td>$_POST[interests]</td> ";

 } 
 Print "</table>"; 



?>

<?php
$host="localhost"; // Host name 
$username="----"; // Mysql username 
$password="----"; // Mysql password 
$db_name="--c"; // Database name 
$tbl_name="---l"; // Table name

// 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 value of id that sent from address bar
$uid=$_POST['uid'];

$sql = "Select * from $tbl_name WHERE uid='$uid'";
$result = mysql_query($sql) or die(mysql_error());


while($row = mysql_fetch_array( $result )) {

echo "<h2></h><br><p>";
echo "<div align='center'><h1>GALLERY</h><p><br></div>";
echo "<h2>Clip 1 </h><p><p>";

if($row['clip1'] != ''){ 
echo "<h2>Clip 1 </h><p><p>"; 
echo "<div align='center'>" . $row['clip1'] . "</div><p><br>"; 
} 
if($row['clip2'] != ''){ 
echo "<h2>Clip 2 </h><p><p>"; 
echo "<div align='center'>" . $row['clip2'] . "</div>"; 
} 
if($row['clip3'] != ''){ 
echo "<h2>Clip 3 </h><p><p>"; 
echo "<div align='center'>" . $row['clip3'] . "</div>"; 
} 
if($row['clip4'] != ''){ 
echo "<h2>Clip 4 </h><p><p>"; 
echo "<div align='center'>" . $row['clip4'] . "</div>"; 
}
if($row['clip5'] != ''){ 
echo "<h2>Clip 5 </h><p><p>"; 
echo "<div align='center'>" . $row['clip5'] . "</div>"; 
}
if($row['clip6'] != ''){ 
echo "<h2>Clip 6 </h><p><p>"; 
echo "<div align='center'>" . $row['clip6'] . "</div>"; 
}
if($row['clip7'] != ''){ 
echo "<h2>Clip 7 </h><p><p>"; 
echo "<div align='center'>" . $row['clip7'] . "</div>"; 
}
if($row['clip8'] != ''){ 
echo "<h2>Clip 8 </h><p><p>"; 
echo "<div align='center'>" . $row['clip8'] . "</div>"; 
}
}



?>

解决方案

Form field names aren't supposed to start with a number, as in name="48hfilm" for example.

After doing a certain amount of testing, I got back a parse error with Print "<th>48h Film Challenge?</th> <td>$_POST[48hfilm]</td> ";

Change:

<td><input type="radio" name="48hfilm" id="48hfilm" value="Yes">Yes 

<input type="radio" name="48hfilm" id="48hfilm" value="No">No</td>

To:

<td><input type="radio" name="hfilm48" id="hfilm48" value="Yes">Yes 

<input type="radio" name="hfilm48" id="hfilm48" value="No">No</td>

or start it with a letter such as name="a_48hfilm"

这篇关于使用php / html格式插入到mysql中 - 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆