Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3457596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:52:46+00:00 2026-05-18T09:52:46+00:00

I am trying to get a guest book to work using PHP. I have

  • 0

I am trying to get a guest book to work using PHP. I have managed to make it function, the thing is that I don’t want the guest book to be in my index.php. I want it to be on a dynamic page, index.php?=guestbook for instance.

The problem is that when I put the code on another page rather than index.php the thing that happends when I fill out the fields and press the submit button, I get redirected to index.php and nothing is submited to my database. This all works fine as long as the code is in the index.php.

My first question is: What is causing this?
Second question: How do I get the code to function properly eventhough I have it in index.php?=guestbook?

Thanks in advance!

I am using xampp btw.

See below for the code:

    <html>

<head>
 <link rel="stylesheet" href="stylesheet.css" type="text/css">
</head>

<body>

<h1>Guestbook</h1><hr>

<?php

mysql_select_db ("guestbookdatabase") or die ("Couldn't find database!");

$queryget = mysql_query ("SELECT * FROM guestbook ORDER BY id ASC") or die("Error witch query.");

$querygetrownum = mysql_num_rows ($queryget);

if ($querygetrownum == 0)
 echo "No posts have been made yet. Be the first!";

while ($row = mysql_fetch_assoc ($queryget))
{
 $id = $row ['id'];
 $name = $row ['name'];
 $email = $row ['email'];
 $message = $row ['message'];
 $date = $row ['date'];
 $time = $row ['time'];

  if ($id%2)
   $guestbookcomment = "guestbookcomment";
  else
   $guestbookcomment = "guestbookcommentdark";


   echo "
    <div class='$guestbookcomment'>
     <div class='postheader'>
     <b>Posted by $name ($email) on $date at $time</b>
     </div>

      <div class='message'>
      ".nl2br(strip_tags($message))."
      </div>
    </div>
   ";}

echo "<hr>";

if($_POST['submit'])
{
 $name = $_POST['name'];
 $email = $_POST['email'];
 $message = $_POST['message'];
 $date = date("Y-m-d");
 $time = date("H:i:s");

  if ($name&&$email&&$message)
  {
   $querypost = mysql_query ("INSERT INTO guestbook VALUES ('','$name','$email','$message','$date','$time')");
   echo "Please wait... <meta http-equiv='refresh' content='2'>";
  }
  else
   echo "Please fill out all fields.";
}

echo "
<form action='index.php' method='POST'>

Your name: <input type='text' name='name' class='name' maxlength='25' ><br> <br>

Your email: <input type='text' name='email' class='email' maxlength='35'><br><br>

<div class='your_message'>
Your message:<input type='textarea' name='message' class='messagetextarea' maxlength='250'><br><br>
</div>

<input type='submit' name='submit' value='Post'>

</form>

";

?>

</body>

</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:52:47+00:00Added an answer on May 18, 2026 at 9:52 am

    1) The action property of your form should be the same as the name of the file where the code is in. 🙂 You create a guestbook.php, for example, but the action still is ‘index.php’. Hence the problem. You send the POST data to index.php but there’s no code to process it.

    2) The query string doesn’t affect the form. Only the filename.

    I hope I understood your problem correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.