dongyi5570 2015-10-14 20:26
浏览 58

PHP脚本连接到数据库并创建一个条目,但它在SQL表中是空白的

I am trying to create a registration and login page by using PHP to connect to MYSQL database and insert the information into the tables. Unfortunately I am able to connect to the database with no problems, and it connects to the table. When I process the information by submitting it via the HTML form, it says that an entry has been added but the MYSQL database has a blank entry. I will post the HTML and PHP below. Thank you for all your help.

<HTML>

  <HEAD>
    <TITLE> Programming </TITLE>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <LINK REL="stylesheet" TYPE="text/css" href="homework2.css"> 

    </HEAD>
    <BODY>

      <!-- CSS for http://the7.dream-demo.com/ -->

      <div id="container">
        
        <div id="header">
          <div class="menuitem"> <a href="home.html">Home</a> </div>
          <div class="menuitem"><a href="products.html">Products</a></div>
          <div class="menuitem"><a href="cases.html">Case Studies</a></div>
          <div class="menuitem"><a href="pricing.html">Pricing</a></div>
          <div class="menuitem"><a href="aboutus.html">About Us</a></div>
        </div>

        <div id="bodycontent">
          
          <div id="banner">
           <div id="bannerleft"> <h1> We make you better athletes. Find out how! </h1> </div>
           <div id="signin"> 
             
             <form class="well form-inline" action="login.php" method="post">

              <input type="text" class="input-small" placeholder="Email"  name="email" >
              <input type="password" class="input-small" placeholder="Password" name="password">
              <br><br>

<!--
  If you do not want to use twitter bootstrap css then you should uncomment next 6 lines and uncomment the
  above 2 lines that provide input boxes

        <label for="email">Email:</label>
        <input type="text" name="email" id="email">
        <br>
        <label for="password">Password:</label>
        <input type="password" name="password" id="password">
        <br>
    -->

    <input type="submit" name="submit" id="logmein" value="Log In">
  </form>
  
</div>

</div>
<div id="featurestrip"> 

  
  <div id="signup">

    <form action="signup.php" method="post">

     
     <label for="user_name">Firstname:</label>
     <input type="text" name="signup-FirstName" id="signup-FirstName">
     <br>


<label for="user_pass">Password:</label>
     <input type="password" name="signup-Password" id="signup-Password">
     <br><br>

     <label for="user_email">Email:&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
     <input type="text" name="signup-email" id="signup-email">
     <br>
     
     <input type="submit" name="signmeup" id="signmeup" value="Sign Me Up!">
   </form>

 </div>

 <div id="featureright"> <p>Sign up and find out more on how we can help. Pricing starts at $19.95 a month. </p>
  <p><h3>Premium service starts at $49.95.</h3></p>

</div>   


</div>
<div id="corefeatures"> 



 <img height="200px" src="http://www.hockeymanitoba.ca/wp-content/uploads/2013/02/ltad-model.jpg">
</div>

<div id="testimonials"> Testimonial
  <img height="200px" src="http://www.neuroexplosion.com/storage/development%20model%20jpeg.jpg?__SQUARESPACE_CACHEVERSION=1305662626397">

  <img height="200px" src="http://www.phecanada.ca/sites/default/files/physical_literacy/LTAD_FMS.jpg">
</div>
       <!--
       <div id="portfolio"> Portfolio</div>
       <div id="skills"> Skills</div>
     -->
   </div>
   
   <div id="footer">Copyright Notice. All Rights Reserved. 2014</div>

 </div>

 
</BODY> 
</HTML>

PHP

PHP CODE BELOW

<?php


echo "<TR>";
    echo "<TD>";
    $dyn_user_name = $_POST['user_name'];
    echo $dyn_user_name;
    echo "</TD>";

    echo "<TD>";
    $dyn_user_pass = $_POST['user_pass'];
    echo $dyn_user_pass;
    echo "</TD>";

    echo "<TD>";
    $dyn_user_email= $_POST['user_email'];
    echo $dyn_user_email;
    echo "</TD>";
    echo "</TR>";


///This is for connecting to the database

$mysql_hostname = 'localhost';
$mysql_user = 'username';
$mysql_password = 'password';
$mysql_database = 'users_db2015';

$connect = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die ("Couldn't connect");

echo "Connection Successful";

  //to put data into database
  //select database
  $db_selected = mysql_select_db($mysql_database, $connect) 
  or die ("Couldn't connect to the database");

  if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}
  echo "<BR>Selected the database " . $mysql_database;



  //create sql query for data insertion

  $insert_sql = "INSERT INTO users1 (user_name, user_pass, user_email)
  values ('$dyn_user_name', '$dyn_user_pass', '$dyn_user_email')";



  $insert_result = mysql_query($insert_sql);
  //if successful, add another row, if not, then don't
  if ($insert_result){
    echo "<BR> 1 record added";
  }
  else{
    echo "<BR> Couldn't add the  information";
  }

   //Display data in the database (run a query in mysql to retrieve data)

  //prepare query
    $get_data_sql = "SELECT * FROM users1";

    //run query
    $result= mysql_query($get_data_sql);

     //get numbner of rows in the result 

    $num_rows = mysql_num_rows($result);



    //loop through result

    $q=0;

    while ($q < $num_rows){


      //takes results and gives you the first row, which is
      //stored as a hashtable
      //takes row and represents as key value pair, keep on using the value pair 
      //as the keys
      $new_row= mysql_fetch_array($result);


      //look into firstname and retrieve what's in that row, so it will return a name

      //do this same this for the score 
      echo $row_user_name = $new_row['user_name'];
      echo $row_user_pass = $new_row['user_pass'];
      echo $row_user_email = $new_row['user_email'];


      echo "<TR>";
      echo "<TD>";
      echo $row_user_name;
      echo "</TD>";     
      echo "<TD>";
      echo $row_user_pass;
      echo "</TD>";
      echo "<TD>";
      echo $row_user_email;
      echo "</TD>";
      echo "</TR>";

      $q=$q+1;
    }

?>
</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向