Default avatar pic always showing in Pal requests - php

im trying to develop a social networking application and im having some trouble showing a user's selected avatar. Every users can upload pictures and there is a field called avatar and when this is set to 1, it is the users avatar pic. Only one pic can be an avatar.
My PHP code:
<div class="interactContainers" id="pal_requests">
<?php
$pal_requests = "SELECT * FROM pal_requests WHERE mem2='$user_id' ORDER BY pal_request_id ASC LIMIT 50";
$pal_request_query = mysql_query($pal_requests) or die(mysql_error());
$pal_request_num_rows = mysql_num_rows($pal_request_query);
if($pal_request_num_rows < 1)
{
echo ' You have no Pal requests at this time.';
exit();
}
else
{
while($row = mysql_fetch_array($pal_request_query))
{
$request_id = $row["pal_request_id"];
$mem1 = $row["mem1"];
$query_user = "SELECT user_first_name, user_last_name, picture_thumb_url FROM users LEFT JOIN picture ON users.user_id = picture.user_id
AND picture.avatar=1 WHERE users.user_id='$mem1' LIMIT 1";
$user_info = mysql_query($query_user, $connections) or die(mysql_error());
}
if(!empty($row["picture_thumb_url"]))
{
$avatar = '<img src="/NNL/User_Images/$row["picture_thumb_url"]" width="50" height="50" border="0"/>';
}
else
{
$avatar = '<img src="/NNL/Style/Images/default_avatar.png" width="50" height="50" border="0"/>';
}
}
?>
<?php
while ($row = mysql_fetch_array($user_info)){ $requesterFirstName = $row["user_first_name"]; $requesterLastName = $row["user_last_name"]; }
{
$thumbnail_user = $row["picture_thumb_url"] != '' ? $row["picture_thumb_url"] : '../Style/Images/default_avatar.png';
echo '<hr />
<table width="100%" cellpadding="5">
<tr>
<td width="17%" align="left"><div style="overflow:hidden; height:50px;">'. $avatar .'</div></td>
<td width="83%"><a class="ordinary_text_12_blue "href="user_view.php?user_id2=' . $mem1 . '">'. $requesterFirstName .' '. $requesterLastName .'</a> wants to be your Pal<br /><br />
<span id="req' . $request_id . '">
<a class="ordinary_text_12" href="#" onclick="return false" onmousedown="javascript:acceptFriendRequest(' . $request_id . ');" >Accept</a>
OR
<a class="ordinary_text_12" href="#" onclick="return false" onmousedown="javascript:denyFriendRequest(' . $request_id . ');" >Deny</a>
</span></td>
</tr>
</table>';
}
?>
</div>
The default avatar is being called all the time even though a user has selected their own avatar. Can someone tel me what im doing wrong?

This Block of code should be inside the body of the second while loop. In first while loop the variable $row["picture_thumb_url"] is never set.
if(!empty($row["picture_thumb_url"]))
{
$avatar = '<img src="/NNL/User_Images/$row["picture_thumb_url"]" width="50" height="50" border="0"/>';
}
else
{
$avatar = '<img src="/NNL/Style/Images/default_avatar.png" width="50" height="50" border="0"/>';
}

Related

Printing Horizontal Tables Including Images Using PHP MySQL

I am trying to print out on my sites home page a horizontal table which includes a picture of a car and then below the make, model & price of the car.
Here's roughly what I have done:
<?php
$List = "";
$sql = mysql_query("SELECT * FROM Car ORDER BY listed DESC LIMIT 5");
$Count = mysql_num_rows($sql);
if ($Count > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$make = $row["make"];
$model = $row["model"];
$price = $row["price"];
$List .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" valign="top"><a href="/motors/cars.php?id=' . $id . '"><img style="border:#666 1px solid;"
src="/../../motors-' . $id . '.jpg" alt="' . $status . ' ' . $title . '" width="100" height="80" border="1" /></a></td>
</tr>
<tr>
<td width="80%" valign="top" align="left"><font face="Arial" color="#000080"><B>
' . $make . ' ' . $model . '</B></font><br />' . $price . '
view car details</align></td>
</tr>
</table>';
}
} else {
$List = "No cars at present";
}
mysql_close();
?>
Can anyone help me sort this code to print out horizontally? Many Thanks!
The src of the image is most likely wrong, /../../motors... is still /motors...
you can move the images into your webapps /motors/images folder and set src as /motors/images/motors...
The table you create must be nested in another table.
<table>
<tr>
<td>
<table of a car>
</td>
<td>
<table of a car>
</td>
<td>
<table of a car>
</td>
.... etc.
</tr>
</table>
It will make sense to emit a tr every few cars to wrap to a new line.
table of a car is the html you collect in $List.

