i have a profile page which uses php includes to get reviews.php and posts.php displayed on the page.
the page reviews.php has a form and i am trying to get this form to submit/use the action php server self but when i do this for some reason it ignores the mysql query on the page reviews.php and instead of inserting it into the table ptb_reviews it inserts it into ptb_posts. so the problem here is its carrying out the query on posts.php and i dont know why this is happening, can someone please help me?
here's the reviews.php page
<?php ob_start(); ?>
<?php
// check if the review form has been sent
if(isset($_POST['review_content']))
{
$content = $_POST['review_content'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
}
//We check if all the fields are filled
if($_POST['review_content']!='')
{
{
$sql = "INSERT INTO ptb_reviews (id, from_user_id, to_user_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
$_SESSION['message']="<div class=\"infobox-wallpost\"><strong>Thank You</strong> - Your review has been sent to the Escort and is awaiting approval.</div><div class=\"infobox-close4\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
} }
}
?>
<div class="reviewcontent">
<?php
$profile_bits = get_profile_bits();
while ($profile = mysql_fetch_array($profile_bits)) { ?>
<?php if ($user['account_type'] == "Escort"){
?>
<?php
$days = $reviews['date_added'];
function days_from_date2($days) {
$age = date_diff(date_create($days), date_create('now'))->d;
return $age;
}
?>
<div class="reviewcontent1">
<?php
$reviews_set = get_reviews();
?>
<br/>
<h3><span class="underline"><?php echo "".$profile['display_name'].""; ?>'s Latest Reviews</span></h3>
<br/>
<?php
if(mysql_num_rows($reviews_set) > 0) {
while ($reviews = mysql_fetch_array($reviews_set)) {
$age = days_from_date($reviews['date_added']);
?>
<div class="review_box" id="reviewcase">
<div class="review-content2">
<?php echo "{$reviews['content']}"; ?>
</div>
<div class="message_pic2">
<?php echo "<img width=\"50px\" height=\"50px\" src=\"data/photos/{$reviews['from_user_id']}/_default.jpg\">";?>
</div>
<div class="reviews_footer2">
<?php echo "Posted by {$reviews['display_name']}"; ?> <?
$datetime1 = new DateTime();
$datetime2 = new DateTime ($reviews['date_added']);
$interval = $datetime1->diff($datetime2);
$mdhms = explode('-',$interval->format('%m-%d-%H-%i-%s'));
$labels = Array(' months', ' days', ' hours', ' minutes', ' seconds');
$i = 0;
foreach($mdhms as $t){
if($t > 0) break;
$i+=1;
}
echo "about ".$t.$labels[$i]." ago"; ?>
</div>
</div>
<?
$account_type = account_type();
while ($acctype = mysql_fetch_array($account_type))
if ($acctype['account_type'] == 'Client') {
echo "
<div class=\"add_review_text\">add a review now</div>";
} ?>
<?
}
}else{
if (!logged_in()) {
echo "
<div class=\"review_box_example\"><div class=\"example_review_pic\"><img width=50px height= 50px src=\"data/photos/0/post.jpg\"/>
</div><div class=\"example_review_text2\">{$profile['display_name']}, you were fantastic!<br/>I can not wait to meet with you again, you were very professional and made me feel very comfortable.<br/><br/>John x</div><div class=\"example_review_pic2\"></div></div><div class=\"example_box_container2\"><div class=\"review_example_arrow2\"></div><div class=\"review_example_box2\"></div><div class=\"review_example_text2\"><strong>Here's an Example</strong></div></div>";
}else{
if (logged_in()) {
echo "
<div class=\"review_box_example\"><div class=\"example_review_pic\"><img width=50px height= 50px src=\"data/photos/0/post.jpg\"/>
</div><div class=\"example_review_text2\">{$profile['display_name']}, you were fantastic!<br/>I can not wait to meet with you again, you were very professional and made me feel very comfortable.<br/><br/>John x</div><div class=\"example_review_pic2\"></div></div><div class=\"example_box_container2\"><div class=\"review_example_arrow2\"></div><div class=\"review_example_box2\"></div><div class=\"review_example_text2\"><strong>Here's an Example</strong></div></div>"; ?>
<?
$account_type = account_type();
while ($acctype = mysql_fetch_array($account_type))
if ($acctype['account_type'] == 'Client') {
echo "
<div class=\"add_review_text\">add a review now</div>";
} ?>
<?
$account_type = account_type();
if ($acctype['account_type'] == 'Escort') {
echo "<div class=\"infobox-noreviews\"><i>{$profile['display_name']} doesn't currently have any posts on his wall.<br/>Why not post a comment to his wall now.</i></div>";
}
}
?>
<?
} }
?>
<?php
{?>
<? } } } ?>
</div>
</div>
<div class="reviewcontent2">
i love me
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<textarea name="review_content" id="review_content" maxlength="180" cols="33" rows="5" class="review_input_box2" style="resize: none;"></textarea>
<input name="add_review" type="image" src="http://www.playtimeboys.com/assets/img/icons/save-edit.png" BORDER="0" ALT="SUBMIT!"class="review_submit4" /></form>
</div>
<script>
$(".reviewcontent2").hide();
$('.add_review_text').click(function () {
if ($('.reviewcontent1').is(":visible")) {
$(".reviewcontent1").fadeOut(300);
$('.reviewcontent2').delay(400).fadeIn(300);
} else if ($('.reviewcontent2').is(":visible")) {
$('.reviewcontent2').fadeOut(300);
$('.reviewcontent1').delay(400).fadeIn(300);
}
});
</script>
<?php ob_end_flush() ?>
To submit a form to the current page, which is what it seems you are trying to do, just specify an empty action:
<form action="" method="post">
The form will now submit to the same URL as the current page is.
Related
I am learning PHP and am stuck right now. In a while loop, all the to-do items are displayed. Each of these elements has a delete button and a check button. The delete button works in every element, but the check button only works in the first one. The check button is to be used to check off an element. When the check button is pressed, an error message is displayed that this element could not be deleted. Only in the first element of course not. I can't find the error.
I suspect there is something wrong with the in the index
<?php
$todos = $conn->query("SELECT * FROM todos ORDER BY id DESC");
?>
<div class="show-todo-section">
<?php if($todos->rowCount() <= 0){ ?>
<div class="todo-item">
<div class="empty">
<img src="img/f.png" width="100%" />
<img src="img/Ellipsis.gif" width="80px">
</div>
</div>
<?php } ?>
<?php while($todo = $todos->fetch(PDO::FETCH_ASSOC)) { ?>
<div class="todo-item">
<form action="app/checked.php" method="POST">
<button class="check-box" value="<?php echo $todo['id']; ?>" name='checked' type="submit">Check</button>
</form>
<form action="app/delete.php" method="POST">
<button class="remove-to-do" value="<?php echo $todo['id']; ?>" name='delete' type="submit">x</button>
</from>
<?php if($todo['checked']){ ?>
<h2 class="checked"><?php echo $todo['title'] ?></h2>
<?php }else { ?>
<h2><?php echo $todo['title'] ?></h2>
<?php } ?>
<small>created: <?php echo $todo['date_time'] ?></small>
<?php for ($i = 1; $i <= $todo['coins']; $i++) {
echo "<img class='coins' src='img/coin.gif' width='40px' />";
} ?>
</div>
<?php } ?>
</div>
the checked.php
<?php
if (isset($_POST['checked'])) {
require '../db_conn.php';
$id = $_POST['checked'];
if(empty($id)){
header("Location: ../index.php?mess=errorChecked". $id);
}else{
$todos = $conn->prepare("SELECT id, checked FROM todos WHERE id=?");
$todos->execute([$id]);
$todo = $todos->fetch();
$uId = $todo['id'];
$checked = $todo['checked'];
$uChecked = $checked ? 0 : 1;
$res = $conn->query("UPDATE todos SET checked=$uChecked WHERE id=$uId");
header("Location: ../index.php?mess=successChecked");
$conn = null;
exit();
}
} else{
header("Location: ../index.php?mess=errorChecked");
}
I have a form that's supposed to enter a reply to a forum topic into the database and redirect the user back to the same topic. After much trial and error I have finally got the form to work, only it is putting two identical entries into the db every time. I cannot figure out why. I have looked up this same problem and most of the other people were not redirecting after the form submission or they were using AJAX or jquery or something. Here is my page info:
<?php
session_start();
include_once('includes/config.php');
include_once('classes/topic.php');
include_once('classes/post.php');
include('includes/header.php');
?>
<link rel="stylesheet" href="css/dd.css">
<?php
$topic = new Topic;
if (isset($_GET['id']))
{
$topic_id = $_GET['id'];
$data = $topic->fetch_data($topic_id);
if (isset($_POST['content']))
{
// someone posted a reply
$date = date('Y-m-d H:i:s');
$by = $_SESSION['user_id'];
$query = $pdo->prepare("INSERT INTO dd_posts (post_content, post_date, post_by, post_topic) VALUES (? ,? ,?, ?)");
$query->bindParam(1, $_POST['content']);
$query->bindParam(2, $date);
$query->bindParam(3, $by);
$query->bindParam(4, $_GET['id']);
$query->execute();
$result = $query->execute();
header("location:topic.php?id=".$_GET['id']);
exit;
}
?>
<div id ="wrapper">
<div class="drop-section">
<div id="menu">
<a class="item" href="drop_index.php">Dead Drop</a>
<a class="item" href="add_topic.php">New Post</a>
<a class="item" href="admin/add_cat.php">New Category</a>
<div id="userbar">
<?php
if( $user->is_logged_in() ) {
echo 'Hello ' . $_SESSION['user_name'] . '. How are you?';
} else {
echo '<a class="item" href="login.php">Sign in</a> or <a class="item" href="index.php">Create an account</a>';
}
?>
</div>
</div>
<table>
<tr class = "header-row">
<div id = "sans">
<?php echo $data['topic_subject']; ?>
- <small>started by <?php echo $data['user_name']; ?> </small><br />
<?php echo $data['topic_content']; ?>
</div>
</tr>
<?php
// retrieve all the replies to the original topic
$post = new Post;
$topic_id = $_GET['id'];
$posts = $post->fetch_all_posts_by_topic($topic_id);
?>
<tr>
<td class="first-column">
<?php foreach ($posts as $post) { ?>
<div class="drop-content-box">
<li><?php echo $post['post_content']; ?><br />
<div class = "forum-user-info">
<a href="player.php?id=<?php echo $post['user_id']; ?>">
<?php echo $post['user_name']; ?></a> - level:
<?php echo $post['user_level']; ?>
</div>
</li>
</div>
<?php } ?>
</td>
</tr>
</table>
<?php
if( $user->is_logged_in() )
{
?>
<div id = "header-section">Reply</div>
<?php if (isset($error)) { ?>
<small><?php echo $error; ?></small>
<?php } ?>
<form action="<?php echo "topic.php?id=".$_GET['id']?>" method="post" autocomplete="off">
<small><i>Do not post the actual answer to any level.</i></small><br />
<textarea rows="15" cols="50" name="content" placeholder="Give us your thoughts..."></textarea><br />
<input type="submit" value="Post" />
</form>
</div>
</div>
<?php
} else {
echo '<div id = "errors"><small>You must be signed in to reply.</div></small>';
}
}
include_once('includes/footer.php');
?>
You're executing the query twice.
$query->execute();
$result = $query->execute();
I am trying to apply delete function on selected record in my application. the problem is that the record are displayed in pagination ie 3,4 rows, i am able to delete record from the first page but when i move to the second page and select few records, the delete record buton doesn't work. any adivise will really help.
I am looking for replies
here is my code for listings
public function index($offset=0)
{
if ( $this->session->userdata('u_name') == FALSE )
{
$data['page_title']="Admin Login";
redirect('admin/login',"refresh",$data);
}
$this->load->model('candidate_model');
$limit=4;
$results=$this->candidate_model->get_all_Candidate($limit,$offset);
$data['candidates']=$results['rows'];
$offset = $this->uri->segment(3, 0);
$data['num_results']=$results['num_rows'];
$this->load->library('pagination');
$config=array();
$config['first_url'] = 'candidateList/index';
$config['base_url']=site_url('candidateList/index');
$config['total_rows']=$data['num_results'];
$config['per_page']=$limit;
$config['uri_segment']=3;
$config['first_link'] = '>';
$config['first_tag_open'] = '<div>';
$config['first_tag_close'] = '</div>';
$this->pagination->initialize($config);
$data['page_title']="Candidate List";
$this->load->view('manageCandidate',$data);
}
my code for delete function is bellow
if($this->input->post('Delete')=='Delete')
{
for($i=0;$i<count($_POST['checkbox']);$i++)
{
$candidate_id = $_POST['checkbox'][$i];
$this->candidate_model->deleteCandidate($candidate_id);
$this->session->set_flashdata('deleteSelected','Selected Candidate has been deleted.');
}
$data['page_title']="Candidate List";
redirect('candidateList',$data);
}
Delete function is here:
public function candidate()
{
if ( $this->session->userdata('u_name') == FALSE )
{
$data['page_title']="Admin Login";
redirect('admin/login',"refresh",$data);
}
$checkList=$this->input->post('checkbox');
$this->load->model('candidate_model');
if($checkList!=NULL)
{
if($this->input->post('Delete')=='Delete')
{
for($i=0;$i<count($_POST['checkbox']);$i++)
{
$candidate_id = $_POST['checkbox'][$i];
$this->candidate_model->deleteCandidate($candidate_id);
$this->session->set_flashdata('deleteSelected','Selected Candidate has been deleted.');
}
$data['page_title']="Candidate List";
redirect('candidateList',$data);
}
else if($this->input->post('Email')=='Email')
{
for($i=0;$i<count($_POST['checkbox']);$i++)
{
$admin_id = $_POST['checkbox'][$i];
$email_to[$i] = $_POST['checkbox'][$i];
$data['email_to'] = $email_to;
}
$data['page_title']='Send Mail';
$this->load->view('admin/sendmail4',$data);
}
}
else
{
$this->session->set_flashdata('deleteSelect','Please Select at-least one Candidate.');
$data['page_title']="Candidate List";
redirect('candidateList',$data);
}
}
ManageCandidate code:
<?php
$this->load->view('includes/template3');
?>
<?php
$this->load->view('includes/superAdminMenu');
?>
<div class="dashboard">
Add Candidate
<?php if($this->session->flashdata('deleteCandidate')) : ?>
<p class="successMsg"><?php echo $this->session->flashdata('deleteCandidate')?></p>
<?php endif; ?>
<?php if($this->session->flashdata('editCandidate')) : ?>
<p class="successMsg"><?php echo $this->session->flashdata('editCandidate')?></p>
<?php endif; ?>
<?php if($this->session->flashdata('deleteSelected')) : ?>
<p class="successMsg"><?php echo $this->session->flashdata('deleteSelected')?></p>
<?php endif; ?>
<?php if($this->session->flashdata('deleteSelect')) : ?>
<p class="noRows"><?php echo $this->session->flashdata('deleteSelect')?></p>
<?php endif; ?>
<?php if($this->session->flashdata('msgSent')) : ?>
<p class="successMsg"><?php echo $this->session->flashdata('msgSent')?></p>
<?php endif; ?>
<?php
if($num_results==0)
{ ?>
<p class="noRows"><?php echo "You have not added any Candidate.";?></p>
<?php }
else
if($num_results>0)
{ ?>
<form action="candidateList/candidate" method="post" name="sendMail" class="addformClass" id="candidateList1">
<!-- Script by hscripts.com -->
<!-- copyright of HIOX INDIA -->
<!-- Free javascripts # http://www.hscripts.com -->
<script type="text/javascript">
checked=false;
function checkedAll (candidateList1) {
var aa= document.getElementById('candidateList1');
if (checked == false)
{
checked = true
}
else
{
checked = false
}
for (var i =0; i < aa.elements.length; i++)
{
aa.elements[i].checked = checked;
}
}
</script>
<!-- Script by hscripts.com -->
<?php if(isset($candidates)) { ?>
<div class="candidateTable">
<div class="candidateRowHeading">
<div class="candidateHeadingChkBox">
<h4><input type='checkbox' name='checkall' onclick='checkedAll(candidateList1);'>
</h4>
</div><!--END candidateHeadingChkBox-->
<div class="candidateColHeading1">
<h4>Candidate Name</h4>
</div><!--END candidateColHeading1-->
<div class="candidateColHeading3">
<h4>Email</h4>
</div><!--END candidateColHeading3-->
<div class="candidateColHeading4" style="display:none">
<h4>Status</h4>
</div><!--END candidateColHeading4-->
<div class="candidateColHeading6">
<h4>Recruiter Assigned</h4>
</div><!--END candidateColHeading6-->
<div class="candidateColHeading5">
<h4>Action</h4>
</div><!--END candidateColHeading5-->
</div><!--END candidateRowHeading-->
<?php $count=0; ?>
<?php foreach ($candidates as $candidate) { ?>
<div class="candidateRowData">
<div class="candidateColChkBox">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $candidate->candidate_id; ?>">
</div><!--END candidateColChkBox-->
<div class="candidateColData1">
<?php echo anchor('admin/viewCandidate/'.$candidate->candidate_id, $candidate->first_name." ".$candidate->last_name); ?>
</div><!--END candidateColData1-->
<div class="candidateColData3">
<h4><?php echo $candidate->email; ?></h4>
</div><!--END candidateColData3-->
<div class="candidateColData4" style="display:none">
<h4><?php echo $candidate->lead_status; ?></h4>
</div><!--END candidateColData4-->
<div class="candidateColData6">
<h4>
<?php if($candidate->recruiter_id_fk!=0) { ?>
<?php echo get_recruiterFirstName($candidate->recruiter_id_fk); ?>
<?php echo get_recruiterLastName($candidate->recruiter_id_fk); ?>
<?php echo " (<strong>"; ?>
<?php echo get_recruiterLogin($candidate->recruiter_id_fk); ?>
<?php echo "</strong>) "; ?>
<?php }
else if($candidate->recruiter_id_fk==0) { ?>
<?php echo "Not Assigned"; ?>
<?php } ?>
</h4>
</div><!--END candidateColData6-->
<div class="candidateColData5">
<?php echo anchor('admin/editCandidate/'.$candidate->candidate_id,'Edit'); ?>
<?php echo anchor('admin/deleteCandidate/'.$candidate->candidate_id,'Delete'); ?>
</div><!--END candidateColData5-->
</div><!--END candidateRowData-->
<?php $count++; } ?>
</div><!--END candidateTableCom-->
<?php } ?>
<?php } ?>
<?php if(isset($candidates)) { ?>
<div id="pageNum">
<?php echo $this->pagination->create_links(); ?>
</div>
<?php } ?>
<?php
if($num_results>0) {
echo '<input type="submit" name="Delete" class="emailAllBtn" value="Delete" />';
echo '<input type="submit" name="Email" class="emailAllBtn" value="Email" />';
echo "</form>";
} ?>
</div>
<?php
$this->load->view('includes/footer2');
?>
<?php
function get_recruiterFirstName($id)
{
$CI =& get_instance();
$mod = $CI->load->model('recruiter_model');
$count = $CI->recruiter_model->get_recruiterFirstName($id);
return $count;
}
?>
<?php
function get_recruiterLastName($id)
{
$CI =& get_instance();
$mod = $CI->load->model('recruiter_model');
$count = $CI->recruiter_model->get_recruiterLastName($id);
return $count;
}
?>
<?php
function get_recruiterLogin($id)
{
$CI =& get_instance();
$mod = $CI->load->model('recruiter_model');
$count = $CI->recruiter_model->get_recruiterLogin($id);
return $count;
}
?>
Small mistake exist in your pagination code offset value correct it
public function index($offset=0)
{
if ( $this->session->userdata('u_name') == FALSE )
{
$data['page_title']="Admin Login";
redirect('admin/login',"refresh",$data);
}
$this->load->model('candidate_model');
$limit=4;
//whenever you are calling this pagination offset value you need to fetch it from URL
$offset_url = $offset = $this->uri->segment(3, 0);
//if it's not exist take the default value
$offset = is_numeric($offset_url)?$offset_url:$offset;
$results=$this->candidate_model->get_all_Candidate($limit,$offset);
$data['candidates']=$results['rows'];
..............
}
at the moment i have a script that gets the users reviews. if there arn't any reviews for that user and users are not logged in then it will echo out this:
<?
}
}else{
if (!logged_in()) {
echo "<div class=\"infobox-noreviews\"><i>{$profile['display_name']
}
doesn't currently have any reviews.<br/>To post a review to his wall,
Login
now.
</i></div>
<div class=\"example_review\"><div class=\"example_review_pic\">
<img width=50px height= 50px src=\"data/photos/0/review.jpg\"/>
</div>
<div class=\"example_review_text\">e.g. I had an amazing time. Defo going to be meeting again.
<br/><br/>Thanks Larry x</div><div class=\"example_review_pic2\">
</div></div>
<div class=\"example_box_container\"><div class=\"review_example_arrow\"></div>
<div class=\"review_example_box\"></div><div class=\"review_example_text\"> <strong>Here's an Example</strong>
</div></div>";
}
$account_type = account_type();
if ($acctype['account_type'] == 'member') {
echo "<div class=\"infobox-noreviews\"><i>{$profile['display_name']
}
doesn't currently have any reviews.<br/>Why not post a review to his wall now.</i> </div>";
}
$account_type = account_type();
if ($acctype['account_type'] == 'user') {
echo "<div class=\"infobox-noreviews\"><i>{$profile['displays_name']
}
doesn't currently have any reviews.<br/>Sorry but users cannot post Reviews.</i> </div>";
}
}
?>
otherwise the users reviews are listed to both logged in and logged out users.
however i also want to make it so that if the user is logged in and there are no reviews then it will also echo out the above script. i have tried to do this and cant figure out how to do it.
Please can someone help me and show me what i can do. thanks heres my script:
<div class="reviewcontent">
<?php if ($user['account_type'] == "user"){
?>
<?php
$days = $reviews['date_added'];
function days_from_date($days) {
$age = date_diff(date_create($days), date_create('now'))->d;
return $age;
}
?>
<div class="reviewcontent1">
<?php
$reviews_set = get_reviews();
?>
<br/>
<h3>Latest Reviews</h3>
<br/>
<?php
if(mysql_num_rows($reviews_set) > 0) {
while ($reviews = mysql_fetch_array($reviews_set)) {
$age = days_from_date($reviews['date_added']);
?>
<div class="reviewcase" id="reviewcase">
<div class="review-content">
<?php echo "{$reviews['content']}"; ?>
</div>
<div class="message_pic">
<?php echo "<img width=\"50px\" height=\"50px\" src=\"{$prof_photo}\">";?>
</div>
<div class="reviews_footer">
<?php echo "Posted by {$reviews['display_name']}"; ?> <?
$datetime1 = new DateTime();
$datetime2 = new DateTime ($reviews['date_added']);
$interval = $datetime1->diff($datetime2);
$mdhms = explode('-',$interval->format('%m-%d-%H-%i-%s'));
$labels = Array(' months', ' days', ' hours', ' minutes', ' seconds');
$i = 0;
foreach($mdhms as $t){
if($t > 0) break;
$i+=1;
}
echo "about ".$t.$labels[$i]." ago"; ?>
</div>
</div>
<?
}
}else{
if (!logged_in()) {
echo "<div class=\"infobox-noreviews\"><i>{$profile['display_name']} doesn't currently have any reviews.<br/>To post a review to his wall, Login now.</i></div>
<div class=\"example_review\"><div class=\"example_review_pic\"><img width=50px height= 50px src=\"data/photos/0/review.jpg\"/>
</div><div class=\"example_review_text\">e.g. I had an amazing time. Defo going to be meeting again.<br/><br/>Thanks Larry x</div><div class=\"example_review_pic2\"></div></div><div class=\"example_box_container\"><div class=\"review_example_arrow\"></div><div class=\"review_example_box\"></div><div class=\"review_example_text\"><strong>Here's an Example</strong></div></div>";
}
$account_type = account_type();
if ($acctype['account_type'] == 'member') {
echo "<div class=\"infobox-noreviews\"><i>{$profile['display_name']} doesn't currently have any reviews.<br/>Why not post a review to his wall now.</i></div>";
}
$account_type = account_type();
if ($acctype['account_type'] == 'user') {
echo "<div class=\"infobox-noreviews\"><i>{$profile['displays_name']} doesn't currently have any reviews.<br/>Sorry but users cannot post Reviews.</i></div>";
}
}
?>
<?
}
?>
<?php
{?>
<?php
if (logged_in() != '') {
$account_type = account_type();
while ($acctype = mysql_fetch_array($account_type))
if ($acctype['account_type'] == 'member') {
?>
<?php
// check if the review form has been sent
if(isset($_POST['review_content']))
{
$content = $_POST['review_content'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
}
//We check if all the fields are filled
if($_POST['review_content']!='')
{
{
$sql = "INSERT INTO ptb_reviews (id, from_user_id, to_user_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
echo "<div class=\"infobox-profile4\"><strong>Thank You</strong> - Your review has been sent for approval.</div>";
} }
}
?>
<?php if(isset ($_SESSION['user_id'])) { ?>
<div class="review-input-case">
<div class="reviewcase" id="reviewcase">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">Review user:<br /><textarea name="review_content" rows="4" maxlength="120" class="review_input_box" style="resize: none;"></textarea><input name="add_review" type="submit" class="review_submit"value="Add Review" /></form>
</div>
</div>
<?php } } } ?>
<?php
if (logged_in() != '') {
$account_type = account_type();
while ($acctype = mysql_fetch_array($account_type))
if ($acctype['account_type'] == 'user') { ?>
<?php
// check if the review form has been sent
if(isset($_POST['review_content']))
{
$content = $_POST['review_content'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
}
//We check if all the fields are filled
if($_POST['review_content']!='')
{
{
$sql = "INSERT INTO ptb_reviews (id, from_user_id, to_user_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
echo "<div class=\"infobox-profile4\"><strong>Thank You</strong> - Your review has been sent for approval.</div>";
} }
}
?>
<?php if(isset ($_SESSION['user_id'])) { ?>
<div class="review-input-case">
<div class="reviewcase" id="reviewcase">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">Review user:<br /><textarea name="review_content" rows="4" class="review_input_box" style="resize: none;" disabled="yes" placeholder="user Profiles Cannot Leave Reviews."></textarea><input name="add_review" type="submit" class="review_submit" value="Add Review" disabled="yes"/></form>
</div>
</div>
<?php } } } ?>
<?php
if (!logged_in()) { ?>
<div class="review-input-case">
<div class="reviewcase" id="reviewcase">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">Review user:<br /><textarea name="review_content" rows="4" class="review_input_box" style="resize: none;" disabled="yes" placeholder="You must be logged in to leave this user a Review."></textarea><input name="add_review" class="review_submit" type="submit" value="Add Review" disabled="yes"/></form>
</div></div>
<? } }?>
</div>
</div>
$query = mysql_query("SELECT reviews FROM users WHERE userid=$id");
if(mysql_num_rows($query)<1)
{
include('the file with first code');
// or
// echo 'the first code';
}
else
{
}
Hi i'm having a problem with my forum comment form. Basically i am trying to allow a user to read a users post and comment on it, the form data is suppose to be inserted into mysql.
the values i need inserted are the comment_id which is the session id of the user and the post_id the id of the post their commenting on and the content which they type.
For some reason this is not being inserted into mysql and is coming up with my echoed success message without any errors. can someone please show me where im going wrong.
Thanks
<?php
$page_title = "Read Post";
include('includes/header.php');
include ('includes/mod_login/login_form2.php'); ?>
<?php
confirm_logged_in();
if (isset ($_GET['post'])) {
$forum_id = $_GET['post'];
}
?>
<?php include('includes/copyrightbar.php'); ?>
<?
$read_forum_set = read_forum_set();
while ($forum = mysql_fetch_array($read_forum_set)) {?>
<div class="modtitle">
<div class="modtitle-text"><?php echo "{$forum['display_name']}"; ?>'s Forum Post</div>
<? } ?>
</div>
<div class="modcontent57">
<br /><br /><br/><br/>
<div class="forum">
<div class="forum-pic"><?php echo "<img src=\"data/photos/{$_SESSION['user_id']}/_default.jpg\" width=\"100\" height=\"100\" border=\"0\" align=\"right\" class=\"img-with-border-forum\" />";?>
</div>
<div class="message-links">
<strong><< Back to Forum
</div>
<br /><br /><br/><br/>
<?php
$datesent1 = $forum['date_sent']; ?>
<?php
$read_forum_set = read_forum_set();
while ($forum = mysql_fetch_array($read_forum_set)) {
$prof_photo = "data/photos/{$forum['user_id']}/_default.jpg";
$result = mysql_query("UPDATE ptb_forum SET ptb_forum.read_forum='1' WHERE ptb_forum.id='$forum'")
or die(mysql_error());
?>
<div class="message-date">
<?php echo "".date('D M jS, Y - g:ia', strtotime($forum['date_sent'])).""; ?></div>
<div class="img-with-border-frm-read"><?php echo "<img width=\"60px\" height=\"60px\" src=\"{$prof_photo}\"><br />"; ?></div>
<?php echo "<div class=\"forum-content2\"><div class=\"forum_subject\"><strong>Subject:</strong></div><div class=\"forum_subject2\"><i>{$forum['title']}</i></div><div class=\"forum_body\"><strong>Post:<br/></strong></br ><i>{$forum['content']}</i></div></div>";?>
<?php
// check if the review form has been sent
if(isset($_POST['forum_comment']))
{
$content = $_POST['forum_comment'];
//We remove slashes depending on the configuration
if(get_magic_quotes_gpc())
{
$content = stripslashes($content);
}
//We check if all the fields are filled
if($_POST['forum_comment']!='')
{
{
$sql = "INSERT INTO ptb_forum_comments (comment_id, post_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
mysql_query($sql, $connection);
echo "<div class=\"infobox-profile4\"><strong>Thank You</strong> - Your review has been sent for approval.</div>";
} }
}
?>
<?php if(isset ($_SESSION['user_id'])) { ?>
<div class="forum-comment-box">
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<textarea name="forum_comment" id="forum_comment" style="resize:none; height:100px; width:543px;"></textarea><input type="submit" name="send_button" id="send_button" style="float:right; margin-right:30px; text-align:center;" value="Reply to {$message['display_name']}" /></form></div>
<? } } ?>
</div>
</div>
<?php include('includes/footer.php'); ?>
</div>
You have some missing table names here:
$sql = "INSERT INTO ptb_forum_comments (comment_id, post_id, content) VALUES (NULL, '".$_SESSION['user_id']."', '".$profile_id."', '".$content."');";
as you can see you have 3 tables names and 4 values.