Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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
Php 将声明后页插入到问题本身_Php_Mysql - Fatal编程技术网

Php 将声明后页插入到问题本身

Php 将声明后页插入到问题本身,php,mysql,Php,Mysql,我试图提交网页本身,但由于某些原因,下面的代码无法工作。另外,在成功插入数据后,我如何获取table1主键ID?我有一张需要此ID的儿童表。谢谢您的建议 <?php include('db_login.php'); $connection = mysql_connect( $db_host, $db_username, $db_password ); if (!$connection){ die ("Could not connect to the database: <br

我试图提交网页本身,但由于某些原因,下面的代码无法工作。另外,在成功插入数据后,我如何获取table1主键ID?我有一张需要此ID的儿童表。谢谢您的建议

<?php
include('db_login.php');
$connection = mysql_connect( $db_host, $db_username, $db_password );

if (!$connection){
  die ("Could not connect to the database: <br />". mysql_error());
}
// Select the database
$db_select=mysql_select_db($db_database);
if (!$db_select){
  die ("Could not select the database: <br />". mysql_error());

  if ($_POST['Submit']) 
  { 
    $first = $_POST["first"];
    $first = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($first): $first);
    $last = $_POST["last"];
    $last = mysql_real_escape_string(get_magic_quotes_gpc() ? stripslashes($last): $last);


    $insertsql = "INSERT INTO table1(FirstName,LastName) VALUES ('".$first."', '" .$last. "')";

    $result1 = mysql_query($insertsql) or die(mysql_error());
 }
 ?>
 <form name="hotlineForm" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"
  method="post">
 <input id="first" type="text">
 <input id="last" type="text">
 <input type="submit" value="Submit"></form></body>

哪一部分在邮件背面不起作用?您是否没有输入if语句

要获取上次插入的ID,请在$result1=mysql\u查询(…)之后使用以下命令:


哪一部分在邮件背面不起作用?您是否没有输入if语句

要获取上次插入的ID,请在$result1=mysql\u查询(…)之后使用以下命令:


更改表单输入以包含名称属性。如果没有它们,您的
$\u帖子将是空的

<input name='first' id="first" type="text">
<input name='last' id="last" type="text">
<input name='Submit' type="submit" value="Submit">

更改表单输入以包括名称属性。如果没有它们,您的
$\u帖子将是空的

<input name='first' id="first" type="text">
<input name='last' id="last" type="text">
<input name='Submit' type="submit" value="Submit">
我没有看到具有此名称的表单元素

尝试:

要获取插入的ID,您可以使用:

mysql_insert_id();
我没有看到具有此名称的表单元素

尝试:

要获取插入的ID,您可以使用:

mysql_insert_id();

您在此处缺少一个结束语
}

if (!$db_select){
  die ("Could not select the database: <br />". mysql_error());
}  <<----  Close your if statement here.
if ($_POST['Submit']) 
if(!$db\u选择){
die(“无法选择数据库:
”.mysql_error());
}此处缺少一个结束语
}

if (!$db_select){
  die ("Could not select the database: <br />". mysql_error());
}  <<----  Close your if statement here.
if ($_POST['Submit']) 
if(!$db\u选择){
die(“无法选择数据库:
”.mysql_error());
}为输入字段使用一个名称,并检查它是否发送给
提交

为输入字段使用一个名称,并检查它是否发送给
提交

描述“不工作”。你收到错误信息了吗?另外,
mysql\u insert\u id()
将从您以前的查询中获取新插入的id。
get\u magic\u quotes
已被破坏(并且已经存在多年)。不要使用它,也不要依赖它。您的表单输入没有
name
属性。我没有收到任何错误消息。我不知道如何调试代码。我正在使用远程服务器进行开发。请描述“不工作”。你收到错误信息了吗?另外,
mysql\u insert\u id()
将从您以前的查询中获取新插入的id。
get\u magic\u quotes
已被破坏(并且已经存在多年)。不要使用它,也不要依赖它。您的表单输入没有
name
属性。我没有收到任何错误消息。我不知道如何调试代码。我正在使用远程服务器进行开发。更好的方法是使用
if($\u server['REQUEST\u METHOD']='POST')
,它完全不需要现场检测,并且是100%可靠的。更好的方法是使用
if($\u server['REQUEST\u METHOD']='POST')
,它完全不需要现场检测,并且是100%可靠的。
if (!$db_select){
  die ("Could not select the database: <br />". mysql_error());
}  <<----  Close your if statement here.
if ($_POST['Submit'])