Style with css in php

I'm new to this so please be gentle
I want to style for example $product_name, $author, $details.
I guess I could style the echos but in this case the only echo is
<?php
// Connect to the MySQL database
include "storescripts/connect_mysql.php";
// This block grabs the whole list for viewing
$dynamicList = "";
$sql = mysql_query("SELECT * FROM products ORDER BY id DESC");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$product_name = $row["product_name"];
$author = $row["author"];
$details = $row["details"];
$link = $row["link"];
$isbn = $row["isbn"];
$isbn13 = $row["isbn13"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<table width="580" border="0" cellspacing="0">
<tr>
<td width="120"><img src="/inventory_images/' . $id . '.jpg" width="120" height="184" border="0" /></td>
<td width="456"><p>' . $product_name . '<p><br />
<p>' . $author . '</span><br />
<p>' . $details . '<br />
visa </td>
</tr>
</table>';
}
} else {
$dynamicList = "Database empty.";
}
mysql_close();
?>
Have you tried adding some CSS classes to your table cells?
$dynamicList .= '
<table width="580" border="0" cellspacing="0">
<tr>
<td width="120"><img src="/inventory_images/' . $id . '.jpg" width="120" height="184" border="0" /></td>
<td width="456"><p class="product_name">' . $product_name . '<p><br />
<p class="author">' . $author . '</span><br />
<p class="detail">' . $details . '<br />
visa </td>
</tr>
</table>';
In the head add some styles:
<style>
.product_name{color:red;}
.author{color:green;}
.detail{color:blue;}
</style>
Why not just add CSS rules to your stylesheet?
table tr td p {
// some styles
}
You can add a class with styles to the <p> elements that contain each value
<td width="456"><p class="product-name">' . $product_name . '</p>...
PHP is only a preprocssor and coughs up the code as the page loads and before any of the css of HTML kicks in so you can style it as normal
You can use style="" and class="" parameters on your <p> paragraph tags as well on the table cells <td>. You can also try to add for example styled <span> or <div> tags to your variables I suppose.
For example:
$product_name = "<span class='yourstyleclass'>$row['product_name']</span>";

select all from database of the selected checkbox

