I'm trying to create my own query form, so that I can create a table in my DB, update data, select data, and so on. I have a file test.php with the form on which I will type my commands in a textarea. It will send my query to submitquery.php which contains the exact following:

我正在尝试创建自己的查询表单,以便我可以在数据库中创建表,更新数据,选择数据等。我有一个文件test.php,其中我将在textarea中键入我的命令。它会将我的查询发送到submitquery.php,其中包含以下内容:

<?php
$con=mysqli_connect("host","user","pass","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$result = mysqli_query($con,"$_POST['myquery']");


mysqli_close($con);
?> 

this is the code I have in test.php:

这是我在test.php中的代码:

<form action="submitquery.php" method="post">
<textarea name="myquery" id="myquery"></textarea>
<input type="submit" name="submit" value="Submit">
</form>

but when I submit, I get "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /public_html/admin/submitquery.php on line 9"

但是当我提交时,我得到“解析错误:语法错误,意外的T_ENCAPSED_AND_WHITESPACE,期望第9行的/public_html/admin/submitquery.php中的T_STRING或T_VARIABLE或T_NUM_STRING”

I'm not that great with PHP, I'm a very basic beginner. Could anyone please tell me what I'm doing wrong? Thanks!

我对PHP不太好,我是一个非常基础的初学者。谁能告诉我我做错了什么?谢谢!

2 个解决方案

#1


0

Do like this..

这样做..

<?php
$query=$_POST['myquery'];
$result = mysqli_query($con,$query);
mysqli_close($con);
?>

Well .. coming to your example.. What if i typed DROP TABLE yourtablename; ? You will lose all your table information.

嗯..来你的例子..如果我输入DROP TABLE yourtablename怎么办; ?您将丢失所有表格信息。

You need to check for SQL Injections... It's highly recommended to use Prepared Statements on PDO rather than doing like this.

您需要检查SQL注入...强烈建议在PDO上使用Prepared Statements而不是这样做。

更多相关文章

  1. mysqli类使用预处理语句不返回任何数据
  2. 使用/发送POST数据时的libcurl C问题(不是c++)
  3. laravel 框架自带表单验证
  4. PHP:在类中使用数据库
  5. 纯真ip数据库查询的php实现(补充分组查询)
  6. 添加到数据库后,保持在同一页面而不刷新它
  7. PHP 导出 万级别数据 时间测试
  8. AJAX学习之提交表单
  9. 数据库是存储我的Web应用程序数据的最佳选择吗?

随机推荐

  1. UNIX网络编程之源代码的编译和使用
  2. 在linux上获取已连接电视的电源状态
  3. mt7620的u-boot 代码
  4. linux audio(alsa) 驱动注册的简明流程.
  5. Linux常用命令(十) - nl
  6. linux抢占式调度
  7. Linux中有趣的几条命令
  8. Linux 基础总结(一)--Linux常用系统变量,a
  9. 英特尔 QSV 在 FFMPEG 中的使用(Linux)
  10. 在虚拟机中的Linux系统搭建ftp服务器,使用