Help! . . . Sorry about the not so great title. I have a recipe site where i want the user to be able to edit a recipe but only if they submitted it. I have added enough of the page's code below to give you an idea of the format and the link I want to show if the user is logged in and on a recipe page they submitted is in red print. As it currently is coded, it shows on all recipe pages when the user is signed in and that obviously isn't good.
NOTE: I know that the $row_recipe "user_id" from the recipe table and the $row_users "id" from the users table have to be the same and it needs to be an if statement so as not to show if the user is not logged in or if they are logged in but not on a recipe page that they submitted. I cannot figure out how to code it because I barely know php - and - is it even possible to accomplish given what we have to work with?
<?php
session_start();
$string = "ABCEFGHJKMNPRSTWYZ23456789"; // salt to select chars from
srand((double)microtime()*1000000); // start the random generator
$thecode=""; // set the inital variable
for ($i=0;$i<5;$i++){ // loop and create password
$thecode = $thecode . substr ($string, rand() % strlen($string), 1);
}
$_SESSION["verification_key"] = $thecode;
include("thumbnail.php");
include("include.php");
$sql = "SELECT * from ".TABLE_PREFIX."users where `id` ='".$_COOKIE["ses_id"]."'";
$res = mysql_query($sql);
///Get recipe details
$id = $_REQUEST["id"];
$res_recipe = mysql_query("select a.*, b.first_name, b.last_name, user_id, date_format(post_date, '".Get_Date_Format($date_format)."') as formatted_date from ".TABLE_PREFIX."recipes a left join ".TABLE_PREFIX."users b on a.user_id = b.id where a.id = '$id'");
if($row_recipe = mysql_fetch_array($res_recipe))
{
$vews = $row_recipe["views"];
$new_views = $vews+1;
$res_view = mysql_query("update ".TABLE_PREFIX."recipes set views = '$new_views' where id = '$id'");
if($row_recipe["picture"]!="")
if(file_exists("admin/uploads/".$row_recipe["picture"])){
{
if (makethumb($row_recipe["picture"], "admin/uploads", "150" , "L_", "admin/uploads") ){
$pathtopic2 = $NewThumbFileName;
}
else{
$pathtopic2 ="admin/uploads/".$row_recipe["picture"];
}
}
}
else{
$pathtopic2 = "";
}
}
$html_title = $row_recipe["html_title"];
if ($html_title ==""){
$html_title = $row_recipe["name"];
}
$html_keywords = $row_recipe["html_keywords"];
if ($html_keywords ==""){
$html_keywords = $row_recipe["name"];
}
$html_description = $row_recipe["html_description"];
if ($html_description ==""){
$html_description = $row_recipe["name"];
}
printheader(1,$html_title,$html_keywords,$html_description);
$res_df = mysql_query("select * from ".TABLE_PREFIX."settings");
if($row_df = mysql_fetch_array($res_df))
{
///Date Format
$date_format = $row_df["date_format"];
///User Comments - fSol add
$user_comments = $row_df["user_comments"];
///Guest Comments - fSol add
$guest_comments = $row_df["guest_comments"];
}
?>
<script language="JavaScript" src="genfns.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function Validation(input)
{
var requiredFields = new Array("post_name","post_email","comment","key");
var fieldNames = new Array("Name","Email","Comment","Varification Code");
var fieldCheck = true;
var fieldsNeeded = "\nA value must be entered in the following field(s):\n\n\t";
for(var fieldNum=0; fieldNum < requiredFields.length; fieldNum++) {
if ((input.elements[requiredFields[fieldNum]].value == "") ||
(input.elements[requiredFields[fieldNum]].value == " ")) {
fieldsNeeded += fieldNames[fieldNum] + "\n\t";
fieldCheck = false;
}
}
if (fieldCheck == true){
if (document.frmitem.post_email.value!=""){
if (!emailCheck(document.frmitem.post_email.value))
return false
else
return true
}
else{
return true;
}
}
else {
alert(fieldsNeeded);
return false;
}
}
function ViewPrint(id) {
newWindow = window.open('/print.php?id='+id, 'Print', 'width=600,height=500, scrollbars=yes');
newWindow.focus();
}
function ViewPhoto(id,imagewidth,imageheight) {
newWindow = window.open('/view_photo.php?id='+id, 'Details', 'width='+imagewidth+',height='+imageheight+', scrollbars=yes, resizable =1');
newWindow.focus();
}
</script>
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" class="text">
<tr>
<td align="right" height="0">
<?php
///Get messages
///comment posted
$rated = "";
$addtofav = "";
$sendfreind = "";
$comentpost = "";
$msg = "";
if(isset($_REQUEST["comentpost"]))
{
$comentpost = $_REQUEST["comentpost"];
}
///recipe rated
if(isset($_REQUEST["rated"]))
{
$rated = $_REQUEST["rated"];
}
///Added to favoutites
if(isset($_REQUEST["addtofav"]))
{
$addtofav = $_REQUEST["addtofav"];
}
///Send to friend
if(isset($_REQUEST["sendfreind"]))
{
$sendfreind = $_REQUEST["sendfreind"];
}
if($rated=="su"){
$msg ="Recipe rated";
}
if($comentpost=="su"){
$msg ="Comment Posted";
}
if($addtofav=="su"){
$msg ="Added to Favorites";
}
if($addtofav=="ae"){
$msg ="Already exists in Favorites";
}
if($sendfreind=="su"){
$msg ="Sent email to friend";
}
if (isset($_REQUEST["failed"])){
if ($_REQUEST["failed"] =="err_var"){
$msg ="Incorrect image verification code. Please try again";
}
}
if($msg !="")
{
?>
<span class="message"><?php echo $msg; ?></span>
<?php
}
?></td></tr>
<tr>
<td><h1><?php echo $row_recipe["name"];?></h1></td>
</tr>
<tr>
<td style="color:#FF5F0F;font-size:14px;font-weight:500;padding:0px 0px 10px 4px">
<?php
if ($row_recipe["first_name"] == ""){
?>
From the Kitchen of Admin
<?php
}
else{?>
From the Kitchen of <?php echo $row_recipe["first_name"]." ".$row_recipe["last_name"];?>
<?php
}?>
</td>
</tr>
<tr>
<td valign="top" style="width:100%;">
<table border="0" cellpadding="0" class="text" style="width:100%;">
<tr>
<td align="left" valign="top">
<?php
///If picture uploaded
if($row_recipe["picture"]!="")
{
if(file_exists("admin/uploads/".$row_recipe["picture"])){
$size = getimagesize("admin/uploads/".$row_recipe["picture"]);
$imgwidth = $size[0];
$imgheight = $size[1];
if ($imgwidth >600) {
$newimagewidth = 600;
}
else{
$newimagewidth = $imgwidth+40;
}
if ($imgheight >500) {
$newimgheight = 500;
}
else{
$newimgheight = $imgheight+80;
}
</td>
<td align="right" valign="top">
<table align="right" cellpadding="0" cellspacing="0" class="text" style="margin-right:20px;">
<?php
if(isset($_COOKIE["ses_code"])){
///If the user logged in
if($_COOKIE["ses_code"] == md5($_COOKIE["ses_username"].$_COOKIE["ses_id"]))
{
///If not added to favourites before
$res_fav = mysql_query("select * from ".TABLE_PREFIX."favourites where recipe_id ='$id' and user_id ='".$_COOKIE["ses_id"]."'");
if(mysql_num_rows($res_fav)==0)
{
?>
<tr><td align="right" valign="middle" style="background-color:#ffffff;"> <a href="<?php echo $url_script;?>add_to_fav.php?recipe_id=<?php echo $id;?>">Add to CookBook</a></td></tr>
<?php
}
}
}
?>
[COLOR="Red"]<?php
if(isset($_COOKIE["ses_code"])){
if($_COOKIE["ses_code"] == md5($_COOKIE["ses_username"].$_COOKIE["ses_id"])){
?>
<tr><td align="right" valign="middle" style="background-color:#ffffff;"><br /><a href="http://www.myrecipesite.com/edit_recipe.php?id=<?php echo $id;?>" title="edit recipe"></a></td></tr>
<?php
}
}else{
?>
<?php
}
?> [/COLOR]
Thanks up front for any help.