Jump to content

Simple GUESTBOOK problem


buknoii

Recommended Posts

greetings! I installed XAMPP on my computer and when i tried creating a php script to view the database it shows the result perfectly.

 

But when I tried creating a simple guestbook program it keeps showing the same error message "WRONG"

 

below are the codes of my program

 

SIGNUP.PHP

<form method="post" action="signup_db.php">

Name : <input type="text" name="frm_name"><br>

E-mail : <input type="text" name="frm_email"><br>

Tel No : <input type="text" name="frm_telno"><br>

Message : <input type="text" name="frm_message"><br>

<input type="submit" name="frm_submit" value="POST GUESTBOOK">

 

 

SIGNUP_DB.PHP

<?php

 

include("dbconnect.php");

 

 

if ($frm_submit=="POST GUESTBOOK")

 

{

 

$query = " insert into gb_entry

(gb_name,gb_email,gb_telno,gb_message) values

('".mysql_real_escape_string($frm_name)."','".

            mysql_real_escape_string($frm_email)."','".

    mysql_real_escape_string($frm_telno)."','".

            mysql_real_escape_string($frm_message)."')"

        ;

 

mysql_query($query) or

die(mysql_error());

 

?>

 

<h2>entry added</h2>

 

<?php

 

}

else

{

echo "WRONG";

}

?>

 

 

 

dbconnect.php

 

<?php

 

mysql_connect("127.0.0.1","root","november") or

die("query=$query\nerror=".mysql_error());

 

mysql_select_db("guestbook") or

die ("could not select database");

 

 

?>

 

 

any help would be appreciated

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/96127-simple-guestbook-problem/
Share on other sites

signup_db.php:

<?php

include("dbconnect.php");

if ($_POST['frm_submit']=="POST GUESTBOOK")

{

   $query = " insert into gb_entry
      (gb_name,gb_email,gb_telno,gb_message) values
      ('".mysql_real_escape_string($frm_name)."','".
            mysql_real_escape_string($frm_email)."','".
          mysql_real_escape_string($frm_telno)."','".
            mysql_real_escape_string($frm_message)."')"
        ;

      mysql_query($query) or
      die(mysql_error());


echo "<h2>entry added</h2>";

}
else
{
   echo "WRONG";
}
?>

try this 

 

 

php code

 

<?php
$host = "localhost";
$user = "root";
$password = "";
$dbase = "guestbook";

$dblink = mysql_connect($host,$user,$password);
mysql_select_db($dbase,$dblink);

$query = "INSERT INTO guestbook_example (name, comment) VALUES ('$name','$comment')";
  $result1 = mysql_query($query, $dblink);


?>

 

 

html code

<form name="form1" method="post" action="">
  <p>Name 
    <input type="text" name="name">
</p>
  <p>Comment 
    <label>
    <input type="text" name="comment">
    </label>
  </p>
</form>

 

Jun and Derrick thanks for the help! what i did is i incorporated both of your codes and it worked perfectly.

 

<?php

 

include("dbconnect.php");

 

$xname = $_POST['frm_name'];

$email = $_POST['frm_email'];

$telno = $_POST['frm_telno'];

$message = $_POST['frm_telno'];

$frm_submit = $_POST['frm_submit'];

 

if ($_POST['frm_submit']=="POST GUESTBOOK")

 

{

 

  $query = " insert into gb_entry

      (gb_name,gb_email,gb_telno,gb_message) values

      ('".mysql_real_escape_string($xname)."','".

            mysql_real_escape_string($email)."','".

          mysql_real_escape_string($telno)."','".

            mysql_real_escape_string($message)."')"

        ;

 

      mysql_query($query) or

      die(mysql_error());

 

 

echo "<h2>entry added</h2>";

 

}

else

{

  echo "WRONG";

}

?>

 

thanks guys!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.