The code given below which display all the products in the home page.. and each product has a checkbox.. I wanted to select the checkbox of few products, and if I click on submit, the next page doesn't view the selected checkbox results
$sql = mysql_query("SELECT * FROM products ORDER BY date_added DESC LIMIT 15");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
$colindex = 1;
$totcols = 3;
$rowclosed = false;
//$totrows=ceil($count/$totcols);
$dynamicList .= "<dl id='Searchresult'> <form action='selected.php' method='POST'> <table width=\"50%\" border=\"0\" cellspacing=\"0\" align=\"center\" cellpadding=\"3\">";
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
if ($colindex == 1) {
$dynamicList .= "<tr>";
$rowclosed = false;
}
$dynamicList .= '<td width="142" valign="top" align="center">
<div id="products">
<div class="product">
<img style=" 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="100" height="100" border="0" /><div class="pr-info"><h4>' . $product_name . '</h4>
<input type="checkbox" name="check[]" value="<?php .$id. ?>"/>
</div>
</div></td>';
}
}
The Code below is where i used to retrieve the data from database of selected checkbox
foreach ($_POST['check'] as $k => $check) {
$where[ ] = $k . " = '" . mysql_real_escape_string($check) . "'";
}
include "storescripts/connect_to_mysql.php";
$sql = mysql_query("Select * from products where " . implode(' AND ', $where)); // Connect to the MySQL database
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while ($row = mysql_fetch_array($sql)) {
$id = $row["id"];
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '<td width="142" valign="top" align="center">
<div id="products">
<div class="product">
<a href="printer.php?id=' . $id . '">
<img style=" 1px solid;" src="inventory_images/' . $id . '.jpg" alt="' . $product_name . '" width="200" height="200" border="0" />
</a>
<div class="pr-info"><h4>' . $product_name . '</h4><p>' . $details . ' </p>
<span class="pr-price"><span>Rs.</span><sup>' . $price . '</sup></span>
</div>
</div></td>';
}
} else {
echo "That item does not exist.";
exit( );
}
Try changing the beginning of your second code to this:
include "storescripts/connect_to_mysql.php";
$sql = mysql_query('SELECT * FROM products WHERE id IN ('.implode(', ', array_values($_POST['check'])).')');
// rest of your code, beginning at $productCount = ...
But, how it was said before, you should start using PDO!
I think you final query and code should look this way...please change your code with this...and post the results:
foreach($_POST['check'] as $k){
$where[]= $k;}
var_dump($where); //it show you something, show me the var_dump result ???
include "storescripts/connect_to_mysql.php";
$query = "Select * from products where id IN(".implode(",",$where).")";
echo $query; //this line too....show me the result
$sql = mysql_query($query);
// Connect to the MySQL database
$productCount = mysql_num_rows($sql);
//the rest of your code ;)
-----------------------EDITED--------------------------------
Your problem is in this line:
<input type="checkbox" name="check[]" value="<?php .$id. ?>"/>
That line is wrong, make this change and see how it's work:
<input type="checkbox" name="check[]" value="<?php echo $id;?>"/>
Saludos ;)

Add fields to event display form

