Jump to content

WolfRage

Members
  • Posts

    647
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://www.feralbytes.com

Profile Information

  • Gender
    Male

WolfRage's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. PHP is server side, if you want to submit a form to the server than do so and check it using PHP on the server side. Then if the results are good take them to a completion page else send them back to the form and highlight the improper field(s). There is no opening and closing windows using PHP that is javascript.
  2. Simply includen the script below for the page with comments. Not tested! <?php $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='SELECT * FROM comment WHERE page='.$_SERVER['PHP_SELF']; $result=$mysqli->query($sql); while($row = $result->fetch_array(MYSQLI_ASSOC)) { ?><div class="comment_container"> <p class="comment"><?php echo $row['notes']; ?></p> <p class="comment_signature"><?php echo $row['name'].' | '.$row['time']; ?></p> </div><?php /*Be sure to include your HTML that will separate each comment block you will most likely want the separation to be applied on the top.*/ } $result->close(); $mysqli->close(); ?> In order to post comments you will need to use the comment form that you created earlier and submit to this script: <?php if($_POST['submit']==='Submit') { $name=htmlspecialchars(trim($_POST['visitor'])); // we use htmlspecialchars to prevent some one from injecting content. $email=htmlspecialchars(trim($_POST['visitormail'])); //We could also use the filter_var() here if you want more precision. $url=htmlspecialchars(trim($_POST['url'])); $notes=nl2br(htmlspecialchars(trim($_POST['notes']))); if(empty($name)&&empty($email)&&empty($url)&&empty($notes)) { $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='INSERT INTO table_name (name, email, url, notes, time, pagecolumn) VALUES ('.$mysqli->real_escape_string($visitor).', '.$mysqli->real_escape_string($visitoremail).', '.$mysqli->real_escape_string($url).', '.$mysqli->real_escape_string($notes).','.$mysqli->real_escape_string($_SERVER['REQUEST_TIME']).','.$mysqli->real_escape_string($_SERVER['PHP_SELF']).')'; $mysqli->query($sql); $mysqli->close(); } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. header('Location: '.$_SERVER['HTTP_REFERER']); //HTTP_REFERER may not always be set by the users browser! } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. ?> Besure to take the time to customize these scripts further; at the very least you will need to change the database settings to correctly connect. Truth of the matter is that you had everything that you needed right here to complete your comment script. However you unfortunately did not participate in the excercise. Thus you have learned little of PHP; so it is very unlikely that I will help you out agian. Particularly because you do not appreciate free work and expected me to build you something quickly even though you were not willing to contribute anything more than setting up the database.
  3. Ok so the html structure should look something like this: <div class="comment_container"> <p class="comment"></p> <p class="comment_signature"></p> </div> *Note to self be sure to perform nl2br before inserting the comments into the DB. You can of course apply your CSS rules using the classes. I will have more latter today, should have time throughout the day and for the rest of the week during work. We will get it done. Sorry for delays but as you know time is money. This weekend I launched one new website and I am nearing a deadline for another project that has much work still to be done. Any ways still trying to squeeze you in.
  4. No make the name something like include_comments.php. Change your pagecolumn column to a varchar not an int. I need your html that will style the comments just like you want. So please mock up the html the way you would want it to look for a comment, you can even include a fake comment and I will modify it to properly loop with our SQL Query.
  5. OK I saw that you added a time stamp to the table like I suggested, but we will also need a page column; so that we can pull comments for a specific page. This lesson will be to more parts. One more tonight and the final tomorrow. Then we can wrap up any lose ends. After you have added that other column for your entries into your data base we will extract the comments on a per page level. As a quick side note to automate the process when we add comments to the database we will pull the page name with the Reserved variable $_SERVER['PHP_SELF']. The automated page for pulling your comments. <?php $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='SELECT * FROM comment WHERE page='.$_SERVER['PHP_SELF']; $result=$mysqli->query($sql); while($row = $result->fetch_array(MYSQLI_ASSOC) { //At this point I am guessing that this will work as a while statement. But I am pretty sure. //Next we need your HTML here so that it will be styled the way you would like for your comments. //We should be able to spit our the parts of the returned query like so. echo $row['time']; echo $row['name']; echo $row['url']; echo $row['notes']; /*Be sure to include your HTML that will separate each comment block you will most likely want the separation to be applied on the top.*/ } $result->close(); $mysqli->close(); ?> Tomorrow I will combine all of the sections together appropriately and then we will add any missing pieces. Then you can have a look and tell me what else you would like.
  6. Hey I wanted to tell you sorry for dorpping off, but I got buzy over the weekend with a new site launch. Do you still want my help in completing this project? Have you made any progress outside of the forum?
  7. You are going to to compare the string that you plan to insert into the file with every line in the file and if no match is found then you can insert it.
  8. All together the script will look something like this, minus your changes for your database information and the table name. <?php if($_POST['submit']==='Submit') { $name=htmlspecialchars(trim($_POST['visitor'])); // we use htmlspecialchars to prevent some one from injecting content. $email=htmlspecialchars(trim($_POST['visitormail'])); //We could also use the filter_var() here if you want more precision. $url=htmlspecialchars(trim($_POST['url'])); $notes=htmlspecialchars(trim($_POST['notes'])); if(empty($name)&&empty($email)&&empty($url)&&empty($notes)) { $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='INSERT INTO table_name (visitor, visitoremail, url, notes) VALUES ('.$mysqli->real_escape_string($visitor).', '.$mysqli->real_escape_string($visitoremail).', '.$mysqli->real_escape_string($url).', '.$mysqli->real_escape_string($notes).')'; $mysqli->query($sql); $mysqli->close(); } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. header('Location: '.$_SERVER['HTTP_REFERER']); //HTTP_REFERER may not always be set by the users browser! } else { echo 'Nothing was Posted!'; }// we will change this to be more helpful later. ?> Next we will work on the script to extract these entries from your database; and then display them on your page. For all of those critics out there: Before we take this live we will need to make the input script more complex to include at the minimum a page column so that comments can be stored in the same table for multiple pages. We should also add a time stamp column which can be done with either PHP or MySQL.
  9. Our SQl statement for inserting the information in your data base will look like this: <?php $mysqli = new mysqli('dataBaseHost', 'userName', 'userPassword', 'userDataBase'); if ($mysqli->connect_error) { die('Connect Error ('.$mysqli->connect_errno .') '.$mysqli->connect_error); } //Of course there are much better was to handle this error instead of dying but for now. $sql='INSERT INTO table_name (visitor, visitoremail, url, notes) VALUES ('.$mysqli->real_escape_string($visitor).', '.$mysqli->real_escape_string($visitoremail).', '.$mysqli->real_escape_string($url).', '.$mysqli->real_escape_string($notes).')'; $mysqli->query($sql); $mysqli->close(); ?> More to come...
  10. Yes target = "framename" shoud do it. This method is probably the simplest method it enact however it is also the most resource intensive as it reads the entire file into an array. $lines = count(file($file)); I think the best appraoch is to use the while with the fgets() as it automatically advances the file pointer. Sorry about the infinite loop, I forgot to use fgets in my example along with incrementing the counter which caused your loop. So I would do it like this: $handle = fopen( $filepath, "r" ); $count =0; while( fgets($handle) ) { $count++; } $line=rand(0,$count); fseek($handle,0); fseek($handle,$line); $data=fgets($handle); fclose($handle); echo '<FORM METHOD="'."LINK".'" ACTION="'.$line.'"> <INPUT TYPE="'."submit".'" VALUE="'.$data.'"> </FORM>'; //Your echo statement was not producing valid HTML. Hope this advances your quest! Make sure you replace "LINK" with your actual link...
  11. Really Thanks, Gizmola! SOrry having a busy day at work today. When I get home I will work to put together the rest of your scripts so that you can implement your comments. Of course any other interested parties could actively contribute before then... giz... mola... lol
  12. To allow you to move forward look up the SQL for simple insert into a single table. We will use that SQL statement to craft our php prepared SQL statement. Also did you test out the form with the script and did it echo all of the variables as expected?
  13. Come on now try to learn. You know that this code was not complete I stated you need to increment your counter, which is not defined, plus you need to echo it. <?php $fp = fopen("myfile.txt", "r"); $count=0; while (!feof($fp)) { $count=$count+1; } echo 'The number of lines in this file is = '.$count.' +1 because the file and the counter start at line 0.'; fclose($fp); ?>
  14. Ok in order to pull off what you want to do with the dates, it is going to be relatively complex at least in my mind I am working through it now. I know we will need to use strtotime() along with date() in order to get the future dates we want. To help me visualize this can you give me some example dates to work with and what the expected out come would look like. Then I should be able to come up with a formula that will parse the dates the way you want.
  15. I know your in a hurry but I am doing this in my spare time, which I ran out of yesterday. You will want 5 fields the first field should be a incremental unique key. I will post the next steps in a few.
×
×
  • 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.