Error 500 on webserver but not local host - php

I have a website that is working on my local machine and works on one set of webhosting but when I move it to the secure intranet that it needs to be placed on I get a server 500 error.
If I simplify the problem the server is not handling includes properly so I have put all content into the php page and I directly go to the GET part that is broken I put https://192.168.2.252/searchbysurname.php?q=morris in the address bar. This works on my normal localhost. I cant access the console logs on the server.
Search by Surname.php
<?php
session_start();
$q = ($_GET['q']);
# Connect
$dbc = #mysqli_connect ( '*******', '*********', '*******', '********')
OR die ( mysqli_connect_error() ) ;
mysqli_set_charset( $dbc, 'utf8' ) ;
$q1="SELECT employees.employeeid, employees.firstname, employees.surname FROM employees where UCASE(employees.surname) LIKE UCASE('%".$q."%')";
$r1 = mysqli_query($dbc,$q1);
echo "<table class = 'CSSTableGenerator'>";
while($row1 = mysqli_fetch_assoc($r1))
{
echo "
<tr><td>" . $row1['firstname'] . "</td><td>" . $row1['surname'] . "</td>
<td><input type='button' value='View' onclick='viewresults(" . $row1['employeeid'] . ")'></td>
<td><input type='button' value='Edit' onclick='editresults(" . $row1['employeeid'] . ")'></td>
</div></td></tr>
";
}
echo "</table>";?>
<div id="mainpart"><b></b></div></div>

the server in the intranet can have a different configuration?
Does it have mysqli for instance?
try to run a simple script with <?php phpinfo(); ?> both on local and intranet server and compare...

Related

Connection to database shows blank page

I have a file login.php to try to connect to my database.
I put the file login.ph inside the server folder and started the server.
Then i call the file in the browser and it shows a blank page. It does not respond even if i change the values of the database to an incorrect value.
I don't know if the error is inside the code or if it is another problem.
Thanks.
login.php:
<?php
$username = $_GET['fname'];
$password = $_GET['fpass'];
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$qz = "SELECT contact_id FROM contacts" ;
$qz = str_replace("\'","",$qz);
$result = mysqli_query($con,$qz);
while($row = mysqli_fetch_array($result))
{
echo $row['contact_id'];
}
mysqli_close($con);
?>
You must check $con variable that you have set with the result of the connection:
if (!$con) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
Do you have web server (say apache) installed and running on your server? You have to. Then put your file on the web server folder (say /var/www/html) and test in the browser.

php executing code from previous version of file

I'm a newbie using phpmyAdmin on a NAS drive. I have a simple html page which calls a php file (CommitteeExtract.php) to retrieve data from a mySQL database on the server. While developing I created a number of versions of the php file. I eventually got it working on version 8 (CommitteeExtract8.php). I now want to rename it to CommitteeExtract.php. However, when I do so the generated html file looks and works like the original (failed) verison. I have noticed renaming the file to any previous version give the result from that version, even if the code in the file is version 8.
Is the server caching the old versions and ignoring the current content? How do I get it to recognise only the current version.
I hope this is clear, any help would be appreciated:
CommitteeExtract.php looks like this:
<html>
<head>
<link rel="stylesheet" href="Style_Main.css" >
<title>Details</title>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Birthday</th>
<th>Email</th>
<th>Street</th>
<th>Town</th>
<th>MobilePhone</th>
</tr>
<?php
$servername = "xxx.xxx.x.xxx";
$username = "User";
$password = "1234";
$dbase = "mydatabase";
// Create connection
$conn = mysql_connect($servername, $username, $password) or die("Cannot ccnnect to server");
mysql_select_db($dbase) or die("Could not connect to $dbase database");
clearstatcache();
$query="SELECT FullName, DateOfBirth, EmailAddress, Street, Town, City, County, PostCode, MobilePhone FROM mydatabase'";
$result = mysql_query($query) or die("Query Data Extract failed");
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr>";
echo "<td>" . $row['FullName'] . "</td>";
echo "<td>" . $row["DateOfBirth"] . "</td>";
echo "<td>" . $row["EmailAddress"] . "</td>";
echo "<td>" . $row["Street"] . "</td>";
echo "<td>" . $row["Town"] . "</td>";
echo "<td>" . $row["MobilePhone"] . "</td>";
echo "</tr>";
}
mysql_free_result($result);mysql_close($link);
?>
</table>
</body>
<p>There's a button down here! Waheyyyy</p>
<button type="Button" onclick="ExportToExcel()">Export to Excel</button>
</html>
it is called from a menu item in a list by this
<li class="dropdown">Export Data
<div class="dropdown-content">
Gmail Contacts
Committee Extract
Produce Forms
</div>
</li>
When the href contains CommitteeExtract8.php, and the file is called CommitteeExtract8.php it works fine, returning my data.
However If rename the file to CommitteeExtract.php and change the href to CommitteeExtract.php it fails with same errors as the original CommitteeExtract.php, even though the code is completely different.
I'm sorry, I don't know how to view and post logs

Query PHP output suddenly only shows code, no values?

