I am creating a client account management area on my site (check balance, pay your bill, print/save our contract, check progress, upload files/content, write messages to one another.. I have just about everything going smoothly (thanks entirely to a lot of info and help here @ DaniWeb)..

One issue I am having is the notes board - I can write a message and submit: posts fine (actually, posts the same message twice)... THEN... if I click refresh - it will post a "blank" message (inserts a line w/horizontal rule, essentially - posting a blank message with time stamp.. ) The goal of the noteboard is to allow communication between myself and client - quick notes about progress/design.

It is actually not just posting a BLANK message... for example: I just typed in "1" and pressed submit... "1" came up TWICE (and the message box was cleared to make room naturally for another message, since this would be a "new session"). THEN - with the BLANK box, I press submit - and once again, two more lines with the "1" message... even though the box was empty?

Pardon my ignorance, only been dealing with PHP for... 24 hours?


Posted by client1 on 2011-03-18
-------
Posted by client1 on 2011-03-18
-------
Posted by client1 on 2011-03-18

1
-------
Posted by client1 on 2011-03-18

1
-------
Posted by client1 on 2011-03-18

1
-------
Posted by client1 on 2011-03-18

1
-------

==========================

Here is my NOTEBOARD.PHP code:

<?php

session_start();

if(!isset($_SESSION['username'])){
    header( 'Location: loginform.html' );
}

require('db.php');

$client_ID = mysql_query("SELECT client_ID
	FROM clients WHERE username='".$_SESSION['username']."'")or die(mysql_error());
$client_ID = mysql_fetch_array($client_ID);
$client_ID = $client_ID['client_ID'];

mysql_query("
	INSERT INTO noteboard(client_ID, date, message)
	VALUES('$client_ID', CURDATE(), '$_POST[message]')
	");
	
if(!empty($_POST[message]))

mysql_query("
INSERT INTO noteboard(client_ID, date, message)
VALUES('$client_ID', CURDATE(), '$_POST[message]')
");

#

// Displays all current notes
$getNotes = mysql_query("SELECT * FROM noteboard WHERE client_ID='".$client_ID."' ORDER BY date");

while($row = mysql_fetch_array($getNotes, MYSQL_ASSOC)){
    echo "Posted by " . $_SESSION['username'] . " on " . $row['date'] . "<br /><p>"
	. $row['message'] . "</p><hr />";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Your Portfolio - Client Area - Note Board</title>
</head>
<body>

<form action="noteboard.php" method="post">
<h3>Message:</h3><br />
<textarea name="message" cols="30" rows="10"></textarea><br />
<input type="submit" value="Submit" />

</body>
</html>
Member Avatar for TechySafi

Hey again?? :P anyway I guess I can help you ;)

Everything is okay till line 15, no change. But after that put somthing like this

$msgfinal=$_POST['message'];
if(isset($_POST=['Submit']))// now it wont let that page to execute the query until you pressed on submit button 
{
//button is pressed now so let's check if its a re-post
include("db.php");
$re1 = mysql_query("select * from  noteboard");
while($myrow = mysql_fetch_row($re1))
{
$msg_on_db=$myrow[2];
}
if($msgfinal==$msg_on_db) //if there is a match
{
echo "Opps! No repost!!";
}
else
{
//Here goes your final execution....i mean make your query here to insert datas
}
}

LOL im trying!! Getting a syntax error with:

if(isset($_POST=['submit']))

This is such a different world.. frustrates me since I could probably troubleshoot but I don't even know what the codes are (yet). Trying to read the codes, learn what they mean/do and hope I can one day know what the hell I am doing (hate using tutorials to learn but what choice do I have? I am really not a tutorial kind of learner.. like to just test and do - so this is making me nuts...!!)

I got rid of the syntax error (removed $$$ --> if(isset($_POST)) //

NOW the messages aren't posting at all tho... not on my MySQL back end or on the noteboard page. I want the messages typed b/w myself and client to display ON the page along with the message box.. hmmmm!! I'll keep trying to figure it out but I feel like my troubleshooting skills lead to a bigger mess LOL

Member Avatar for TechySafi
<?php
 
session_start();
 
if(!isset($_SESSION['username'])){
    header( 'Location: loginform.html' );
}
 
require('db.php');
 
$client_ID = mysql_query("SELECT client_ID
	FROM clients WHERE username='".$_SESSION['username']."'")or die(mysql_error());
$client_ID = mysql_fetch_array($client_ID);
$client_ID = $client_ID['client_ID'];
if(isset($_POST['Submit']))
{
	$post=$_POST['message'];
	$sql="select * from noteboard where message='$post'";
  $excute=mysql_query($sql);
  $ne= mysql_num_rows($excute);
	
if($_POST['message']==""))
{
	echo "Opps! Blank post";
}
elseif($ne==1)
{
	echo "Re-post";
}
else
{
mysql_query("INSERT INTO noteboard(client_ID, date, message)
VALUES('$client_ID', CURDATE(), '$_POST[message]')
");
}
}
#
 
// Displays all current notes
$getNotes = mysql_query("SELECT * FROM noteboard WHERE client_ID='".$client_ID."' ORDER BY date");
 
while($row = mysql_fetch_array($getNotes, MYSQL_ASSOC)){
    echo "Posted by " . $_SESSION['username'] . " on " . $row['date'] . "<br /><p>"
	. $row['message'] . "</p><hr />";
}
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Your Portfolio - Client Area - Note Board</title>
</head>
<body>
 
<form action="note.php" method="post"> //change form action, replace note.php with the page name you put these all codes.
<h3>Message:</h3><br />
<textarea name="message" cols="30" rows="10"></textarea><br />
<input type="submit" name="Submit" value="Submit" />
 
</body>
</html>

Changed many things, be careful with database,table names etc. If this still doesn't help then I can't do any better without seeing whats going on and to see whats going on I need your clients & noteboard table :)

Anyway let me know what happens

Thanks! I'll try it out now and let you know. Seriously appreciate your help a LOT... I'm probably going to go backwards and learn code names/behaviors/rules AFTER I get this project working. I thought I could teach myself like I did HTML/CSS (hands-on) but I think I need a mixture of a terms "guide" and hands-on... I can see PHP is an entirely different world..

Member Avatar for TechySafi

Don't give up...keep experimenting !
And take a look at http://www.w3schools.com/php/ It won't take too long to understand ABCDEF...even JKL of php :P

This is so frustrating! Argh! Hope I don't screw it all up when I start designing the pages around the PHP coding LOL... Gotta take my son out for a bit to the park plus I think I do better when I step away for an hour!!! I hope these codes make sense.. I check the boards from my phone so let me know if these codes are missing something else that you need for them to make sense!! THANK YOU!!!! :)
Ok -


NOTEBOARD.PHP (as you just posted) -- giving errors on 22, 26, 27, and 30. --- The codes I have been posting are the noteboard.

OTHER CODES...

DP.PHP (my basic database file....)---->

<?php
 
// Replace these parameters with your own database information.
// I'm running on my own server, so my username is automatically
// root and I have no password. This will be different on a server.
$conn = mysql_connect("database-hostaddress","username","password4");
 
// mysql_select_db is a predefined function in MySQL
// It let's us call the database, so we can save it
// in our variable $db
$db = mysql_select_db("databasename",$conn);

=======================================================

PROFILE.PJP (basically... the redirect page from logging in - will eventually house the "pay bill", "upload content files", etc... the 'main page' for clients login---->

<?php

// We have to start our session every time we're
// going to call our session variable for a
// logged in issue.
session_start();

// Let's also make sure the user is logged in at all
// If the PHP $_SESSION[] array is not (!) set
if(!isset($_SESSION['username'])){
    //Then redirect them to the login page
    header( 'Location: login.html' );
}

echo "<h1>Profile Page</h1>";

echo "<p>Welcome, " . $_SESSION['username'] . "!
          This is your profile page. You can view and edit your information, or navigate to any of the other options. Please check back regularly to check the progress of your project(s), submit payment information, print/save a copy of our project contract, or upload your website content.</p>";

echo "Your email address: " . $_SESSION['email'] .  "<br />" .
        "Your PayPal address: " . $_SESSION['paypal'];

echo "<p><a href='documents.php'>Documents</a></p><p><a href='noteboard.php'>Client Noteboard</a></p><p><a href='logout.php'>Logout</a></p>";

==============================

DOCUMENTS.PHP: This page has nothing to do with the NOTEBOARD.PHP - but, mentioning so you can see what a mess I am (working with) LOL... This is where files can be uploaded and my next step is going to be to include a text editor so clients can type/paste/copy/write their content that I need to place on each page (that will be another project disaster probably).. I THINK this page is working semi-well... I tested it briefly and made a few quirks (it was allowing ALL clients to see one anothers uploads but I think I fixed it... Will do more testing later on. ---->

<?php

session_start();

if(!isset($_SESSION['username'])){
    header( 'Location: login.html' );
}

require('db.php'); // Connect to the database since we'll be needing it later.

// Where the file is going to be placed
$target_path = "uploads/";

$client_ID = mysql_query("SELECT 'client_ID'
				   FROM 'clients'
				    WHERE username='".$_SESSION['username']."'");

if(!empty($_FILES)){
	// Add the original filename to our target path.
	// Result is "uploads/filename.extension"
	$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

	if((!$_FILES["uploadedfile"]["type"] == "image/gif")
	  ||(!$_FILES["uploadedfile"]["type"] == "image/png")
	  ||(!$_FILES["uploadedfile"]["type"] == "image/jpeg") // "jpeg" for Firefox
	  ||(!$_FILES["uploadedfile"]["type"] == "image/jpeg") // "jpeg" for IE
	  ||(!$_FILES["uploadedfile"]["type"] == "text/css")
	  ||(!$_FILES["uploadedfile"]["type"] == "text/html")
	  ||(!$_FILES["uploadedfile"]["type"] == "text/javascript")
	  ||(!$_FILES["uploadedfile"]["type"] == "application/msword")
	  ||(!$_FILES["uploadedfile"]["type"] == "application/pdf")
	  &&(!$_FILES["file"]["size"] < 100000)){
		  echo "The file is not of the right type or size. It should be a
			  .gif, .png, .jpeg/.jpg, .css, .html, .javascript, .doc, or .pdf and under 100kb.";

		  echo "
If you need to send me a file different from these specification, feel free to
				email it to me at you@domain.com. These specifications are for the website's safety.";
	}else{
		if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
			mysql_query("INSERT INTO uploads(ID, URL) VALUES ('$client_ID', '$target_path')");
		} else{
			echo "There was an error uploading the file, please try again!";
		}
	}
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Client Documents</title>
</head>
<body>

<form enctype='multipart/form-data' action='documents.php' method='POST'>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

</body>
</html>

AHA, you read my mind :) I use w3schools for everythinggg... I tutor web design and marketing so I always refer my students to W3 (I think they get annoyed at how much I reference the site) but... I will def. be checking out their PHP info. I am trying to succeed at this project before I try teaching myself another code. Total brain overload the past 48 hours.

Hey man I could help you further with TeamViewer or something let me know if you want my help. It's not easy to correct all your PHP since I would need an exact replica to see what's really going on, so it's just easier to just see what you have and show you how it's done.

Got it to work - Thanks for posting and the offer tho! Here is what I did - in the event someone else needs assistance in the future... I actually Google'd the issue and "noteboard" and came up with it (Google always to the rescue) --->

Changed my INSERT section to:

if (isset($_POST['Submit'])) { // if the form has been submitted
    if ($_POST[message]!="") { // if the message isn't blank
        mysql_query("
            INSERT INTO noteboard(`client_ID`, `date`, `message`)
            VALUES('$client_ID', CURDATE(), '$_POST[message]')
        ") or die(mysql_error());
        // refresh the page
        header("Location: this-page.php"); // Change this-page.php for the name of the noticeboard
    }
}

AND... revised my submit line to:

<input type="submit" name="Submit" value="Submit" />

(*HERE IS THE COMPLETE NOTEBOARD.PHP FILE*)---->

<?php

session_start();

if(!isset($_SESSION['username'])){
    header( 'Location: loginform.html' );
}

require('db.php');

$client_ID = mysql_query("SELECT client_ID
    FROM clients WHERE username='".$_SESSION['username']."'")or die(mysql_error());
$client_ID = mysql_fetch_array($client_ID);
$client_ID = $client_ID['client_ID'];

if (isset($_POST['Submit'])) { // if the form has been submitted
    if ($_POST[message]!="") { // if the message isn't blank
        mysql_query("
            INSERT INTO noteboard(`client_ID`, `date`, `message`)
            VALUES('$client_ID', CURDATE(), '$_POST[message]')
        ") or die(mysql_error());
        // refresh the page
        header("Location: noteboard.php"); // Change this-page.php for the name of the noticeboard
    }
} 
// Displays all current notes
$getNotes = mysql_query("SELECT * FROM noteboard WHERE client_ID='".$client_ID."' ORDER BY date");

while($row = mysql_fetch_array($getNotes, MYSQL_ASSOC)){
    echo "Posted by " . $_SESSION['username'] . " on " . $row['date'] . "<br /><p>"
    . $row['message'] . "</p><hr />";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>

<form action="noteboard.php" method="post">
<h3>Message:</h3><br />
<textarea name="message" cols="30" rows="10"></textarea><br />
<input type="submit" name="Submit" value="Submit" /></form>

</body>
</html>

Aha... and now I am trying to implement the PHP code into my design and have one more question (I hope...) - which line(s) can I revise to change WHERE the messages will be posted? They are currently coming up ABOVE the text area... but now with the design set into the code -- it is coming up above the entire page... on the left top corner. Is there a way to get the messages down and below my textbox (or thereabouts..) - and not outside of the design of the page? I have a feeling it might be something I am missing (via. HTML and my tables).. but not sure..

Moving onto the next aspect b/c this is really frustrating me.. ! Appreciate everyone's help -- can't believe I got this far!!!

Member Avatar for TechySafi

giving errors on 22, 26, 27, and 30

On line 22: there is an extra ")". Remove that.
I don't see any wrong with 26,27and 30 :O Could you show me what kinda error you got? Copy-paste all those error.

you can take help from @Jiwe, I would say the same If I'd have high bandwidth :)

If you still need help I'm here. I can't visualize what you're saying though so if you're still up to it I can help you with remote control.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.