Reputation: 5
The code I am using works fine on a different computer by where I am currently it outputs the code in text format like it is a .txt document.
here are some of the pages affected.
connect.php
<?php
$con=mysqli_connect("hr-computing","student","codd","brodie");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
events.php
<?php
$deets = $_POST['deets'];
$deets = preg_replace('#[^0-9/]#i', '', $deets);
include ("connect.php");
$events = '';
$query = mysql_query('SELECT description FROM events WHERE evdate ="'.$deets.'"');
$num_rows= mysql_num_rows($query);
if ($num_rows > 0) {
$events.= '<div id="eventsControl"><button onMouseDown="overlay()">Close</button><br /><b> ' . $deets . '</b><br /><br /></div>';
while($row= mysql_fetch_array($query)) {
$desc = $row['description'];
$events .='<div id="eventsBody">'.$desc .'<br /><hr><br /></div>';
}
}
echo $events;
?>
calendar_start.php
<?php
$showmonth = $_POST['showmonth'];
$showyear = $_POST['showyear'];
$showmonth= preg_replace('#[^0-9]#i', '', $showmonth);
$showyear= preg_replace('#[^0-9]#i', '', $showyear);
$day_count = cal_days_in_month(CAL_GREGORIAN, $showmonth, $showyear);
$pre_days = date('w', mktime(0,0,0, $showmonth, 1, $showyear));
$post_days = (6-(date('w', mktime(0,0,0, $showmonth, $day_count, $showyear))));
echo '<div id="calendar_wrap">';
echo '<div class="title_bar">';
echo '<div class="previous_month"><input name="button" type="submit" value="Previous Month" onClick="javascript:last_month();"></div>';
echo '<div class="show_month">' . date('F', mktime(0, 0, 0, $showmonth)) . ' ' . $showyear . '</div>';
echo '<div class="next_month"><input name="button" type="submit" value="Next Month" onClick="javascript:next_month();"></div>';
echo '</div>';
echo '<div class="week_days">';
echo '<div class="days_of_the_week">Sun</div>';
echo '<div class="days_of_the_week">Mon</div>';
echo '<div class="days_of_the_week">Tues</div>';
echo '<div class="days_of_the_week">Wed</div>';
echo '<div class="days_of_the_week">Thur</div>';
echo '<div class="days_of_the_week">Fri</div>';
echo '<div class="days_of_the_week">Sat</div>';
echo '<div class="clear"></div>';
echo '</div>';
if ($pre_days != 0) {
for($i=1; $i<=$pre_days; $i++) {
echo '<div class="non_cal_day"></div>';
}
}
include ("connect.php");
for ($i=1; $i<= $day_count; $i++) {
$date = $i.'/'.$showmonth.'/'.$showyear;
$query = "Select id FROM events WHERE evDate = '$date'";
$num_rows = 0;
if($result = mysql_query($query)) {
$num_rows = mysql_num_rows($result);
}
if($num_rows > 0) {
$event = "<input name='$date' type='submit' value='Details' id='$date'
onClick='javascript:show_details(this);'>";
}
echo '<div class="cal_day">';
echo '<div class="day_heading">' . $i . '</div>';
if($num_rows != 0) { echo "<div class='openings'><br/>" . $event . "</div>";}
echo '</div>';
}
if ($post_days !=0) {
for($i=1; $i<=$post_days; $i++) {
echo '<div class="non_cal_day"></div>';
}
}
echo '</div>';
?>
working php file
<html>
<body>
<style>
body
{
background-color:#CD0074;
}
</style>
<form action="http://hr-computing/public/Brodie Evans/project/login.php" method="post">
FirstName: <input type="text" name="firstname" /><br />
Surname: <input type="text" name="surname" /><br />
Email: <input type="text" name="email" /><br />
Password: <input type="password" name="p" id="password"/><br />
<input type="submit" value="Submit"/>
</form>
<?php
$con=mysqli_connect("*****","*******","****","*******");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO Details (FirstName, surname, email)
VALUES('$_POST[firstname]','$_POST[surname]','$_POST[email]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
</body>
</html>
Upvotes: 0
Views: 129
Reputation: 2681
Is apache configured to interpret files with suffix ".php" as PHP files? Check your apache's mod_php configuration. it should contain something like this.
location depends on what kind of server you run. This sample shows xampp on windows. See /apache/conf/extra/httpd-xampp.conf
#
# PHP-Module setup
#
LoadFile "<path to php installation>/php5ts.dll"
LoadModule php5_module "<path to php installation>/php5apache2_2.dll"
<FilesMatch "\.php[5]*$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
And another sample for Debian. See /etc/apache2/mods-available/php5.conf
<IfModule mod_php5.c>
<FilesMatch "\.ph(p3?|p5?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
# To re-enable php in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
</IfModule>
Upvotes: 1
Reputation: 2621
That's why on your "different computer" PHP is not running. When you don't have PHP running or installed (and configured) on your webserver, Apache will output the code as it is.
The PHP code just can not be parsed without a installed PHP.
Upvotes: 0
Reputation: 2639
I believe that you haven't got PHP installed in Apache, so the Apache cannot interpret files with php extention as a proper script. Please check if your Apache server is installed, configured in a proper way and the PHP module is also installed.
I hope you are trying to call your script by http://localhost/.../calendar_start.php
, not by file://C:/www/.../calendar_start.php
?
Upvotes: 0