music_fan01 Posted October 9, 2011 Share Posted October 9, 2011 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; Quote Link to comment Share on other sites More sharing options...
fenway Posted October 9, 2011 Share Posted October 9, 2011 Minus the colons, sure -- are there no other tables? Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 9, 2011 Author Share Posted October 9, 2011 No, there are no other tables. And the colons where I have Guest, Name, and Message? Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 9, 2011 Author Share Posted October 9, 2011 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> Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted October 10, 2011 Share Posted October 10, 2011 I can see a serious problem with the PHP, but what's wrong with the database? Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 10, 2011 Author Share Posted October 10, 2011 I am not sure if I called everything right and while I was making my database, I had got no errors, but I dont know if it will work with my php. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted October 11, 2011 Share Posted October 11, 2011 I don't undertand, if you have already created the database what are you asking about the PHP? Quote Link to comment Share on other sites More sharing options...
mikosiko Posted October 11, 2011 Share Posted October 11, 2011 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 Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 11, 2011 Author Share Posted October 11, 2011 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 Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 11, 2011 Author Share Posted October 11, 2011 I don't undertand, if you have already created the database what are you asking about the PHP? My php doesnt work now with my database. At first I thought it might have been my database, but I think its my php or both. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted October 11, 2011 Share Posted October 11, 2011 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? Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 11, 2011 Author Share Posted October 11, 2011 Right now, local server. Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 12, 2011 Author Share Posted October 12, 2011 http://www.homeandlearn.co.uk/php/php12p2.html this was the example I was looking at when working on my code. Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted October 12, 2011 Share Posted October 12, 2011 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; ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted October 12, 2011 Share Posted October 12, 2011 If you're getting PHP syntax errors, you're in the wrong forum. Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 13, 2011 Author Share Posted October 13, 2011 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? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted October 13, 2011 Share Posted October 13, 2011 yes, you would need to change the information for $host, $name and $password to reflect your hosted database and an account on that. then run the page to create the table on that server. Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 14, 2011 Author Share Posted October 14, 2011 Ok, I think I understand how it works. Thanks! Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted October 14, 2011 Share Posted October 14, 2011 No problem, just an FYI, you can normaly (depends on how your hosting is set up) still use "localhost" for hosted database access as long as the PHP is running on the same server. Quote Link to comment Share on other sites More sharing options...
music_fan01 Posted October 14, 2011 Author Share Posted October 14, 2011 I'll look into cause I would feel a lot safer using "localhost" than the username. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.