Jump to content

Recommended Posts

    I am working on making a standalone script for comments I can include into my main page. The script I worked with is PHP Auto Members. I can pull details out of the DB by using an array that is below. But I cannot get this to input any information into my database nor display the information I put into the database. It does connect to the database though, through using the functions.php file.

 

Names from PHP automembers come out of this script

 

<?php echo $member_details_array['name']; ?>

 

Other items in the array are below:

 

id

name

companyname

email

address

county

postcode

tel

fax

heardaboutusfrom

their_username

their_password

comments

activated

activated_date

duration

expire_date

 

  For my comment script I have a table called cmt with sublevels of "post_id" , "post_dt", and "post_dtl"

 

"post_dtl" is the variable and db table for the context.

"post_id” is the variable and db table for the post id I can use to index them better.

“post_dt” is the variable and db table for the date/time.

 

Here are my scripts below: There are 4 files.

 

 

Comment.php

 

<?php 

include_once("../functions.php");
include_once("../".$installed_config_file);
include_once("constants.inc.php");

if(!session_id()) session_start();

if (isset($_SESSION['md5_pass'])) 
{
   pama_authenticate($_SESSION['username'],$_SESSION['md5_pass'],"members",0);
   include ("comment.html");
}
else
{
   ?>
   <a href="#">Please Login to Post a Comment</a>
      <?php
}
?>

<?php include 'cmt-display.php' ?>

 

 

Comment.html

 

 <form action="cmt-form.php" id="comment" method="post" enctype="multipart/form-data" name="commPost" target="_self"> 
   <input type="hidden" name="todo" value="post_comment">
    <textarea name="post_dtl" cols="45" onclick="this.value=''" rows="8" value="post_comment">Enter Comment Here</textarea>
    <input name="submit" type="submit" value="Submit" onclick="document.location = 'comment.php'"/>
</form>

 

 

 

cmt-form.php

 

 <?php
include_once("../functions.php");
include_once("../".$installed_config_file);
include_once("constants.inc.php");


$dtl = $_POST[post_dtl]; 

$query="INSERT INTO cmt (post_dtl) VALUES ('null', '".$dtl."')";

mysql_query($query) or die ('Error posting comment')

?>

 

 

cmt-display.php

 

 <?php

echo $member_details_array['email']; 

$dtl = mysql_query("SELECT post_dtl, * FROM cmt");

  echo $dtl

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/182177-comments-integration-into-member-script/
Share on other sites

It may be inserting you are just not pulling the right display data:

 

<?php

echo $member_details_array['email']; 

$dtl = mysql_query("SELECT post_dtl, * FROM cmt");
while ($row = mysql_fetch_assoc($dtl)) {
    foreach ($row as $r) {
        echo $r . "<br />";
   }
   echo "<br />";
}
?>

 

The above code is dependent on the MySQL connection being connected.

 

EDIT:

One other issue I noticed was here:

 

<?php
include_once("../functions.php");
include_once("../".$installed_config_file);
include_once("constants.inc.php");


$dtl = $_POST[post_dtl]; 

$query="INSERT INTO cmt (post_dtl) VALUES ('null', '".$dtl."')";

mysql_query($query) or die ('Error posting comment')

 

On your insert you only have 1 column defined but 2 values being inserted... I think you only need one (as I take it the first one is for the auto_increment id that is not necessary).

 

<?php
include_once("../functions.php");
include_once("../".$installed_config_file);
include_once("constants.inc.php");


$dtl = $_POST['post_dtl']; // also it is good practice to enclose associative array indexes in quotes to avoid notice errors.

$query="INSERT INTO cmt (post_dtl) VALUES ('".$dtl."')";

mysql_query($query) or die ('Error posting comment')

I got some of this done, now I can see the name of the users but the form will not post the information into it. I don't get the connect to mysql error, just the error posting comment, so the query isnt written right. What im trying to do is add the user name and details into the comment table. Here are the changes I made.

 

<?php
include_once("../functions.php");
include_once("../".$installed_config_file);
include_once("constants.inc.php");

$dbhost = 'localhost';
$dbuser = 'u7200607_1733';
$dbpass = 'japple12';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = 'u7200607_1733';
mysql_select_db($dbname);

$name =$member_details_array['email'];

$dtl = $_POST['post_dtl']; // also it is good practice to enclose associative array indexes in quotes to avoid notice errors.

$query="INSERT INTO cmt (post_dtl, ) VALUES ('.$dtl', '.$name')";

mysql_query($query) or die ('Error posting comment')


?>



 

 

Here is my

 

Basically I want it to display like:

 

Justin posted on xx-xx-xxxx at xx:xx

This is my comment.....

 

 

 

 

$dtl = mysql_query("SELECT post_dtl, * FROM cmt");

makes no sense

$dtl = mysql_query("SELECT * FROM cmt");

makes sense if u want to select all columns or even

$dtl = mysql_query("SELECT post_dtl FROM cmt");

makes sense if u want to select that one column only.

but i dont think that makes sense (the first one)

I am a novice lol. I will change that, I understand what you're saying. I want every column to show. But I cannot figure out why it won't insert.. is there anything wrong with my query? It does seem to be entering the query somewhat, because my default text in the comment box says "Enter Comment Here" now I need to tweak it to show right.

 

Now when I changed that part, it queries fine to get the details out. I have to take the post_id column out though.

 

3

 

84

ns

 

4

 

Enter Comment Here

ns

 

5

 

Enter Comment Here

ns

 

first of all, the textarea shouldnt equal nothing everytime u click it. that would be horrible.(javascript onclick event u have)

from comment form:

$date = date("insert the date format here");
$query="INSERT INTO cmt (post_dtl, yourusernamecolumn, datecolumnname) VALUES ('$dtl', '$_SESSION[username]', '$date')";

i dont know what the null would do... makes no sense. you need to also insert the username of the poster and the date and time. into the database with that statement.

to  do the date u can either make two columns in your database table, one for date(monthyear and day) and one for time OR you can make one called date and format the date() function to be month year and day with the word "at" included and then the time

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.