dsieyx2015 2013-05-16 08:10
浏览 32

PHP FORM INSERT INTO不插入记录

I'm working on a Uni assignment and am having trouble inserting records to MySQL database using a form. My set up is below. I can view entries in the database with no problem. I'm new to this so sorry in advance :(

conninfo.php

<?php
$strServer="localhost";   
$strDatabase="djdatabase";   // CHANGE TO YOUR DATABASE NAME HERE
$strUser="root";    
$strPwd="";    // Leave blank for WAMPServer

$strDB=mysql_connect($strServer,$strUser,$strPwd)or die("Could not open database");
$database=mysql_select_db("$strDatabase",$strDB);

?>

addnewdata.php

<?php include "conninfo.php";
$newdj=$_POST["dj"];  //pick up from form
$newfn=$_POST["fn"];
$newem=$_POST["em"];
$newwe=$_POST["we"];
$newpi=$_POST["pi"];
$newev=$_POST["ev"];


$query = "INSERT INTO dj(DJName, FirstName, Email, Website, Picture,    EventNumber)VALUES('$newdj', '$newfn', '$newem', '$newwe', '$newpi', '$newev)";

mysql_query($query);


header("location:showall.php");
?>

enternewdata.php

<?php include "conninfo.php";?>
<html>
<head>


</head>
<body>

<form action="addnewdata.php" method="post">

DJ Name:<input type="text" name="dj"><br>
FirstName: <input type="text" name="fn" /><br>
Email: <input type="text" name="em" /><br>
Website: <input type="text" name="we" /><br>
Picture: <input type="text" name="pi" /><br>
EventID: <input type="text" name="ev" /><br>
<br><br>

<button type="submit">Submit</button>
</form>

</body>
</html>

Many Thanks for your help :)

  • 写回答

3条回答 默认 最新

  • douhuang2282 2013-05-16 08:16
    关注

    had better use SET command to insert data

    $query = "INSERT INTO dj SET
                DJName=".$newdj.",
                FirstName=".$newfn.",
                Email=".$newem.",
                Website=".$newwe.",
                Picture=".$newpi.",
                EventNumber=".$newev."";
    $save = mysql_query($query);
    if($save){
        header("location:showall.php");
    }else{
        die(mysql_error());
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程