Had to move servers in an emergency, and a PHP page that was working on the old server no longer works. (It's not a question of connecting to the db.) Code's below. Anyone know why this worked at IX Web Hosting but not at GoDaddy?
Thanks,
RedKnights
<?php
require_once('../config.php');
require_once('topnav.inc.php');
session_start();
function format_phone($phone)
{
return "(".substr($phone, 0, 3).") ".substr($phone, 3, 3)."-".substr($phone, 6);
}
function query_with_callback($from, $to, $rowcallback)
{
global $report_type, $report_clinics, $report_sort, $report_questions;
$dfrom = "20".substr($from, 6, 2)."-".substr($from, 0, 2)."-".substr($from, 3, 2)." 00:00:00";
$dto = "20".substr($to, 6, 2)."-".substr($to, 0, 2)."-".substr($to, 3, 2)." 23:59:59";
$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME ,$link);
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
$query = "SELECT * FROM ((SELECT a.formtype, a.clinicid, a.cliniccompany, a.clinicemail, a.datesent, CONCAT(a.patientname,' ',a.patientlastname) as patientname, a.patientphone, a.patientemail";
if ($report_questions)
{
// if ($report_type == "0" || $report_type == "1")
$query .= ", a.patientquestion";
// if ($report_type == "0" || $report_type == "2")
$query .= ", a.q1 as areas_threat, a.q2 as skin_type, a.q3 as sun_tanned, a.q4 as photosensitive, a.q5 as hair_color";
}
$query .= " FROM askexpert a INNER JOIN customer c ON c.id = a.clinicid ) UNION (";
$query .= "SELECT '3' as formtype, customer_id as clinicid, company as cliniccompany, c.email as clinicemail, from_unixtime(ci.date_timestamp) as datesent, CONCAT(firstname,' ',realname) as patientname, ci.phone as patientphone, ci.email as patientemail";
if ($report_questions)
{
$query .= ", ci.info as patientquestion, areas_treat, skin_type, sun_tanned, photosensitive, hair_color";
}
$query .= " FROM contact_ip ci INNER JOIN customer c ON c.id = ci.customer_id )) AS res";
// if ($report_clinics == "1" || $report_clinics == "2")
// $query .= " INNER JOIN customer c ON c.id = a.clinicid";
$query .= " WHERE datesent >= '$dfrom' AND datesent <='$dto'";
if ($report_type != "0")
$query .= " AND formtype = '$report_type'";
if ($report_clinics == "1")
$query .= " AND (clinicid BETWEEN 1 AND 14)";
else if ($report_clinics == "2")
$query .= " AND c.user_id <> 1";
if ($report_sort == "0")
$query .= " ORDER BY datesent ASC";
else if ($report_sort == "1")
$query .= " ORDER BY datesent DESC";
else if ($report_sort == "2")
$query .= " ORDER BY clinicid ASC";
else if ($report_sort == "3")
$query .= " ORDER BY clinicid DESC";
$result = mysql_query($query, $link);
if ($result)
{
while ($row = mysql_fetch_assoc($result))
$rowcallback($row);
mysql_free_result($result);
}
mysql_close($link);
}
function print_report_row($row)
{
global $report_type, $report_questions;
echo "<tr><td><span style=\"color:#000099;font-weight:bold\">";
if ($row['formtype'] == '1')
echo "AE";
else if ($row['formtype'] == '2')
echo "IC";
else
echo "GC";
echo "</span></td><td>".$row['clinicid']."</td>";
echo "<td>".$row['cliniccompany']."</td>";
echo "<td>".$row['clinicemail']."</td>";
echo "<td>".$row['datesent']."</td>";
echo "<td>".$row['patientname']."</td>";
echo "<td>".$row['patientemail']."</td>";
echo "<td>".format_phone($row['patientphone'])."</td>";
if ($report_questions)
{
if ($report_type == "0" || $report_type == "1")
echo "<td>".$row['patientquestion']."</td>";
if ($report_type == "0" || $report_type == "2")
{
echo "<td>".$row['areas_threat']."</td>";
echo "<td>".$row['skin_type']."</td>";
echo "<td>".$row['sun_tanned']."</td>";
echo "<td>".$row['photosensitive']."</td>";
echo "<td>".$row['hair_color']."</td>";
}
}
echo "</tr>";
}
function print_report($from, $to)
{
global $report_type, $report_questions;
echo "<table width=100%>";
$cs = 7;
if ($report_questions && ($report_type == "0" || $report_type == "1"))
$cs +=2;
if ($report_questions && ($report_type == "0" || $report_type == "2"))
$cs +=6;
echo "<tr><td bgcolor=#fffff0 colspan=$cs><h2>Report for dates from $from to $to</h2></td></tr>";
echo "<tr><th></th><th>Clinic ID</th><th>Clinic Name</th><th>Clinic Email</th><th>Date Sent</th><th>Patient Name</th><th>Patient Email</th><th>Patient Phone</th>";
if ($report_questions)
{
if ($report_type == "0" || $report_type == "1")
echo "<th>Patient Question</th>";
if ($report_type == "0" || $report_type == "2")
echo "<th>Areas Threat</th><th>Skin Type</th><th>Sun Tanned ?</th><th>Photosensitive ?</th><th>Hair Color</th>";
}
echo "</tr>";
query_with_callback($from, $to, print_report_row);
echo "</table>";
}
function stream_field($row, $field, $formatfn = null)
{
$sep = ";";
if(!isset($row[$field]))
return "NULL".$sep;
elseif ($row[$field] != "")
if ($formatfn)
return $formatfn(preg_replace("/\r\n|\r|\n/", " ", $row[$field])).$sep;
else
return preg_replace("/\r\n|\r|\n/", " ", $row[$field]).$sep;
else
return "".$sep;
}
function stream_row($row)
{
global $report_type, $report_questions;
$sep = ";";
$schema_insert = "";
$schema_insert .= stream_field($row, 'clinicid');
$schema_insert .= stream_field($row, 'cliniccompany');
$schema_insert .= stream_field($row, 'clinicemail');
$schema_insert .= stream_field($row, 'datesent');
$schema_insert .= stream_field($row, 'patientname');
$schema_insert .= stream_field($row, 'patientemail');
$schema_insert .= stream_field($row, 'patientphone', format_phone);
if ($report_questions)
{
if ($report_type == "0" || $report_type == "1")
$schema_insert .= stream_field($row, 'patientquestion');
if ($report_type == "0" || $report_type == "2")
{
$schema_insert .= stream_field($row, 'areas_threat');
$schema_insert .= stream_field($row, 'skin_type');
$schema_insert .= stream_field($row, 'sun_tanned');
$schema_insert .= stream_field($row, 'photosensitive');
$schema_insert .= stream_field($row, 'hair_color');
}
}
$schema_insert .= ";";
print(trim($schema_insert));
print "\n";
}
if (!isset($date_to))
$date_to = date("m/d/y");
if (!isset($date_from))
$date_from = date("m/d/y", time()-30*24*60*60);
if (!isset($report_type))
$report_type = "0";
if (!isset($report_clinics))
$report_clinics = "0";
if (!isset($report_sort))
$report_sort = "0";
if (!isset($report_questions))
$report_questions = 0;
if (isset($report_download))
{
download_report($date_from, $date_to);
}
?>
<html>
<center>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><td height="40"><h1>Admin - Ask Expert report</h1></td></tr>
</table>
<?php admin_top_nav(); ?>
<form method='post'>
<table>
<tr>
<td>Select form types for report :</td>
<td>
<select name="report_type" id="report_type" size=1>
<option value="0" <?php if ($report_type == "0"){echo "selected";}?>>ALL</option>
<option value="1" <?php if ($report_type == "1"){echo "selected";}?>>Ask an Expert</option>
<option value="2" <?php if ($report_type == "2"){echo "selected";}?>>Instant Consultation</option>
<option value="3" <?php if ($report_type == "3"){echo "selected";}?>>General Contact</option>
</select>
</td>
<tr>
<tr>
<td>Filter clinics :</td>
<td>
<select name="report_clinics" id="report_clinics" size=1>
<option value="0" <?php if ($report_clinics == "0"){echo "selected";}?>>ALL clinics</option>
<option value="1" <?php if ($report_clinics == "1"){echo "selected";}?>>Signature Web</option>
<option value="2" <?php if ($report_clinics == "2"){echo "selected";}?>>All except Signature</option>
</select>
</td>
</tr>
<tr>
<td>Sort results by :</td>
<td><input type=radio name="report_sort" value="0" <?php if ($report_sort == "0"){echo "checked";}?>>Sent date (ASC)</td>
<tr>
<tr>
<td></td>
<td><input type=radio name="report_sort" value="1" <?php if ($report_sort == "1"){echo "checked";}?>>Sent date (DESC)</td>
<tr>
<tr>
<td></td>
<td><input type=radio name="report_sort" value="2" <?php if ($report_sort == "2"){echo "checked";}?>>Clinic ID (ASC)</td>
<tr>
<tr>
<td></td>
<td><input type=radio name="report_sort" value="3" <?php if ($report_sort == "3"){echo "checked";}?>>Clinic ID (DESC)</td>
<tr>
<tr><td colspan=2><input type="checkbox" name="report_questions" id="report_questions" <?php if ($report_questions){echo "checked";}?> />Include questions in report</td></tr>
<tr><td colspan=2>Select time range for report : (in mm/dd/yy format example 09/19/07)</td></tr>
<tr>
<td>From : <input id='date_from' name='date_from' size=15 value='<?php echo $date_from; ?>'/></td>
<td>To : <input id='date_to' name='date_to' size=15 value='<?php echo $date_to; ?>' /></td>
</tr>
<tr>
<td><input type='submit' value='View results' name='report_view'/></td>
<td><input type='submit' value='Download exel report' name='report_download' /></td>
</tr>
</table>
</form>
<?php
if (isset($report_view))
{
echo "<hr/>";
print_report($date_from, $date_to);
}
?>
</body>
</html>