I recently had my eureka moment when I finished my first database connection. After closing my browser and reopening the html form, the output suddenly changed to code instead of the database values?
HTML form:
<form action="formulier3.php" method="post">
Hoogte: <input type="text" name="height"><br>
Breedte: <input type="text" name="width"><br>
<input type="submit">
</form>
PHP Page:
<?PHP
$user_name = "root";
$password = "root";
$database = "addressbook";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
$SQL = "SELECT * FROM price WHERE height = " . $_POST["height"] . " AND width = " . $_POST["width"] . "";
$result = mysql_query($SQL);
while ( $db_field = mysql_fetch_assoc($result) ) {
print $db_field['ID'] . "<BR>";
print $db_field['value'] . "<BR>";
print $db_field['height'] . "<BR>";
print $db_field['width'] . "<BR>";
}
mysql_close($db_handle);
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}
?>
This is my output:
"; print $db_field['value'] . "
"; print $db_field['height'] . "
"; print $db_field['width'] . "
"; } mysql_close($db_handle); } else { print "Database NOT Found "; mysql_close($db_handle); } ?>
Does anyone knows what's going on here?
Thank you in advance!
Somehow your server has stopped processing your php pages through the php processor (apache module or fastcgi or whatever).
What you see is the effect of presenting your php code as html. The fact that you don't see all your code but rather a small part of it, it is because the part from the first < (in <?php) until the first > (in print $db_field['ID'] . "<BR>"; is being parsed by the browser as an html tag and so it is not printed. If you look at the page source you'll see the full php code.
So there has been some server-side change that has produced that php files are directly server to the browser instead of parsed by the php engine.
One possible cause, is that you are developing in your local computer and when it worked you typed in your browser something like http://localhost/your_page.php but now you are opening the php file directly from the filesystem, so the browser shows something like file:///xampp/htdocs/your_page.php. You should always open your php pages through the web server (ie. using http://localhost/....) and never by double-clicking on the file in the file explorer.

php / mysql access denied with select into outfile

I have the following php code:
<?php
$hostname="db.";
$database="db..";
$username="db...";
$password="pw...";
$mysql = mysql_connect($hostname, $username, $password);
if(!$mysql)
echo 'Not conneted to the database...' . mysql_error() ;
else
echo 'Connected to the database...' ;
// select the appropriate database
$mysqldb = mysql_select_db( $database );
if(!$mysqldb)
die('Could not select the database...' . mysql_error());
else
echo '<br /><br />Connected to database...<br /><br />' ;
$chk_table_access = 'select * from table_name where 1';
$chk_access = mysql_query($chk_table_access);
echo $chk_table_access . '<br /><br />';
if (!$chk_access)
echo 'Could not access table: ' . mysql_error() ;
else
echo 'Table was accessed..<br /><br />' ;
$backup = 'SELECT * INTO OUTFILE "result.csv" FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY ';
$backup = $backup . "'" . '"' . "'" ;
$backup = $backup . ' FROM cities WHERE 1';
echo $backup . '<br /><br />';
$bk_success = mysql_query($backup);
if (!$bk_success)
echo 'The backup was not successful. Reason: ' . mysql_error();
?>
The program runs fine on localhost, but when I run it from my web site I get the following error: Access denied for user 'dbo????????'#'%' (using password: YES). The web help is not much help.
I do get the "Table was accessed.." message so I'm accessing the table okay. I do frwite to the directory every day without errors. I understand why it doesn't work in phpMyAdmin. I'm a little stumped. It's also the first question I've asked on this forum although I come here often for help. You guys (ladies included) rock.
Thanks in advance,
Steve
Your MySQL user apparently lacks the FILE privilege.
Does the MySQL server run on the same machine as the web server? If both servers run on different machines, you can stop right here: Even with FILE privilege, the output file would be created on the database server (and would probably inaccessible from the web server).

Can't Connect to MySQL DB

I'm trying to conntect to a mysql database for the first time. Can you see what's not working correctly below?
I get an error on line 3.
What would my server address look like from Godaddy to my database? I found that address in my control panel.
Thanks for any help. Never programmed using PHP before.
<body>
<?php
$con = mysql_connect("MydbName.db.3924516.hostedresource.com ","Userid","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Gallerys");
echo "<table border='1'>
<tr>
<th>Thumb Url </th>
<th>Gallery Url</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['THUMBURL'] . "</td>";
echo "<td>" . $row['GALLERYURL'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
</body>
Try check back the authenication settings, you might use the wrong host, username or password.
<?php
$con = mysql_connect("usually it is localhost","your MYSQL username","your MYSQL password");
// Checking the login details.
// Example of default xampp login details: $con = mysql_connect("localhost","root","");
// Xampp MYSQL default does not have password.
if (!$con) // If the login details are wrong, it will should an error.
{
die('Could not connect: ' . mysql_error());
}
?>
Without the exact error it is hard to be sure but on line 3 you have an extra space after hostedresource.com. Try removing the space between the end of the hostname and the quatation mark. Like so:
$con = mysql_connect("MydbName.db.3924516.hostedresource.com","Userid","password");

Categories