Same code working on 000webhost online server but not on both wamp and xampp

Hello,
I have this link on page1.php

<a href="page2.php?word=abandon">abandon</a>

And this is the code for page2.php

<?php
include'bddconnect.php';
$output = '';
$word = $_GET['word'];
$query = "SELECT * FROM table1 WHERE word='$word'";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result))
{
$word= $row['word'];
$definition = $row['definition'];
$id = $row['id'];
$output .= ''.$word.'<br>'.$definition.'';
}
?>
<html>
<body>
<?php print("$output"); ?>
</body>
</html>

So as mentioened in the title this code doesn’t work and dispays a blank white page while using wamp or xampp server while it works fine on 000webhost online server and displays the word and definition when clicking the link.
Is there any explanation to this ?
Thank you in advance.

Is your database connection pointing to the same DB in both locations?

no I have created a database on wamp and an other in xampp but I gave them the same name bdd

Which versions of PHP are the server and your local set-ups using? Though I don’t see anything version specific in there.

[off-topic]And I’ll be the one to mention the really obvious SQL injection vulnerability in this code.[/off-topic]

And did you put an entry into all 3 databases’ table1’s with word=abandon?

yes of caurse

Can you define not working? What happens (or doesn’t) that differs from your expectations? Are there any errors reported?

For S*** And Giggles, change this:
<?php print("$output"); ?>
to this:

<?php echo mysqli_error(); print_r($row); echo $word; print("$output"); ?>

there are no errors just blank page using wamp or xamp but on the other hand with 000webhost when I click the link above it gives me the word abandon with it’s definition that I previously entered manually in table1

And error reporting is on?

I replaced with your code it gives me this error :
Warning : mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\page2.php on line 17
abandon

I suppose yes because I often had errors before

sorry.
<?php echo mysqli_error($con); print_r($row); echo $word; print("$output"); ?>

now no errors but only word (abandon ) is displayed without definition

Indicates your query returned 0 results.

<?php echo mysqli_num_rows($result); echo $query; ?>

0SELECT * FROM table1 WHERE word=‘abandon’

Can I ask a question so since the code is working perfectly on 000webhost online server I suppose that xampp or wamp handle code differenntly no ?

While debugging, instead of programming with blinkers which ignore errors and warnings add these lines to the top of every page:

<?php
declare(strict_types=1); // PHP 7, fail fast
// override php.ini settings
error_reporting(-1); // maximum error reporting
ini_set('display_errors', 'true'); // display to screen

// 

Your query returned 0 results. Go into your databases and verify that you have put an entry into that table in each of them, because everything is telling me you haven’t.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.