Php script can’t find MySQL table Windows site

#1

I am using MS Expression Web 4 and an associated host which provides the MySQL database. Using php code I found online, I am attempting to develop a login system that will eventually redirect the client logging in to a client specific page set up for that client. At this point however, I am unable to connect to the MySQL database table for verification. When I run the connect script I get the message that the table can’t be found. The tech support at the host is able to connect but they tell me that there is something amiss in my code but won’t point me where to look. Of course they want to sell design services. They tell me that Windows, php and MySQL do not play well together. I am looking to find out how to specify the table in addition to the database since that is where the connection throws up the error. Can anyone point me to an instructional location or send me in the direction where my code might be deficient or can I not so my task using platforms I have chosen?

#2

They don’t play well together, and if you have a Windows server, you really should be using something like ASP for a site, but that is a different topic.

How are you trying to connect to the database?
Are you sure that you can connect to it to begin with?
Are you sure the table is in the database you are trying to connect to?

#3

I don’t have the code in front of me but I created a php config page to call the database. I am apparently connecting with it since the error message indicates that it is looking for the table, although i suppose that may not mean it has connected. According to the host tech support they are running their own php script and logging to the dbase without issue. However i suspect they are using Linux as that is how they told me to connect but I am sort of stuck with the Windows platform. I do know the table is in the database as i created the table directly on the host site and can go to mysql administrator and change it and add data.

So I did set up an ASP login as instructed on Microsoft Support using Expression Web 4 with similar results, couldn’t connect. Did not try to troubleshoot that out as the instructions were many years old.

I am thinking about just doing a Wordpress plugin, what is your take on that idea?

Thanks for the helpful information.

#4

WordPress wont help you if you can’t connect to the database.

I would need to see code the know more.

#5

So I set up another file set and I am getting a different result. the config script is:

<?php
   define('DB_SERVER', 'mysqlcluster16');
   define('DB_USERNAME', 'sndconsql');
   define('DB_PASSWORD', 'xxxxxx');
   define('DB_DATABASE', 'passwordmgt');
   $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
   // Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

?>

The login script is:

<?php
   include("config.php");
   session_start();
   
   if($_SERVER["REQUEST_METHOD"] == "POST") {
      // username and password sent from form 
      
      $myusername = mysqli_real_escape_string($db,$_POST['username']);
      $mypassword = mysqli_real_escape_string($db,$_POST['password']); 
      
      $sql = "SELECT id FROM admin WHERE username = '$myusername' and passcode = '$mypassword'";
      $result = mysqli_query($db,$sql);
      $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
      $active = $row['active'];
      
      $count = mysqli_num_rows($result);
      
      
      // If result matched $myusername and $mypassword, table row must be 1 row
		
      if($count == 1) {
         session_register("myusername");
         $_SESSION['login_user'] = $myusername;
         
         header("location: welcome.php");
      }else {
         $error = "Your Login Name or Password is invalid";
      }
   }
?>
<html>
   
   <head>
      <title>Login Page</title>
      
      <style type = "text/css">
         body {
            font-family:Arial, Helvetica, sans-serif;
            font-size:14px;
         }
         label {
            font-weight:bold;
            width:100px;
            font-size:14px;
         }
         .box {
            border:#666666 solid 1px;
         }
      </style>
      
   </head>
   
   <body bgcolor = "#FFFFFF">
	
      <div align = "center">
         <div style = "width:300px; border: solid 1px #333333; " align = "left">
            <div style = "background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>
				
            <div style = "margin:30px">
               
               <form action = "" method = "post">
                  <label>UserName  :</label><input type = "text" name = "username" class = "box"/><br /><br />
                  <label>Password  :</label><input type = "password" name = "password" class = "box" /><br/><br />
                  <input type = "submit" value = " Submit "/><br />
               </form>
               
               <div style = "font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div>
					
            </div>
				
         </div>
			
      </div>

   </body>
</html>

The error messages I get when entering the login information is:
Warning : mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in \WDP\DFS\30\4\6\3\3060094364\user\sites\3184410.site\www\login.php on line 13

Warning : mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in \WDP\DFS\30\4\6\3\3060094364\user\sites\3184410.site\www\login.php on line 16

So I have no idea where to go from here. I did enter code that was supposed to present an error message if the connection to the database failed and no error reported so I am left to believe the connection was made.

I appreciate your time if you wish to further this dialog.

#6

That means there is an issue with your query.

For one thing, you want to use paramaterized queries and not just supplying user submitted data, real escape string is a joke.

https://www.w3schools.com/php/php_mysql_prepared_statements.asp

And because the query failed, it is now false, and not what the other functions need to work, so they are telling you that.

PDO is better, but I’ll leave that up to you to figure out later.

1 Like