I am using an open source calendar to display events, I am having a trouble to add extra fields to event display form. Could anyone please indicate where I need to add code so more fields can be displayed.
Please could anyone kindly help me.
Many Thanks.
Here is the code for displaying the events:
<?php
require("config.php");
require("./lang/lang." . LANGUAGE_CODE . ".php");
require("functions.php");
$auth = auth();
$id = $_GET['id'];
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$sql = "SELECT d, m, y FROM " . DB_TABLE_PREFIX . "mssgs WHERE id=" . $id;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$d = $row["d"];
$m = $row["m"];
$y = $row["y"];
$dateline = $lang['months'][$m-1] . " $d, $y";
$wday = date("w", mktime(0,0,0,$m,$d,$y));
writeHeader($m, $y, $dateline, $wday, $auth);
// display selected posting first
writePosting($id, $auth);
// give some space
echo '<img src="images/clear.gif" width="1" height="25" border="0"><br clear="all">';
// query for rest of this day's postings
$sql = "SELECT id, start_time FROM " . DB_TABLE_PREFIX . "mssgs ";
$sql .= "WHERE y = " . $y . " AND m = " . $m . " AND d = " . $d . " AND id != $id ";
$sql .= "ORDER BY start_time ASC";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result)) {
echo '<span class="display_header">' . $lang['otheritems'] . '</span>';
echo '<br clear="all"><img src="/images/clear.gif" width="1" height="3" border="0"><br clear="all">';
// display rest of this day's postings
while ($row = mysql_fetch_array($result)) {
writePosting($row[0], $auth);
echo '<img src="images/clear.gif" width="1" height="12" border="0"><br clear="all">';
}
}
echo "</body></html>";
function writeHeader($m, $y, $dateline, $wday, $auth)
{
global $lang;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>phpEventCalendar: Event Display</title>
<link rel="stylesheet" type="text/css" href="css/popwin.css">
<?php if ($auth) { ?>
<script language="JavaScript">
function deleteConfirm(eid) {
var msg = "<?php echo $lang['deleteconfirm'] ?>";
if (confirm(msg)) {
opener.location = "eventsubmit.php?flag=delete&id=" + eid + "&month=<?php echo $m ?>&year=<?php echo $y ?>";
window.setTimeout('window.close()', 1000);
} else {
return;
}
}
</script>
<?php } ?>
</head>
<body>
<!-- selected date -->
<table cellspadding="0" cellspacing="0" border="0" width="300" bgcolor="#CCFFCC">
<tr>
<td bgcolor="#CCFFCC"><span bgcolor="#CCFFCC" class="display_header"><?php echo $dateline ?></span></td>
<td bgcolor="#CCFFCC" align="right"><span class="display_header"><?php echo $lang['days'][$wday] ?></span></td>
</tr>
</table>
<img src="images/clear.gif" width="1" height="3" border="0"><br clear="all">
<?php
}
function writePosting($id, $auth)
{
global $lang;
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME) or die(mysql_error());
$sql = "SELECT y, m, d, title, text, start_time, end_time, ";
$sql .= DB_TABLE_PREFIX . "users.uid, fname, lname, ";
if (TIME_DISPLAY_FORMAT == "12hr") {
$sql .= "TIME_FORMAT(start_time, '%l:%i%p') AS stime, ";
$sql .= "TIME_FORMAT(end_time, '%l:%i%p') AS etime ";
} elseif (TIME_DISPLAY_FORMAT == "24hr") {
$sql .= "TIME_FORMAT(start_time, '%H:%i') AS stime, ";
$sql .= "TIME_FORMAT(end_time, '%H:%i') AS etime ";
} else {
echo "Bad time display format, check your configuration file.";
}
$sql .= "FROM " . DB_TABLE_PREFIX . "mssgs ";
$sql .= "LEFT JOIN " . DB_TABLE_PREFIX . "users ";
$sql .= "ON (" . DB_TABLE_PREFIX . "mssgs.uid = " . DB_TABLE_PREFIX . "users.uid) ";
$sql .= "WHERE id = " . $id;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$title = stripslashes($row["title"]);
$body = stripslashes(str_replace("\n", "<br />", $row["text"]));
$postedby = $lang['postedby'] . ": " . $row['fname'] . " " . $row['lname'];
if (!($row["start_time"] == "55:55:55" && $row["end_time"] == "55:55:55")) {
if ($row["start_time"] == "55:55:55")
$starttime = "- -";
else
$starttime = $row["stime"];
if ($row["end_time"] == "55:55:55")
$endtime = "- -";
else
$endtime = $row["etime"];
$timestr = "$starttime - $endtime";
} else {
$timestr = "";
}
if ($auth == 2 || ($auth != 0 && $_SESSION['authdata']['uid'] == $row['uid'])) {
$editstr = "<span class=\"display_edit\">";
$editstr .= "[edit] ";
$editstr .= "[delete] </span>";
} else {
$editstr = "";
}
?>
<table cellspacing="0" cellpadding="0" border="0" width="300" bgcolor="#CCFFCC">
<tr><td bgcolor="#000000">
<table cellspacing="1" cellpadding="1" border="0" width="100%">
<tr>
<td class="display_title_bg" bgcolor="#CCFFCC"><table bgcolor="#CCFFCC" cellspacing="0" cellpadding="0" border="0" width="100%"><tr>
<td bgcolor="#CCFFCC" width="100%"><span class="display_title"> <?php echo $title ?></span></td>
<td bgcolor="#CCFFCC"><img src="images/clear.gif" width="20" height="1" border="0"></td>
<td bgcolor="#CCFFCC" align="right" nowrap="yes"><span class="display_title"><?php echo $timestr ?> </span></td>
</tr></table></td>
</tr>
<tr bgcolor="#CCFFCC"><td class="display_txt_bg" bgcolor="#CCFFCC">
<table cellspacing="1" cellpadding="1" border="0" width="100%" bgcolor="#CCFFCC">
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"><span class="display_txt"><?php echo $body ?></span></td>
</tr>
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"align="right"><span class="display_user"><?php echo $postedby ?></td>
</tr>
<tr bgcolor="#CCFFCC">
<td align="right" bgcolor="#CCFFCC"><?php echo $editstr ?></td>
</tr>
</table>
</td></tr>
</table>
</td></tr></table>
<?php
}
?>
To the best of my understanding writePosting function does most of the job and you need to enhance it to display more info about current event.
I've added a new table row at the end of this code sample to illustrate the idea.
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"><span class="display_txt"><?php echo $body ?></span></td>
</tr>
<tr bgcolor="#CCFFCC">
<td bgcolor="#CCFFCC"align="right"><span class="display_user"><?php echo $postedby ?></td>
</tr>
<tr bgcolor="#CCFFCC">
<td align="right" bgcolor="#CCFFCC"><?php echo $editstr ?></td>
</tr>
<tr bgcolor="#CCFFCC">
<td align="right" bgcolor="#CCFFCC"><?php echo "some extra info" ?></td>
</tr>

