无法找到我的网址或我的编程有问题

时间:2017-02-05 10:28:40

标签: php html

我已经创建了一个数据库(在phpmyadmin上)和一个使用php和html的表单,但我似乎无法找到我的数据库URL地址或者我的表单出现了一些问题...而且它说错误-1 - 桥响应错误,请检查API文档或此ajax响应。这是什么意思? 这是代码:

<html>

   <head>
      <title>Database</title>
   </head>

   <body>
      <?php
         if(isset($_POST['update'])) {
            $dbhost = localhost;'localhost:id674442_wommath';
            $dbuser = 'root';
            $dbpass = 'passroot';

            $conn = mysql_connect($dbhost, $dbuser, $dbpass);

            if(! $conn ) {
               die('Could not connect: ' . mysql_error());
            }

            $fir_name = $_POST['fir_name'];
            $sur_name = $_POST['sur_name'];
            $li_points = $_POST['li_points'];
            $xp_points = $_POST['xp_points'];

            $sql = "UPDATE First_name ". "SET Sur_name = $sur_name ". 
               "WHERE fir_name= $fur_name" ;
            mysql_select_db('test_db');
            $retval = mysql_query( $sql, $conn );

            if(! $retval ) {
               die('Could not update data: ' . mysql_error());
            }
            echo "Updated data successfully\n";

            mysql_close($conn);
         }else {
            ?>
               <form method = "post" action = "<?php $_PHP_SELF ?>">
                  <table width = "400" border =" 0" cellspacing = "1" 
                     cellpadding = "2">

                     <tr>
                        <td width = "100">First_Name</td>
                        <td><input name = "fir_name" type = "text" 
                           id = "emp_id"></td>
                     </tr>
                  <tr>
                     <td width = "100">Surname</td>
                     <td><input name = "sur_name" type = "text" 
                        id = "emp_id"></td>
                  </tr>
                  <tr>
                     <td width = "100">life_points</td>
                     <td><input name = "li_points" type = "text" 
                        id = "emp_id"></td>
                  </tr>

                     <tr>
                        <td width = "100">xp_points</td>
                        <td><input name = "xp_points" type = "text" 
                           id = "emp_salary"></td>
                     </tr>

                     <tr>
                        <td width = "100"> </td>
                        <td> </td>
                     </tr>

                     <tr>
                        <td width = "100"> </td>
                        <td>
                           <input name = "update" type = "submit" 
                              id = "update" value = "Update">
                        </td>
                     </tr>

                  </table>
               </form>
            <?php
         }
      ?>

   </body>
</html>

请帮助!(我的学生希望他们的网站完成!!)

3 个答案:

答案 0 :(得分:0)

检查此行

$dbhost = localhost;'localhost:id674442_wommath';

为什么有分号?

$dbhost设为"localhost"即可。

答案 1 :(得分:0)

问题在于您的$dbhost参数。

您必须将其设置为正确的值。

如果您可以分享更多详细信息,那将很容易帮助您。

如果您正在使用localhost,请务必写下以下内容:

$dbhost = 'localhost';$dbhost = '127.0.0.1';

并确保您的Apache服务器使用端口80,如果它不同,您必须在localhost或ip之后写入它:

$dbhost = 'localhost:port number';$dbhost = '127.0.0.1:port number';

答案 2 :(得分:0)

我已经更新了代码,代码中有很多错误。另外,如果您使用的是php7,请始终使用mysqli而不仅仅是mysql。

<html>

   <head>
      <title>Database</title>
   </head>

   <body>
      <?php

         if(isset($_POST['update'])) {


            $dbhost = 'localhost';
            $dbuser = 'root';
            $dbpass = 'passroot';

            $conn = mysqli_connect($dbhost, $dbuser, $dbpass);

            if(! $conn ) {
               die('Could not connect: ' . mysqli_error());
            }

            $fir_name = $_POST['fir_name'];
            $sur_name = $_POST['sur_name'];
            $li_points = $_POST['li_points'];
            $xp_points = $_POST['xp_points'];

            $sql = "UPDATE First_name SET Sur_name = '".$sur_name."' WHERE fir_name= '".$fir_name."'";

            mysqli_select_db('test_db');
            $retval = mysqli_query( $sql, $conn );

            if(! $retval ) {
               die('Could not update data: ' . mysqli_error());
            }
            echo "Updated data successfully\n";

            mysqli_close($conn);
         }
         else {


            ?>
               <form method = "post" action = "<?php $_PHP_SELF ?>">
                  <table width = "400" border =" 0" cellspacing = "1" 
                     cellpadding = "2">

                     <tr>
                        <td width = "100">First_Name</td>
                        <td><input name = "fir_name" type = "text" 
                           id = "emp_id"></td>
                     </tr>
                  <tr>
                     <td width = "100">Surname</td>
                     <td><input name = "sur_name" type = "text" 
                        id = "emp_id"></td>
                  </tr>
                  <tr>
                     <td width = "100">life_points</td>
                     <td><input name = "li_points" type = "text" 
                        id = "emp_id"></td>
                  </tr>

                     <tr>
                        <td width = "100">xp_points</td>
                        <td><input name = "xp_points" type = "text" 
                           id = "emp_salary"></td>
                     </tr>

                     <tr>
                        <td width = "100"> </td>
                        <td> </td>
                     </tr>

                     <tr>
                        <td width = "100"> </td>
                        <td>
                           <input name = "update" type = "submit" 
                              id = "update" value = "Update">
                        </td>
                     </tr>

                  </table>
               </form>
               <?php
         }
      ?>

   </body>
</html>