帖子功能在php

时间:2016-06-14 14:28:30

标签: php mysql post

我只是一个关于php的初学者并且学习如何编码。我正在关注一个cbt块,我已经在一个动作上将插入的值发布到表单上并将其传递给操作页面并插入到数据库中。我在尝试提交按钮时收到此消息

0查询问题:

我的数据库连接器

<?php

 $host = "localhost";
 $user = "root";
 $password = "";
 $db = "linuxcbtcontacts";

 # Step 1 instantiate DB object
 $conn = mysqli_connect($host,$user,"",$db) or die("Problems connecting:" .      mysql_error());
 #if ($conn) { echo "True"; }

 #$dbselect = mysqli_select_db("linuxcbtcontacts", $conn) or die("Error selecting DB:" . mysql_error());

 # Step 2 - select DB
 #$dbselect = mysqli_select_db($conn, "linuxcbtcontacts") or die("Error selecting DB:" . mysql_error());
 $dbselect = mysqli_select_db($conn,$db) or die("Error selecting DB:" .   mysql_error());

 ?>

我的表单操作页面(在从表单中提交提交后)

<?php
require 'dbconnect.php';


$unique_check = "select name from contacts where name = 'name'";
$results_unique_check = mysqli_query($conn,$unique_check);
$rowcount = mysqli_num_rows($results_unique_check);
echo $rowcount;

if ($rowcount > 0) {
echo "Please use in different name", "<br>";
echo "<a href=query2.php>go back</a>";
exit(); }
else {
$query1 = "INSERT INTO   contacts(name,email,age,yearborn,ratesite,industry,buyourproducts,software,hardware)    VALUES('$_POST[name]','$_POST[email]','$_POST[age]','$_POST[yearborn]','$_POST[ratesite]','$_POST[industry]','$_POST[buyourproducts],'$_POST[software]','$_POST[hardware]')";

# Step 3 - invoke query
$results = mysqli_query($conn,$query1) or die("Problems with query:" . mysql_error());

 $rowcount = mysqli_affected_rows($conn);
 echo "Total Inserted Records:\t", $rowcount, "<br>";

 }


 ?>

从cbt开始,我会在点击提交按钮后收到此消息

0Total Inserted Records:1

已经调整了我在互联网上看到的所有可能性,但我仍然以“0问题查询:”消息结束

1 个答案:

答案 0 :(得分:-2)

  $query1 = "INSERT INTO   contacts(name,email,age,yearborn,ratesite,industry,buyourproducts,software,hardware)    VALUES('".$_POST['name']."','".$_POST['email']."','".$_POST['age']."','".$_POST['yearborn']."','".$_POST['ratesite']."','".$_POST['industry']."','".$_POST['buyourproducts']."','".$_POST['software']."','".$_POST['hardware']."')";