member management by admin using php

Sorry for asking an implement my feature question type question last time. I am new to Stackoverflow.com and also to php that's why.
What I was trying to ask is:
I have made a admin account. Members have registration page so a member will register. When user registers in the database table I will have a field for which 0 value will be initialised which means he is not approved. In admin account I have code to get the list of members. The code is given below:
<h2><?php echo "User list"; ?></h2>
<table border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#f87820">
<td><img src="img/blank.gif" alt="" width="10" height="25"></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "first name"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "lastname name"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="150" height="6"><br><b><?php echo "member id"; ?></b></td>
<td class="tabhead"><img src="img/blank.gif" alt="" width="50" height="6"><br><b><?php echo "delete"; ?></b></td>
<td><img src="img/blank.gif" alt="" width="10" height="25"></td>
</tr>
<?php
}
$result=mysql_query("SELECT member_id,firstname,lastname,login FROM members ORDER BY firstname");
$i = 0;
while($row = mysql_fetch_array($result)) {
if ($i > 0) {
echo "<tr valign='bottom'>";
echo "<td bgcolor='#ffffff' height='1' style='background-image:url(img/strichel.gif)' colspan='6'></td>";
echo "</tr>";
}
echo "<tr valign='middle'>";
echo "<td class='tabval'><img src='img/blank.gif' alt='' width='10' height='20'></td>";
echo "<td class='tabval'><b>".$row['lastname']."</b></td>";
echo "<td class='tabval'>".$row['firstname']." </td>";
echo "<td class='tabval'>".$row['member_id']." </td>";
echo "<td class='tabval'><a onclick=\"return </span></a></td>";
echo "<td class='tabval'></td>";
echo "</tr>";
$i++;
}
?>
</table>
in this i wanna add tho more things in the table 1 to delete a member and 2 to have approved or denied option for that i made two functiom
below code is to delete
if($_REQUEST['action']=="del")
{
$memberId = mysql_real_Escape_string($_REQUEST['member_id']);
mysql_query("DELETE FROM members WHERE member_id=$memberId");
}
below one for approving members
But my problem is I don't know how to include a button or radio button in the table which can pass value delete or approve to these functions.
Please tell me how the syntax is to add this button so that for approving I can change the value 0 that I gave in the database to 1 so that member get approved.
Try this:
echo '<td><a href="http://yourwebsite/yourscriptname.php?action=del&member_id='
. htmlspecialchars($row['member_id']) . '">Delete</a>';
if ($row['approved'] == 0) {
echo ' <a href="http://yourwebsite/yourscriptname.php?action=approve&member_id='
. htmlspecialchars($row['member_id']) . '">Approve</a>';
}
echo '</td>';
And make sure ALL of your database values are being sent to the browser in htmlspecialchars().
On the flipside,
$member_id = 0;
if (isset($_GET['member_id'])) $member_id = intval($_GET['member_id']);
$action = '';
if (isset($_GET['action'])) $action = $_GET['action'];
$sql = '';
switch($action) {
case 'approve':
$sql = "UPDATE members SET approval = 1 WHERE member_id = $member_id";
break;
case 'delete':
$sql = "DELETE FROM member WHERE member_id = $member_id";
break;
}
if (!empty($sql) && !empty($member_id)) {
// execute the sql.
}
What I would do is to set up a form inside of the table.
?> <form name="deleteUser" id="deleteUser" method="post" action="">
<input type="hidden" name="member_id" id="member_id" value="<?php echo $row['member_id'] ?>
<input type="submit" name="action" id="action" value="del" />
</form><?php
I would insert that in between your <td> tag.
<td class='tabval'>INSERT HERE</td>";

Categories