Page 1 of 1
[SOLVED]index
Posted: Sat Nov 15, 2008 1:15 pm
by MMalvin
I recently took over a friends website written in PHP. The index file looks like:
$rpage = @$_GET['page'];
if($rpage == ''){
include('welcome.php');
}elseif($rpage == 'usersearch'){
include('user_search.php');
}elseif($rpage == 'userdetails'){
include('user_details.php');
ETC.... The original file works fine but I wrote a new php page I want to add to the index. If I add a new elseif/include portion the entire page fails to load. Any help would be GREATLY appreciated.
Thanks,
Max
Re: index
Posted: Sat Nov 15, 2008 2:54 pm
by califdon
You haven't shown us how you modified your code. When you get a blank page, trying to load a page generated by PHP, it means that there was a syntax error, so your web server was unable to figure out what PHP was supposed to do, thus it creates a blank page. My first guess is that you failed to close a code block with a curly bracket. If-else is an ugly construct for these kinds of situations, made even uglier when you don't indent your code. A select statement would be more appropriate and a whole lot easier to code and to read. In any case, if you will show us ALL the code, as modified by you, we can probably tell you what's wrong.
Re: index
Posted: Sat Nov 15, 2008 3:24 pm
by MMalvin
Thank you for your reply. I have figured out how to make the page load from the index. I now have a new issue. I'll insert the code then ask the question.
<?php
include('./includes/load_database.php');
connect_mysql();
$userid = $_GET['uid'];
if($_POST['update_hold'] == '1'){
$sql = "UPDATE `zogo_users` SET `hold` = '".$_POST['userhold']."' WHERE `id` = '".$userid."' LIMIT 1;";
mysql_query($sql);
}
if($_POST['update_mg'] == '1'){
$f_holdmessage = mysql_escape_string($_POST['hold_message']);
$sql = "UPDATE `zogo_users` SET `hold_message` = '".$f_holdmessage."' WHERE `id` = '".$userid."' LIMIT 1 ;";
mysql_query($sql);
}
$sql = "SELECT * FROM `zogo_users` WHERE `id` = $userid";
$result = mysql_query($sql);
$zogo_user = mysql_fetch_array($result);
$sql = "SELECT * FROM `zogo_users` WHERE `id` = '".$zogo_user['referred']."'";
$result = mysql_query($sql);
$ref_user = mysql_fetch_array($result);
?>
<br><br>
<table border="0"<?php if($zogo_user['hold'] == 1) echo ' bgcolor="#FFAAAA"'; ?>>
<?php if($zogo_user['hold'] == 1) echo '<tr><td align="center" colspan="5" bgcolor="#FFFFFF"><font color="#FF0000"><b>ACCOUNT ON HOLD</b></font></td></tr>'; ?>
<tr><td>User ID:</td><td><b><?php echo $zogo_user['id']; ?></b></td>
<td width="100"></td>
<td>Referred By:</td><td><a href="?page=userdetails&uid=<?php echo $ref_user['id']; ?>"><?php echo $ref_user['username']; ?></a></td>
</tr>
<tr><td>User Name:</td><td colspan="4"><b><?php echo $zogo_user['username']; ?></b></td></tr>
<tr><td colspan="6"> </td></tr>
<tr>
<td>First Name:</td><td><b><?php echo $zogo_user['firstname']; ?></b></td>
<td width="10"> </td>
<td>Last Name: </td><td><b><?php echo $zogo_user['lastname']; ?></b></td></tr>
<tr><td>Email:</td><td colspan="4"><b><?php echo $zogo_user['email']; ?></b></td></tr>
<tr><td>Birth Date:</td><td colspan="4"><b><?php echo $zogo_user['birthday']; ?></b></td></tr>
<tr><td colspan="6"> </td></tr>
<td>Current Points:</td><td><b><?php echo $zogo_user['zpoints']; ?></b></td>
<td width="10"> </td>
<td>Total Points: </td><td><b><?php echo $zogo_user['zpoints_total']; ?></b></td></tr>
<tr><td>Zogo Score:</td><td colspan="4"><b><?php echo $zogo_user['zscore']; ?></b></td></tr>
<tr><td colspan="6"> </td></tr>
<tr><td>Signed Up:</td><td colspan="4"><b><?php echo $zogo_user['signup']; ?></b></td></tr>
<tr><td>Last Login:</td><td colspan="4"><b><?php echo $zogo_user['lastlogin']; ?></b></td></tr>
<tr><td colspan="6"> </td></tr>
<tr><td valign="top">Shipping Address: </td><td colspan="4"><b>
<?php if($zogo_user['shiprec'] != 0){
$sql = "SELECT * FROM `zogo_usershipping` WHERE `id` = ".$zogo_user['shiprec'];
$result = mysql_query($sql);
$zogo_ship = mysql_fetch_array($result);
echo $zogo_ship['name'].'<br>'.$zogo_ship['address'].'<br>'.$zogo_ship['city'].', '.$zogo_ship['state'].' '.$zogo_ship['zipcode'];
}else{
echo 'No saved address.';
}
?>
</b></td></tr>
<td width="10"> </td>
<tr><td valign="top">Account Hold:</td><td colspan="4"><form action="" method="post">
<select size="1" name="userhold" class="formtextbox">
<option value="0"<?php if($zogo_user['hold'] == 0) echo ' selected'; ?>>Normal</option>
<option value="1"<?php if($zogo_user['hold'] == 1) echo ' selected'; ?>>Hold Account</option>
</select> <input type="submit" value="Update" class="formtextbox"><input type="hidden" name="update_hold" value="1">
<?php
if($zogo_user['hold'] == 1){
echo '<br><textarea name="hold_message" class="formtextbox" style="width: 200px;">'.$zogo_user['hold_message'].'</textarea><input type="hidden" name="update_mg" value="1">';
}
?>
</form>
</td></tr>
</table><br><br>
<?php
$sql = "SELECT * FROM `zogo_users_logs` WHERE `user_id` = $userid GROUP BY `ip`";
$result = mysql_query($sql);
echo '<table border="0" width="95%" class="tdstyle1">';
echo '<tr><td class="datum1"><b>IP Address:</b></td><td class="datum1"><b>Recorded Logins:</b></td><td class="datum1"><b>Users With This IP:</b></td></tr>';
while($records = @mysql_fetch_array($result)){
$sql = "SELECT COUNT(*) FROM `zogo_users_logs` WHERE `ip` = '".$records['ip']."' AND `user_id` = '".$records['user_id']."'";
$result2 = mysql_query($sql);
$ipcount = @mysql_fetch_array($result2);
$ipcount = $ipcount['COUNT(*)'];
echo '<tr>';
echo '<td class="datum1">'.$records['ip'].'</td>';
echo '<td class="datum1">'.$ipcount.'</td>';
echo '<td class="datum1">';
$result2 = mysql_query("SELECT * FROM `zogo_users_logs` WHERE `ip` = '".$records['ip']."' GROUP BY `user_id`");
while($records2 = @mysql_fetch_array($result2)){
$result3 = mysql_query("SELECT * FROM `zogo_users` WHERE `id` = '".$records2['user_id']."'");
$ipuser = @mysql_fetch_array($result3);
echo '<a href="?page=userdetails&uid='.$ipuser['id'].'">'.$ipuser['username'].'</a><br>';
}
echo '</td>';
echo '</tr>';
}
echo '</table>';
?>
<br><br>
<?php
$sql = "SELECT COUNT(*) FROM `zogo_users` WHERE `referred` = $userid";
$result = mysql_query($sql);
$refnum = @mysql_fetch_array($result);
$refnum = $refnum['0'];
$sql = "SELECT * FROM `zogo_users` WHERE `referred` = $userid ORDER BY `signup` DESC";
$result = mysql_query($sql);
///////////////////////////////////
// Make Table
///////////////////////////////////
echo '<table border="0" width="95%" class="tdstyle1">';
echo '<tr><td class="datum1"><b>User:</b></td><td class="datum1"><b>Email Address:</b></td><td class="datum1"><b>Signup Date:</b></td></tr>';
if($refnum > 0){
$i = 0;
while($records = @mysql_fetch_array($result)){
echo '<tr>';
echo '<td class="datum1">';
echo '<a href="?page=userdetails&uid='.$records['id'].'">';
echo $records['username'].'</a></td>';
echo '<td class="datum1">'.$records['email'].'</td>';
echo '<td class="datum1">'.substr($records['signup'], 0, 10).'</td>';
echo '</tr>';
$i++;
if($zp_preview == 1 & $i > 2) break;
}
}else{
echo '<tr><td colspan="3" class="datum1">No users referred.</td></tr>';
}
echo '</table>';
?>
<br><br>
<?php
//Fetch all activity.
$sql = "SELECT * FROM `cj_orders` WHERE `sid` LIKE 'zgnw\_%\_$userid\_%\_%'";
$result = mysql_query($sql);
$i = 0;
while($records = @mysql_fetch_array($result)){
$user_orders["$i"]['rate'] = $records['commissionAmount'];
$user_orders["$i"]['store'] = ucwords($records['advertiserName']);
$user_orders["$i"]['date'] = substr($records['eventDate'], 0, 10);
$user_orders["$i"]['sale'] = '$'.number_format($records['saleAmount'], 2);
$user_orders["$i"]['sid'] = $records['sid'];
$user_orders["$i"]['zpoints'] = $records['zpoints'];
$user_orders["$i"]['status'] = $records['status'];
$user_orders["$i"]['type'] = 'CJ';
$i++;
}
$sql = "SELECT * FROM `pm_orders` WHERE `sid` LIKE 'zgnw\_%\_$userid\_%\_%'";
$result = mysql_query($sql);
while($records = @mysql_fetch_array($result)){
$user_orders["$i"]['rate'] = $records['commissionAmount'];
$user_orders["$i"]['store'] = ucwords($records['adname']);
$user_orders["$i"]['date'] = $records['date'];
$user_orders["$i"]['sale'] = '$'.number_format($records['saleAmount'], 2);
$user_orders["$i"]['sid'] = $records['sid'];
$user_orders["$i"]['zpoints'] = $records['zpoints'];
$user_orders["$i"]['status'] = $records['status'];
$user_orders["$i"]['type'] = 'PM';
$i++;
}
$sql = "SELECT * FROM `revu_orders` WHERE `sid` LIKE 'zgnw\_%\_$userid\_%\_%'";
$result = mysql_query($sql);
while($records = @mysql_fetch_array($result)){
$user_orders["$i"]['rate'] = $records['rate'];
$user_orders["$i"]['store'] = ucwords($records['name']);
$user_orders["$i"]['date'] = substr($records['date'], 0, 10);
$user_orders["$i"]['sale'] = 'Offer'; //number_format($records['saleAmount'], 2);
$user_orders["$i"]['sid'] = $records['sid'];
$user_orders["$i"]['zpoints'] = $records['zpoints'];
$user_orders["$i"]['status'] = $records['status'];
$user_orders["$i"]['type'] = 'RU';
$i++;
}
$sql = "SELECT * FROM `zogo_credits` WHERE `sid` LIKE 'zgnw\_%\_$userid\_%\_%'";
$result = mysql_query($sql);
while($records = @mysql_fetch_array($result)){
$user_orders["$i"]['rate'] = $records['commission'];
$user_orders["$i"]['store'] = ucwords($records['name']);
$user_orders["$i"]['date'] = substr($records['date'], 0, 10);
$user_orders["$i"]['sale'] = 'Credit';
$user_orders["$i"]['sid'] = $records['sid'];
$user_orders["$i"]['zpoints'] = $records['zpoints'];
$user_orders["$i"]['status'] = $records['status'];
$user_orders["$i"]['type'] = 'ZP';
$i++;
}
$sortArr = array();
foreach ($user_orders as $key => $value ){
$sortArr[ $key ] = $value['date'];
}
arsort( $sortArr );
$resultArr = array();
foreach ( $sortArr as $key => $value ){
$resultArr[ $key ] = $user_orders[ $key ];
}
$user_orders = $resultArr;
///////////////////////////////////
// Make Table
///////////////////////////////////
echo '<table border="0" width="95%" class="tdstyle1">';
echo '<tr><td class="datum1"><b>Store:</b></td><td class="datum1"><b>Sale:</b></td><td class="datum1"><b>Commission:</b></td><td class="datum1"><b>Date:</b></td><td class="datum1"><b>Points:</b></td></tr>';
if(count($user_orders)){
$i = 0;
$commission = 0;
foreach ($user_orders as $key => $value ){
echo '<tr>';
echo '<td class="datum1">'.$user_orders[$key]['store'].'</td>';
echo '<td class="datum1">'.$user_orders[$key]['sale'].'</td>';
echo '<td class="datum1">$'.number_format($user_orders[$key]['rate'],2).'</td>';
echo '<td class="datum1">'.$user_orders[$key]['date'].'</td>';
echo '<td class="datum1"><span class="clgreen"><b>'.$user_orders[$key]['zpoints'].'</b></span></td>';
echo '</tr>';
$commission += $user_orders[$key]['rate'];
$i++;
}
echo '<tr><td colspan="4" class="datum1"><b>Total Commission: $'.number_format($commission, 2).'</b></td></tr>';
}else{
echo '<tr><td colspan="4" class="datum1">No recent activity.</td></tr>';
}
echo '</table>';
?>
<br><br>
<?php
//Fetch Orders
unset($user_orders);
$sql = "SELECT * FROM `zogo_orders` WHERE `user_id` = $userid ORDER BY `date` DESC";
$result = mysql_query($sql);
$i = 0;
while($records = @mysql_fetch_array($result)){
$user_orders["$i"] = $records;
$user_orders["$i"]['date'] = substr($records['date'], 0, 10);
$i++;
}
///////////////////////////////////
// Make Table
///////////////////////////////////
echo '<table border="0" width="95%" class="tdstyle1">';
echo '<tr><td class="datum1"><b>Reward:</b></td><td class="datum1"><b>Status:</b></td><td class="datum1"><b>Date:</b></td><td class="datum1"><b>Points:</b></td></tr>';
if(count($user_orders)){
$i = 0;
foreach ($user_orders as $key => $value ){
echo '<tr>';
echo '<td class="datum1">'.$user_orders[$key]['reward_name'].'</td>';
echo '<td class="datum1">'.$user_orders[$key]['status'].'</td>';
echo '<td class="datum1">'.$user_orders[$key]['date'].'</td>';
echo '<td class="datum1"><span class="clgreen"><b>'.$user_orders[$key]['zpoints'].'</b></span></td>';
echo '</tr>';
$i++;
}
}else{
echo '<tr><td colspan="4" class="datum1">No recent orders.</td></tr>';
}
echo '<form action="?page=useredit&uid='.$uid.'" method="post"><input type="submit" name="link" value="Edit"></form>';
echo '<br> <br>';
echo '</td></tr>';
echo '</table>';
?>
<br>
<?php
disconnect_mysql();
?>
The issue is at the very end. My form action to edit the info brings us to the right page but without the UID. Any suggestions?
Re: index
Posted: Sat Nov 15, 2008 3:37 pm
by MMalvin
Sorry for flooding this post. Found my mistake had to change 'uid' to 'userid' I just have to get this site done by tonight. Thanks for all the input
-Max
Re: index
Posted: Sat Nov 15, 2008 3:54 pm
by califdon
MMalvin wrote:Sorry for flooding this post. Found my mistake had to change 'uid' to 'userid' I just have to get this site done by tonight. Thanks for all the input
-Max
I'm glad you got it fixed. Would you please now do us a favor and return to your original post and EDIT the Subject line to include the word [SOLVED], so that others won't spend time trying to debug your code before they realize that you've already solved it? Thank you.