简体   繁体   中英

Problems with mysql_query

Following is the code snippet i am using to connect to a db. Its getting connected, but unable to execute even the simplest of select queries on the DB.

 <html>
  <head>
   <title>Testing Script Nonce</title>
  </head>
  <body>

   <FORM NAME ="form1" METHOD ="POST" ACTION = "testing.php">

   <INPUT TYPE = "TEXT" VALUE ="" NAME = "comment">
   <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Enter Comment">

   </FORM>


   <?php 
      $con = mysql_connect("localhost","root","******") or die(mysql_error());

      if(!$con)
    {
        echo " not connected";
    }


   //$comments = $_POST['comment'];
   //print ($comments);

    $db_selected = mysql_select_db('test', $con);

  if($db_selected)
    {
        echo " selected db properly";
    }



     $query = "SELECT * FROM data";

     $result = mysql_query($con,$query);
     $num=mysql_numrows($result);
     print ($num);

        ?>

   </body>
   </html>

It does not print the number of records present in the table 'data' and just does not do anything and keeps showing "selected db properly" when i press submit.

mysqli_* is not working when i tried.

Any help is much apreciated, i am a beginner in php

the mysql_query(); function takes query first, then connection . like:

mysql_query(query,connection)

Now, Change:

$result = mysql_query($con,$query);

to:

$result = mysql_query($query, $con);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM