Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
insert php无法链接到phpmyadmin,当我插入数据时,它将不会显示在phpmyadmin中_Php_Mysql - Fatal编程技术网

insert php无法链接到phpmyadmin,当我插入数据时,它将不会显示在phpmyadmin中

insert php无法链接到phpmyadmin,当我插入数据时,它将不会显示在phpmyadmin中,php,mysql,Php,Mysql,我的问题:我的insert php在输入详细信息时无法将数据保存到phpmyadmin。 localhost:locahost,用户名:root密码:databasename:b_数据库tablename:my_库 tablecolumn:2包含:isbn主键和标题 index.php <html> <head> <meta name="description" content="Php Code for View, Search, Edit and Delete

我的问题:我的insert php在输入详细信息时无法将数据保存到phpmyadmin。 localhost:locahost,用户名:root密码:databasename:b_数据库tablename:my_库 tablecolumn:2包含:isbn主键和标题

index.php

<html>
<head>
<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Search Library Record</title>
</head>
<body>
<center><h1><u>Library Database</u></h1></center>
<form name="search" method="post" action="search.php">
<table style=" border:1px solid silver" cellpadding="10px" cellspacing="0px"
align="center">
<tr>
<td colspan="3" style="background:#0066FF; color:#FFFFFF; fontsize:
20px">Search</td></tr>
<tr>
<td>Enter Search Keyword</td>
<td><input type="text" name="search" size="40" /></td>
<td><input type="submit" value="Search" /></td>
</tr>
<tr>
<td colspan="3">&nbsp;</td></tr>
<tr bgcolor="#CCCCCC">
<th><a href="add.php">Add Record</a></th>
<th><a href="del.php">Delete Record</a></th>
<th><a href="del.php">Update Record</a></th>
</tr>
</table>
</form>
</body>
</html>
add.php

<?php
$conn_error = 'Could not connect.';
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = '';
$mysql_db='b_database';

if(!@mysql_connect($mysql_host, $mysql_user,$mysql_pass)|| !@mysql_select_db($mysql_db)){
  die($conn_error);

}
?>

<html>
<head>
<meta name="description" content="Php Code for View, Search, Edit and Delete Record" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Add Student Record</title>
</head>
<body>
<center>
<h1><u>Library Database</u></h1>
</center>
<?
if($_POST["do"]=="store")
{
$isbn=$_POST["isbn"];
$title=$_POST["title"];
if($query_run = mysql_query($query)){
  $query="insert into mylibrary value('$isbn','$title')";
  mysql_query($query);
  echo "Successfully store in DATABASE";
  }
  ?>
  <form name="add" method="post" action="add.php">
  <table style=" border:1px solid silver" cellpadding="5px" cellspacing="0px"
  align="center" border="0">
  <tr>
  <td colspan="4" style="background:#0066FF; color:#FFFFFF; fontsize:
  20px">ADD RECORD</td>
  </tr>
  <tr>
  <tr>
  <td>Enter ISBN</td>
  <td><input type="text" name="isbn" size="20"></td>
  </tr>
  <tr>
  <td>Enter TITLE</td>
  <td><input type="text" name="title" size="20"></td>
  </tr>
  <tr>
  <td colspan="4" align="center"><input type="hidden" name="do" value="store">
  <input type="submit" value="ADD RECORD"></td>
  </tr>
  </table>
  </form>
  <p align="center"><a href="index.php">Go Back to Home</a></p>
  <?
  include("search.php");?>
  </body>
  </html>

有很多问题。其中一些:

您的查询字符串错误。你有价值而不是价值 执行$query后,可以将查询字符串分配给它 停止使用不推荐的mysql_*扩展,并切换到或 验证和清理用户输入 学习并使用而不是插入查询字符串。后者为sql注入敞开了大门。 现在回到你眼前的问题。试着改变这部分

if($query_run = mysql_query($query)){
  $query="insert into mylibrary value('$isbn','$title')";
  mysql_query($query);
  echo "Successfully store in DATABASE";
}
像这样的事情

$query = "INSERT INTO mylibrary (isbn, title) VALUES('$isbn', '$title')";
$result = mysql_query($query);
if($result) {
  echo "Successfully stored in DATABASE";
} else {
  echo "Something went wrong: " . mysql_error();
}

你能解释一下为什么用这行吗:if$query\u run=mysql\u query$query{嘿,我们有相同的名字!但是,是的,伙计,一次就够了。如果你没有得到你需要的回复,重写或提供更好的信息。这根本不起作用,没有任何改变。你收集isbn和标题并提交到add.php的代码在哪里???你的index.php没有这个部分。