Jump to content

Recommended Posts

I just want to make sure that I've done this right, this is my first time in awhile making a database for a website.

 

CREATE TABLE `guests` (

`Guest:` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,

`Name:` VARCHAR( 80 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,

`Message:` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL

) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_bin;

 

 

Link to comment
https://forums.phpfreaks.com/topic/248763-guestbook-database/
Share on other sites

I've made a database for my guestbook, but its been awhile since I've made one. Just wondering if someone could look over my code and possible help me with fixing my database.

 

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>


<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            
                  </ul>

   <img src="images/twitter.png" height="49px;"/>
  
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Guestbook</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<form method="post" action="addguest.php">
<div align="center"></div>
<div align="center"></div>
<div align="center" class="style1"></div>
<div align="center"><span class="style1">Name:</span><br />
  <input name="name" type="text" size="30" maxlength="40" />
  <br />
  <br/>
  <br/>
<span class="style1">Message:</span><br />
<textarea name="msg" cols="30" rows="6"></textarea>
<br />
<br />
<input type="reset" value="Reset" />
 
<input type="submit" value="Send" />
</div>


<div align="center">
  <p> </p>
</div>

<?php
$file = "guestbook.txt";

if (fopen($file, "r")) {
$fil = "guestbook.txt";
$fo = fopen ($fil, "r");
$con = fread ($fo,filesize ($fil));
fclose ($fo);
echo "$con";
} else {
echo "<h3>Sorry there was an error please contact me.<h3>";
}
?>


    
           
     <!-- footer -->
    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality Software</a>

    </div>
    </div>
    <!-- end footer -->
</div>
    <!-- end main -->



</body>
</html>

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author 

intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>


<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">contact</a></li>
    <li><a href="#">Guestbook</a></li>
            
                  </ul>

   <img src="images/twitter.png" height="49px;"/>
  
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Guestbook</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>


<?php

CREATE TABLE `guestbook` (`Guest` INT(70) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY, 

`Name` VARCHAR(65) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `Message` 

VARCHAR(200) CHARACTER SET utf32 COLLATE utf32_bin NULL DEFAULT NULL, `Posted` VARCHAR(65) 

CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL) ENGINE = MyISAM CHARACTER SET utf8 

COLLATE utf8_bin



date_default_timezone_set('America/New_York');
date('h:i:s a');

$sql="INSERT INTO $guest(name,message, posted)VALUES('$name', '$msg', '$posted',)";
$result=mysql_query($sql);



$file           = "guestbook.txt";
$name		= $_POST['name'];
$posted 	=$_POST['posted'];

$msg		= $_POST['msg'];

$msg  = stripslashes($msg);
$posted  = stripslashes($posted);

$name = stripslashes($name);

$msg = nl2br(htmlentities($msg));

$posted = nl2br(htmlentities($posted));

$name = nl2br(htmlentities($name));

if (empty($name) || empty($msg)) {
echo "<h3>Sorry all fields are required</h3>";
} else {

$fp = fopen($file,"a");

$timestamp=date("M-d-Y h:m:s A");
fwrite($fp, '
<font size="3">
<BR><BR>
Posted: '.$timestamp.'<br />
Name: '.$name.'<BR>

<BR>Message: '.$msg.'<BR>
');

fclose($fp);
  
echo '<font size="3"><p align="center">Thank you '.$name.' for singing my 

guestbook</p></font>'; 
}
?>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<p align="center"><a href="guestbook.php">Back to GuestBook</a></p>

<div align="center"></div>

          </div>
           
     <!-- footer -->
    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality 

Software</a>

    </div>
    </div>
    <!-- end footer -->
</div>
    <!-- end main -->



</body>
</html>


Link to comment
https://forums.phpfreaks.com/topic/248763-guestbook-database/#findComment-1277595
Share on other sites

just to start.....  please tell me that you really don't have this code in your php

 

 

<?php

CREATE TABLE `guestbook` (`Guest` INT(70) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY,

 

`Name` VARCHAR(65) CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL, `Message`

 

VARCHAR(200) CHARACTER SET utf32 COLLATE utf32_bin NULL DEFAULT NULL, `Posted` VARCHAR(65)

 

CHARACTER SET utf8 COLLATE utf8_bin NULL DEFAULT NULL) ENGINE = MyISAM CHARACTER SET utf8

 

COLLATE utf8_bin

 

Link to comment
https://forums.phpfreaks.com/topic/248763-guestbook-database/#findComment-1278294
Share on other sites

I just changed it now. I now have

 

CREATE TABLE `guestbook`.`guest` (
`Guest Number` INT( 4 ) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY ,
`Name` VARCHAR( 70 ) NULL DEFAULT NULL ,
`Message` VARCHAR( 200 ) NULL DEFAULT NULL ,
`Posted` TIMESTAMP NULL DEFAULT NULL 
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_bin;

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author 

intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>


<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            
                  </ul>

   <img src="images/twitter.png" height="49px;"/>
  
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Guestbook</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<form method="post" action="addguest.php">
<div align="center"></div>
<div align="center"></div>
<div align="center" class="style1"></div>
<div align="center"><span class="style1">Name:</span><br />
  <input name="name" type="text" size="30" maxlength="40" />
  <br />
  <br/>
  <br/>
<span class="style1">Message:</span><br />
<textarea name="msg" cols="30" rows="6"></textarea>
<br />
<br />
<input type="reset" value="Reset" />
 
<input type="submit" value="Send" />
</div>


<div align="center">
  <p> </p>
</div>

<?php

echo "<h3>Sorry there was an error please contact me.<h3>";

?>


    
           
     <!-- footer -->
    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality 

Software</a>

    </div>
    </div>
    <!-- end footer -->
</div>
    <!-- end main -->



</body>
</html>



 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author 

intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>


<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">contact</a></li>
    <li><a href="#">Guestbook</a></li>
            
                  </ul>

   <img src="images/twitter.png" height="49px;"/>
  
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Guestbook</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>


<?php

CREATE TABLE `guestbook`.`guest` (
`Guest Number` INT( 4 ) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY ,
`Name` VARCHAR( 70 ) NULL DEFAULT NULL ,
`Message` VARCHAR( 200 ) NULL DEFAULT NULL ,
`Posted` TIMESTAMP NULL DEFAULT NULL 
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_bin;



date_default_timezone_set('America/New_York');
date('h:i:s a');

$sql="INSERT INTO $guestbook (name,message, posted)VALUES('$name', '$msg', '$posted',)";
$result=mysql_query($sql);


$name		= $_POST['name'];
$posted 	=$_POST['posted'];

$msg		= $_POST['msg'];

$msg  = stripslashes($msg);
$posted  = stripslashes($posted);

$name = stripslashes($name);

$msg = nl2br(htmlentities($msg));

$posted = nl2br(htmlentities($posted));

$name = nl2br(htmlentities($name));

if (empty($name) || empty($msg)) {
echo "<h3>Sorry all fields are required</h3>";
} else {


$timestamp=date("M-d-Y h:m:s A");
fwrite($fp, '
<font size="3">
<BR><BR>
Posted: '.$timestamp.'<br />
Name: '.$name.'<BR>

<BR>Message: '.$msg.'<BR>
');

fclose($fp);
  
echo '<font size="3"><p align="center">Thank you '.$name.' for singing my 

guestbook</p></font>'; 
}
?>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<div align="center"></div>
<p align="center"><a href="guestbook.php">Back to GuestBook</a></p>

<div align="center"></div>

          </div>
           
     <!-- footer -->
    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality 

Software</a>

    </div>
    </div>
    <!-- end footer -->
</div>
    <!-- end main -->



</body>
</html>





 

When I run it, I get the following error:

 

 

Parse error: syntax error, unexpected T_STRING in /home/a9577046/public_html/addguest.php on line 59

Link to comment
https://forums.phpfreaks.com/topic/248763-guestbook-database/#findComment-1278429
Share on other sites

This:



<?php

CREATE TABLE `guestbook`.`guest` (
`Guest Number` INT( 4 ) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY ,
`Name` VARCHAR( 70 ) NULL DEFAULT NULL ,
`Message` VARCHAR( 200 ) NULL DEFAULT NULL ,
`Posted` TIMESTAMP NULL DEFAULT NULL 
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_bin;

 

is NOT php code.  This is SQL and will need to be run against your database, php can not parse SQL code, it's just not what it does.

 

Lets take this back to the start.  Where are you setting all this up? hosting or local server?

Link to comment
https://forums.phpfreaks.com/topic/248763-guestbook-database/#findComment-1278434
Share on other sites

key info at the top of that page is

So, if you have version 1.8 of EasyPHP, type http://127.0.0.1/mysql/ to bring up phpMyAdmin.

However, if you have EasyPHP version 2.0, type http://127.0.0.1/home/mysql/ instead.

You enter the affore mentioned SQL code into the SQL section of your MySQL admin pages.  This will create your table for you to access using your php script.

 

If you want PHP to do it you will need to build it into a string and execute it using mysql_query.

<?php
// make a new page to create table and put this code into it
$host = "localhost"; // as you are running the MySQL database on the same machine that you are running the script on
$name = "dbName"; // change this to the name of a database user account that has permision to create tables
$password = "dbPassword"; // the password for the databse username used in the line above

$con = mysql_connect($host, $name, $password) or die ("ERROR - could not connect to the server.  Server returned the following error message:<br><br>".mysql_error());
$db = "your_database_name"; // this is the database that you will be using within your server - this is NOT the table name
$db = mysql_select_db($db, $con) or die ("ERROR - Could not switch to chosen databse.  Server returned the following error:<br><br>".mysql_error());

$sql = "CREATE TABLE `guestbook`.`guest` (".
"`Guest Number` INT( 4 ) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY ,".
"`Name` VARCHAR( 70 ) NULL DEFAULT NULL ,".
"`Message` VARCHAR( 200 ) NULL DEFAULT NULL ,".
"`Posted` TIMESTAMP NULL DEFAULT NULL ".
") ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_bin";

$qry = mysql_query($sql) or die ("ERROR - Unable to create table. Server responded with:<br><br>".mysql_error());
echo "Table \"guestbook\" has now been created";
exit;
?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/248763-guestbook-database/#findComment-1278571
Share on other sites

key info at the top of that page is

So, if you have version 1.8 of EasyPHP, type http://127.0.0.1/mysql/ to bring up phpMyAdmin.

However, if you have EasyPHP version 2.0, type http://127.0.0.1/home/mysql/ instead.

You enter the affore mentioned SQL code into the SQL section of your MySQL admin pages.  This will create your table for you to access using your php script.

 

If you want PHP to do it you will need to build it into a string and execute it using mysql_query.

<?php
// make a new page to create table and put this code into it
$host = "localhost"; // as you are running the MySQL database on the same machine that you are running the script on
$name = "dbName"; // change this to the name of a database user account that has permision to create tables
$password = "dbPassword"; // the password for the databse username used in the line above

$con = mysql_connect($host, $name, $password) or die ("ERROR - could not connect to the server.  Server returned the following error message:<br><br>".mysql_error());
$db = "your_database_name"; // this is the database that you will be using within your server - this is NOT the table name
$db = mysql_select_db($db, $con) or die ("ERROR - Could not switch to chosen databse.  Server returned the following error:<br><br>".mysql_error());

$sql = "CREATE TABLE `guestbook`.`guest` (".
"`Guest Number` INT( 4 ) NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY ,".
"`Name` VARCHAR( 70 ) NULL DEFAULT NULL ,".
"`Message` VARCHAR( 200 ) NULL DEFAULT NULL ,".
"`Posted` TIMESTAMP NULL DEFAULT NULL ".
") ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_bin";

$qry = mysql_query($sql) or die ("ERROR - Unable to create table. Server responded with:<br><br>".mysql_error());
echo "Table \"guestbook\" has now been created";
exit;
?>

 

And if I wanted to actually host my guestbook, I would have to provide the same information?

Link to comment
https://forums.phpfreaks.com/topic/248763-guestbook-database/#findComment-1278842
Share on other sites

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.