can't connect to localhost on pc

So I’ve been working with this page of code for a while, trying to display it in localhost on my browser. I’ve connected with this exact code to localhost on my mac (using MAMP), but I need to get it to work on my work pc. I’ve installed both WAMP and MAMP for windows, making identical tables and databases on each (as is the one on my mac), but whenever I go to look at in localhost, it says both Connection failed and nothing found- however, the existing html text around it does show up. I’ve cleared it through all security systems, checked all spelling 1000x and tried different ports and creating creating different users - which localhost recognizes (the user). My friend suggested hosting it live and then using that server, which I have not attempted yet, but I still cannot understand why localhost isn’t working. Please help I’ve been dealing with this for so long and it would be a relief to figure it out.

Code:

<?php $product_id = $_GET['id']; $link = mysqli_connect('localhost', 'userx', 'root', 'legend'); if ($link->connect_error) { die("Connection failed: " . $link->connect_error); } if (mysqli_connect_errno()) { echo "Connection failed: " . mysqli_connect_error(); } $result = mysqli_query($link, "SELECT * FROM 'testx'"); ?>
<?php if (mysqli_num_rows($result) == 0) { echo 'nothing found'; } while($row = mysqli_fetch_array($result)) { ?>
	<p>Name: <?php echo $row['unitOne']; ?></p>
	<p>Box Quantity: <?php echo $row['unitTwo']; ?></p>
	<p> ok </p>

<?php } ?>
</div>
<?php mysqli_close($link); ?>

Does it display anything after the “Connection Failed:” ?

In seems you are outputting the error, is it blank?

Also add this to the top of your code.

[php]error_reporting(E_ALL);
ini_set(“display_errors”, 1);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service