Jump to content

music_fan01

Members
  • Posts

    85
  • Joined

  • Last visited

    Never

Everything posted by music_fan01

  1. Yes. Any kind of user input must be validated and filtered. Always assume people will be on your website to do nasty things to it. Thanks for the help!
  2. Now I think I may go it. Also, do I need to add a prepared statement for where my guest have to leave a comment? <!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="index.html">Header</a></div> <div id="menu"> <ul> <li><a href="index.html">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.php">Guestbook</a></li> </ul> </div> </div> <div id="icon"><a href="twitter.com/"> <img border="0" src="http://www.000webhost.com/forum/images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Guestbook</strong></h1> </div> <?php $db = new mysqli("localhost", "a7560006_host", "mypassword", "a7560006_guest"); $preparedStatement1 = $db->prepare('SELECT * FROM guestbook WHERE name = ?'); $preparedStatement1 ->bind_param("s", $name); $preparedStatement1 ->execute(); $prerapedStatement1->bind_result($comment_id,$name,$comment,$datetime); $preparedStatement1->store(); $preparedStatement2 = $db->prepare('SELECT * FROM guestbook WHERE verif_box = ?'); $preparedStatement2 ->bind_param("s", $verif_box); $preparedStatement2 ->execute(); $prerapedStatement1->bind_result($comment_id,$name,$comment,$datetime); $preparedStatement2->store(); while($preparedStatement1->fetch()){ $mysql_host = "localhost"; $mysql_database = "a7560006_guest"; $mysql_user = "a7560006_host"; $mysql_password = "mypassword"; // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server"); mysql_select_db("$mysql_database") or die("cannot select DB"); $tbl_name="guestbook"; // Table name $name = ($_POST['name']); $comment = ($_POST['comment']); $datetime=date("M-d-Y h:i:s A"); //date time $verif_box = ($_POST['verif_box']); if(md5($verif_box).'a4xn' != $_COOKIE['tntcon']){ ?> <table width="400" border="0" align="center"> <tr><td align="center"><h4>You have not entered captcha or entered incorrect captcha!</h4></td></tr> </table> </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> <? exit; } if(empty($name) || empty($comment)) { ?> <table width="400" border="0" align="center"> <tr><td align="center"><h3>Sorry, all fields are required!</h3></td></tr> </table> <? } else { $sql="INSERT INTO $tbl_name (name, comment, datetime) VALUES ('$name', '$comment', '$datetime')"; $result=mysql_query($sql); //check if query successful if($result) { ?> <table width="400" border="0" align="center"> <tr><td align="center"><h3>Thank you for signing my guestbook!</h3></td></tr> </table> <? echo "<meta http-equiv='Refresh' content='1; URL=viewguestbook.php'>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); } ?> </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>
  3. actually if you use prepared statement you don't need at all to use stripslashed or mysql_rea_escape_string or others functions. prepared statement allow you to define what is the value and what is not==>no sql injection And that value has come from a form, hence it does require filtering. So do use stripslashes and htmlentities() as well?
  4. Just make sure that I am coding my prepared statements correctly. <!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="index.html">Header</a></div> <div id="menu"> <ul> <li><a href="index.html">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.php">Guestbook</a></li> </ul> </div> </div> <div id="icon"><a href="twitter.com/"> <img border="0" src="http://www.000webhost.com/forum/images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Guestbook</strong></h1> </div> <?php $preparedStatement = $db->prepare('SELECT * FROM guestbook WHERE name = :name'); $preparedStatement = $db->prepare('SELECT * FROM guestbook WHERE comment = :comment'); $preparedStatement = $db->prepare('SELECT * FROM guestbook WHERE verif_box = :verif_box'); $preparedStatement->execute(array(':name' => $name)); $preparedStatement->execute(array(':comment' => $comment)); $preparedStatement->execute(array(':verif_box' => $verif_box)); $rows = $preparedStatement->fetchAll(); $mysql_host = "localhost"; $mysql_database = "a7560006_guest"; $mysql_user = "a7560006_host"; $mysql_password = "mypassword"; // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server"); mysql_select_db("$mysql_database") or die("cannot select DB"); $tbl_name="guestbook"; // Table name $name = ($_POST['name']); $comment = ($_POST['comment']); $datetime=date("M-d-Y h:i:s A"); //date time $verif_box = ($_POST['verif_box']); if(md5($verif_box).'a4xn' != $_COOKIE['tntcon']){ ?> <table width="400" border="0" align="center"> <tr><td align="center"><h4>You have not entered captcha or entered incorrect captcha!</h4></td></tr> </table> </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> <? exit; } if(empty($name) || empty($comment)) { ?> <table width="400" border="0" align="center"> <tr><td align="center"><h3>Sorry, all fields are required!</h3></td></tr> </table> <? } else { $sql="INSERT INTO $tbl_name (name, comment, datetime) VALUES ('$name', '$comment', '$datetime')"; $result=mysql_query($sql); //check if query successful if($result) { ?> <table width="400" border="0" align="center"> <tr><td align="center"><h3>Thank you for signing my guestbook!</h3></td></tr> </table> <? echo "<meta http-equiv='Refresh' content='1; URL=viewguestbook.php'>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); } ?> </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>
  5. I am trying to protect my guestbook entries from injections such as html, xss, and mysql injections. My php knowledge is very little. If possible, can I have some help please with protecting my entries. I have a few bits and pieces of code to protect my guestbook from injections that I got from some tutorials that I was reading. <!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="index.html">Header</a></div> <div id="menu"> <ul> <li><a href="index.html">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.php">Guestbook</a></li> </ul> </div> </div> <div id="icon"><a href="twitter.com/"> <img border="0" src="http://www.000webhost.com/forum/images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Guestbook</strong></h1> </div> <?php $input = is_numeric($input) ? intval($input) : mysql_real_escape_string($input);function sanitizeString($string) { return htmlentities( (string) $string, ENT_COMPAT, "UTF-8" ); } $preparedStatement = $db->prepare('SELECT * FROM guestbook WHERE name = :name'); $preparedStatement->execute(array(':name' => $name)); $rows = $preparedStatement->fetchAll(); $mysql_host = "localhost"; $mysql_database = "a7560006_guest"; $mysql_user = "a7560006_host"; $mysql_password = "mypassword"; // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server"); mysql_select_db("$mysql_database") or die("cannot select DB"); $tbl_name="guestbook"; // Table name $name = ($_POST['name']); $comment = ($_POST['comment']); $comment = stripslashes($comment); $name = stripslashes($name); $comment = str_replace("<","<",$comment); $name = str_replace("<","<",$name); $datetime=date("M-d-Y h:i:s A"); //date time $verif_box = ($_POST['verif_box']); if(md5($verif_box).'a4xn' != $_COOKIE['tntcon']){ ?> <table width="400" border="0" align="center"> <tr><td align="center"><h4>You have not entered captcha or entered incorrect captcha!</h4></td></tr> </table> </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> <? exit; } if(empty($name) || empty($comment)) { ?> <table width="400" border="0" align="center"> <tr><td align="center"><h3>Sorry, all fields are required!</h3></td></tr> </table> <? } else { $sql="INSERT INTO $tbl_name (name, comment, datetime) VALUES ('$name', '$comment', '$datetime')"; $result=mysql_query($sql); //check if query successful if($result) { ?> <table width="400" border="0" align="center"> <tr><td align="center"><h3>Thank you for signing my guestbook!</h3></td></tr> </table> <? echo "<meta http-equiv='Refresh' content='1; URL=viewguestbook.php'>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); } ?> </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>
  6. Then would I have to put my table in a div in order for it to take effect?
  7. Got it. It works now, but my paragraphs are on top of each other when I am trying to get them side by side.
  8. I was cleaning up my code a bit and trying to put my paragraphs and float them to the right into a div, but now my paragraphs are under my image and not to the right of my image. * body */ body { margin:114px 0 0 0; line-height:15px; font-family: Tahoma, Arial; background: url(images/body_top_bckg.jpg) no-repeat center top #171c20; color:#bed7e6; font-size:11px; } a { color:#018BC1; } a:hover { text-decoration:none; } #header {} #logo { padding:30px 0 120px 0; color:#fff; text-align:center; } /* logo */ #logo a{ color:#fff; text-decoration:none; font-weight:bold; font-size:24px; text-transform:uppercase; } /* Menu */ #menu { color:#fff; text-align:center; } #menu ul { text-align:center; list-style:none; padding:0; } #menu ul li { display:inline } #menu ul a { font-weight:bold; font-size:14px; text-decoration:none; color:#fff; background-color:#445d6c; padding:0 10px 2px 10px; } #menu ul a:hover { background-color:#f26513; } /* Main */ #main { background: url(images/body_all_bckg.jpg) repeat-y top center; } #content { width: 780px; margin:0 auto; overflow:hidden; margin-bottom:3cm; } /* Text */ #text { float: right; width: 760px; margin-top:1cm; } #text p { margin:7px 0 7px 0; } #text li { background:url(images/li.gif) no-repeat 0px 7px; } h1 { margin:30px 0 0 0; padding:5px 0 7px 45px; text-transform:uppercase; font-size:25px; color:#fff; background:url(images/h1_bckg.jpg) no-repeat; float:left; } /* Footer */ #footer { background:url(images/footer_bckg.jpg) no-repeat top center; height:102px; clear:both; width:780px; margin:0 auto; } #left_footer { float:left; padding:60px 0 0 30px; color:#fff; font-size:12px; } #left_footer a { color:#fff; } #left_footer a:hover { text-decoration:none; } #right_footer { float:right; padding:60px 30px 0 0; color:#fff; font-size:12px; text-align:right; } #right_footer a { color:#fff; } #right_footer a:hover { text-decoration:none; } #content .inner_copy { border:0;color:#f00; float:left; width:50%!important; margin:-202px 0 0 0; overflow:hidden; line-height:0; padding:0; font-size:12px } /* gallery */ .row img { margin: 2px; border: 1px solid #0000ff; clear: both; width: 100px; height: 90px; margin-left:3px; } .first { float: right; text-align: center; } .last { border: 1px solid #ffffff; float: right; } .desc { text-align: center; font-weight: normal; width: 120px; margin: 10px; } /* image */ #image { width: 400px; } img.floatLeft { float: left; margin: 4px; } /* paragraphs */ #p { float: left; margin-right: 4px; padding-left: 20px; font-size:12pt; } /* Divider */ #div { float: right; width: 20px; margin-right: 1px; height: 200px; } /* Icon */ #icon { text-align:center; } #container { margin: 20px auto 900px auto; width: 1000px; } aside { width: 400px; float: left; } section { margin: 0; padding: 0 0 20px 0; overflow: auto; text-align: left; } p { margin: 0 50px 10px; text-indent: 20px; } <!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>Blank</strong></h1> </div> <img src="images/test.jpg" class="floatLeft" width="360px;" height="332px;"/> <div id=""container"> <aside> <h2>Header for paragraph 1</h2> <p>Test </p> </aside> <section> <h2>Header for paragraph 2</h2> <p>Test</p> </section> </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>
  9. My border=0 in my table is not working, I still have a black border. Not sure if I have to add div and styling in my css or not such as or if its something already in my css that I overlooked. style.css #table{ border-style:none; } <!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="index.html">Header</a></div> <ul id="menu"> <ul> <li><a href="index.html">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.php">Guestbook</a></li> </ul> <div id="icon"><a href="twitter.com/"> <img border="0" src="images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> </div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Guestbook</strong></h1> </div> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td align="center"><strong>Guestbook</strong> <p align="center">Please leave your comments.</p> <p align="center">* Required field</p></td> </tr> </table> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1> <tr> <form id="form1" name="form1" method="post" action="addguestbook.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1"> <tr> <td width="117">*Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /></td> </tr> <tr> <td valign="top">*Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </td> </form> </tr> </table> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0" > <tr> <td align="center"><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td> </tr> </table> </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> /* body */ body { margin:114px 0 0 0; line-height:15px; font-family: Tahoma, Arial; background: url(images/body_top_bckg.jpg) no-repeat center top #171c20; color:#bed7e6; font-size:11px; } a { color:#018BC1; } a:hover { text-decoration:none; } #header {} #logo { padding:30px 0 120px 0; color:#fff; text-align:center; } /* logo */ #logo a{ color:#fff; text-decoration:none; font-weight:bold; font-size:24px; text-transform:uppercase; } /* Menu */ #menu { color:#fff; text-align:center; } #menu ul { text-align:center; list-style:none; padding:0; } #menu ul li { display:inline } #menu ul a { font-weight:bold; font-size:14px; text-decoration:none; color:#fff; background-color:#445d6c; padding:0 10px 2px 10px; } #menu ul a:hover { background-color:#f26513; } /* Main */ #main { background: url(images/body_all_bckg.jpg) repeat-y top center; } #content { width: 780px; margin:0 auto; overflow:hidden; margin-bottom:3cm; clear:both; } /* Text */ #text { float: left; width: 760px; margin-top:1cm; } #text p { margin:7px 0 7px 0; } #text li { background:url(images/li.gif) no-repeat 0px 7px; } h1 { margin:30px 0 0 0; padding:5px 0 7px 45px; text-transform:uppercase; font-size:25px; color:#fff; background:url(images/h1_bckg.jpg) no-repeat; float:left; } /* Footer */ #footer { background:url(images/footer_bckg.jpg) no-repeat top center; height:102px; clear:both; width:780px; margin:0 auto; } #left_footer { float:left; padding:60px 0 0 30px; color:#fff; font-size:12px; } #left_footer a { color:#fff; } #left_footer a:hover { text-decoration:none; } #right_footer { float:right; padding:60px 30px 0 0; color:#fff; font-size:12px; text-align:right; } #right_footer a { color:#fff; } #right_footer a:hover { text-decoration:none; } #content .inner_copy { border:0;color:#f00; float:left; width:50%!important; margin:-202px 0 0 0; overflow:hidden; line-height:0; padding:0; font-size:12px } /* Floats */ #leftFloat { float: left; width: 100px; } #rightFloat { float: right; width: 100px; } /* gallery */ .row img { margin: 2px; border: 1px solid #0000ff; clear: both; width: 100px; height: 90px; margin-left:3px; } .first { float: right; text-align: center; } .last { border: 1px solid #ffffff; float: right; } .desc { text-align: center; font-weight: normal; width: 120px; margin: 10px; } /* image */ #image { margin-top:1cm; width: 400px; margin-top:2cm; float:left; padding-left:20px; } /* Divider */ #div { float: right; width: 20px; margin-right: 1px; height: 200px; } /* Icon */ #icon { text-align:center; } /* Table */ table,th,td { border:1px solid black; } /* Index */ img.floatLeft { float: left; margin: 4px; } /* paragraphs */ #p { float: left; margin-right: 4px; padding-left: 20px; font-size:12pt; }
  10. I added the class to my css and to my img, but now my paragraphs end up being under my img instead of to the right. <div id="image"> <img src="images/test.jpg" class="floatLeft;" width: "200px;"/> </div> /* body */ body { margin:114px 0 0 0; line-height:15px; font-family: Tahoma, Arial; background: url(images/body_top_bckg.jpg) no-repeat center top #171c20; color:#bed7e6; font-size:11px; } a { color:#018BC1; } a:hover { text-decoration:none; } #header {} #logo { padding:30px 0 120px 0; color:#fff; text-align:center; } /* logo */ #logo a{ color:#fff; text-decoration:none; font-weight:bold; font-size:24px; text-transform:uppercase; } /* Menu */ #menu { color:#fff; text-align:center; } #menu ul { text-align:center; list-style:none; padding:0; } #menu ul li { display:inline } #menu ul a { font-weight:bold; font-size:14px; text-decoration:none; color:#fff; background-color:#445d6c; padding:0 10px 2px 10px; } #menu ul a:hover { background-color:#f26513; } /* Main */ #main { background: url(images/body_all_bckg.jpg) repeat-y top center; } #content { width: 780px; margin:0 auto; overflow:hidden; margin-bottom:3cm; } / * Text */ #text { float: left; width: 760px; margin-top:1cm; } #text p { margin:7px 0 7px 0; } #text li { background:url(images/li.gif) no-repeat 0px 7px; } h1 { margin:30px 0 0 0; padding:5px 0 7px 45px; text-transform:uppercase; font-size:25px; color:#fff; background:url(images/h1_bckg.jpg) no-repeat; float:left; } /* Footer */ #footer { background:url(images/footer_bckg.jpg) no-repeat top center; height:102px; clear:both; width:780px; margin:0 auto; } #left_footer { float:left; padding:60px 0 0 30px; color:#fff; font-size:12px; } #left_footer a { color:#fff; } #left_footer a:hover { text-decoration:none; } #right_footer { float:right; padding:60px 30px 0 0; color:#fff; font-size:12px; text-align:right; } #right_footer a { color:#fff; } #right_footer a:hover { text-decoration:none; } #content .inner_copy { border:0;color:#f00; float:left; width:50%!important; margin:-202px 0 0 0; overflow:hidden; line-height:0; padding:0; font-size:12px } /* Floats */ #leftFloat { float: left; width: 100px; } #rightFloat { float: right; width: 100px; } /* gallery */ .row img { margin: 2px; border: 1px solid #0000ff; clear: both; width: 100px; height: 90px; margin-left:3px; } .first { float: right; text-align: center; } .last { border: 1px solid #ffffff; float: right; } .desc { text-align: center; font-weight: normal; width: 120px; margin: 10px; } /* image */ #image { margin-top:1cm; width: 400px; margin-top:2cm; } .floatLeft { float: left; } /* paragraphs */ #p { float: left; margin-right: 4px; padding-left: 20px; font-size:12pt; } /* Divider */ #div { float: right; width: 20px; margin-right: 1px; height: 200px; } /* Icon */ #icon { text-align:center; }
  11. Oops! Heres my css. Sorry about that. /* body */ body { margin:114px 0 0 0; line-height:15px; font-family: Tahoma, Arial; background: url(images/body_top_bckg.jpg) no-repeat center top #171c20; color:#bed7e6; font-size:11px; } a { color:#018BC1; } a:hover { text-decoration:none; } #header {} #logo { padding:30px 0 120px 0; color:#fff; text-align:center; } /* logo */ #logo a{ color:#fff; text-decoration:none; font-weight:bold; font-size:24px; text-transform:uppercase; } /* Menu */ #menu { color:#fff; text-align:center; } #menu ul { text-align:center; list-style:none; padding:0; } #menu ul li { display:inline } #menu ul a { font-weight:bold; font-size:14px; text-decoration:none; color:#fff; background-color:#445d6c; padding:0 10px 2px 10px; } #menu ul a:hover { background-color:#f26513; } /* Main */ #main { background: url(images/body_all_bckg.jpg) repeat-y top center; } #content { width: 780px; margin:0 auto; overflow:hidden; margin-bottom:3cm; } / * Text */ #text { float: left; width: 760px; margin-top:1cm; } #text p { margin:7px 0 7px 0; } #text li { background:url(images/li.gif) no-repeat 0px 7px; } h1 { margin:30px 0 0 0; padding:5px 0 7px 45px; text-transform:uppercase; font-size:25px; color:#fff; background:url(images/h1_bckg.jpg) no-repeat; float:left; } /* Footer */ #footer { background:url(images/footer_bckg.jpg) no-repeat top center; height:102px; clear:both; width:780px; margin:0 auto; } #left_footer { float:left; padding:60px 0 0 30px; color:#fff; font-size:12px; } #left_footer a { color:#fff; } #left_footer a:hover { text-decoration:none; } #right_footer { float:right; padding:60px 30px 0 0; color:#fff; font-size:12px; text-align:right; } #right_footer a { color:#fff; } #right_footer a:hover { text-decoration:none; } #content .inner_copy { border:0;color:#f00; float:left; width:50%!important; margin:-202px 0 0 0; overflow:hidden; line-height:0; padding:0; font-size:12px } /* Floats */ #leftFloat { float: left; width: 100px; } #rightFloat { float: right; width: 100px; } /* gallery */ .row img { margin: 2px; border: 1px solid #0000ff; clear: both; width: 100px; height: 90px; margin-left:3px; } .first { float: right; text-align: center; } .last { border: 1px solid #ffffff; float: right; } .desc { text-align: center; font-weight: normal; width: 120px; margin: 10px; } /* image */ #image { margin-top:1cm; width: 400px; margin-top:2cm; } /* paragraphs */ #p { float: left; margin-right: 4px; padding-left: 20px; font-size:12pt; } /* Divider */ #div { float: right; width: 20px; margin-right: 1px; height: 200px; } /* Icon */ #icon { text-align:center; }
  12. http://starr05.comule.com/guestbook.php I am trying to get my tables that I have before and after some signs my guestbook centered and below where I have my "Guestbook" header. Right now, its centerd, but its up where my links are. I've tried making a div for my table #table{margin-top:2cm;} but that didnt work so I went ahead and took it out. Not too sure what else I can try. <!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="index.html">Header</a></div> <ul id="menu"> <ul> <li><a href="index.html">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.php">Guestbook</a></li> </ul> <div id="icon"><a href="twitter.com/"> <img border="0" src="images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> </div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Guestbook</strong></h1> <table width="400" border="0" align="left" cellpadding="3" cellspacing="0"> <tr> <td align="center"><strong>Guestbook</strong> <p>Please leave your comments.</p> <p>* Required field</p></td> </tr> </table> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <form id="form1" name="form1" method="post" action="addguestbook.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#000000"> <tr> <td width="117">* Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /></td> </tr> <tr> <td valign="top">* Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </td> </form> </tr> </table> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td align="center"><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td> </tr> </table> </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> <!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="index.html">Header</a></div> <ul id="menu"> <ul> <li><a href="index.html">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.php">Contact</a></li> <li><a href="guestbook.php">Guestbook</a></li> </ul> <div><a href="twitter.com/"> <img border="0" src="http://www.000webhost.com/forum/images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> </div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Guestbook</strong></h1> <table width="400" border="0" align="center" cellpadding="-" cellspacing="0" > <tr> <td><strong>View Guestbook | <a href="guestbook.php">Sign Guestbook</a> </strong></td> </tr> </table> <br> <?php $mysql_host = "mywebhost"; $mysql_database = "a7560006_guest"; $mysql_user = "a7560006_hoku"; $mysql_password = mypassword"; $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server "); mysql_select_db("$mysql_database") or die("cannot select DB"); $sql="SELECT * from $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" > <tr> <td><table width="400" border="0" cellpadding="3" cellspacing="1"> <tr> <td>Comment Number</td> <td>:</td> <td><? echo $rows['comment_id']; ?></td> </tr> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><? echo $rows['name']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><? echo nl2br($rows['comment']); ?></td> </tr> <tr> <td valign="top">Date/Time </td> <td valign="top">:</td> <td><? echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <BR> <?php } mysql_close(); //close database ?> </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>
  13. I have my index page set up with an image and two paragraphs to the right. I am trying to use <img class="floatLeft" />, but when I adjust my code using <img class="floatLeft" /> my picture ends up next to my header. <!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</title> <link href="style.css" rel="stylesheet" type="text/css" /></head> <body> <!-- header --> <div id="header"> <div id="logo"><a href="index.html">Header</a></div> <ul id="menu"> <ul> <li><a href="index.html">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.php">Contact</a></li> <li><a href="guestbook.php">Guestbook</a></li> </ul> <div id="icon"><a href="twitter.com/"> <img border="0" src="images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> </div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Welcome</strong></h1> </div> <div id="image"> <img src="images/test.jpg" style="float:left; width: 365px;"/> </div> <div id="p"> <div style="float: left; width: 180px;"> <h2>Header</h2> <p>Paragraph </p> </p> </div> <div id="div" style="float: left;"> <img src="images/div103.gif" /></div> <div style="float: left; width: 190px;"> <h2>Headerh2> <p> Paragraph </p> </div> </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> /* body */ body { margin:114px 0 0 0; line-height:15px; font-family: Tahoma, Arial; background: url(images/body_top_bckg.jpg) no-repeat center top #171c20; color:#bed7e6; font-size:11px; } a { color:#018BC1; } a:hover { text-decoration:none; } #header {} #logo { padding:30px 0 120px 0; color:#fff; text-align:center; } /* logo */ #logo a{ color:#fff; text-decoration:none; font-weight:bold; font-size:24px; text-transform:uppercase; } /* Menu */ #menu { color:#fff; text-align:center; } #menu ul { text-align:center; list-style:none; padding:0; } #menu ul li { display:inline } #menu ul a { font-weight:bold; font-size:14px; text-decoration:none; color:#fff; background-color:#445d6c; padding:0 10px 2px 10px; } #menu ul a:hover { background-color:#f26513; } /* Main */ #main { background: url(images/body_all_bckg.jpg) repeat-y top center; } #content { width: 780px; margin:0 auto; overflow:hidden; margin-bottom:3cm; } / * Text */ #text { float: left; width: 760px; margin-top:1cm; } #text p { margin:7px 0 7px 0; } #text li { background:url(images/li.gif) no-repeat 0px 7px; } h1 { margin:30px 0 0 0; padding:5px 0 7px 45px; text-transform:uppercase; font-size:25px; color:#fff; background:url(images/h1_bckg.jpg) no-repeat; float:left; } /* Footer */ #footer { background:url(images/footer_bckg.jpg) no-repeat top center; height:102px; clear:both; width:780px; margin:0 auto; } #left_footer { float:left; padding:60px 0 0 30px; color:#fff; font-size:12px; } #left_footer a { color:#fff; } #left_footer a:hover { text-decoration:none; } #right_footer { float:right; padding:60px 30px 0 0; color:#fff; font-size:12px; text-align:right; } #right_footer a { color:#fff; } #right_footer a:hover { text-decoration:none; } #content .inner_copy { border:0;color:#f00; float:left; width:50%!important; margin:-202px 0 0 0; overflow:hidden; line-height:0; padding:0; font-size:12px } /* Floats */ #leftFloat { float: left; width: 100px; } #rightFloat { float: right; width: 100px; } /* gallery */ .row img { margin: 2px; border: 1px solid #0000ff; clear: both; width: 100px; height: 90px; margin-left:3px; } .first { float: right; text-align: center; } .last { border: 1px solid #ffffff; float: right; } .desc { text-align: center; font-weight: normal; width: 120px; margin: 10px; } /* image */ #image { margin-top:1cm; width: 400px; margin-top:2cm; } /* paragraphs */ #p { float: left; margin-right: 4px; padding-left: 20px; font-size:12pt; } /* Divider */ #div { float: right; width: 20px; margin-right: 1px; height: 200px; } /* Icon */ #icon { text-align:center; }
  14. I went back and focused on my divs and I read over the tutorials. Would using classes be a better option?
  15. Would it be better to put margin-top in the image css or that #text css?
  16. I am trying to get rid of my <br/> tags by using margin-top, but when I insert my margin-top into the div that has my image and two paragraphs it doesnt work where I it. It adds it below my links. I have an image and my two paragraphs in my content div and the content div is in the main div. I've tried putting margin-top in my content div, nothing happens, I put it in my main div and thats where I get the break at. Dont know what I am doing wrong. <!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="index.html">Home</a></li> <li><a href="">Link</a></li> <li><a href="">Link</a></li> <li><a href="">Link</a></li> <li><a href="contact.php">Contact</a></li> <li><a href="guestbook.php">Guestbook</a></li> </ul> <div><a href="twitter.com/"> <img border="0" src="images/twitter.png" alt="twitter" width="58px;" height="53px;" /> </a></div> </div> </div> <!--end header --> <!-- main --> <div id="main"> <div id="content"> <div id="text"> <h1><strong>Welcome</strong></h1> </div> <br/> <br/> <br/> <br/> <br/> <br/> <div id="image"> <img src="images/test.jpg" style="width: 360px;"/></div> <div id="p"> <div style="float: left; width: 180px;"> <h2>Header</h2> <p> This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. </p> </div> <div id="div" style="float: left;"> <img src="images/div103.gif" /></div> <div style="float: left; width: 190px;"> <h2>Header</h2> <p> This is our left text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. This is our right text column. </p> </div> </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> /* body */ body { margin:114px 0 0 0; line-height:16px; font-family: Tahoma, Arial; background: url(images/body_top_bckg.jpg) no-repeat center top #171c20; color:#bed7e6; font-size:11px; } a { color:#018BC1; } a:hover { text-decoration:none; } #header {} #logo { padding:30px 0 120px 0; color:#fff; text-align:center; } /* logo */ #logo a{ color:#fff; text-decoration:none; font-weight:bold; font-size:24px; text-transform:uppercase; } /* Menu */ #menu { color:#fff; text-align:center; } #menu ul { text-align:center; list-style:none; padding:0; } #menu ul li { display:inline } #menu ul a { font-weight:bold; font-size:14px; text-decoration:none; color:#fff; background-color:#445d6c; padding:0 10px 2px 10px; } #menu ul a:hover { background-color:#f26513; } /* Main */ #main { background: url(images/body_all_bckg.jpg) repeat-y top center; } #content { width: 780px; margin:0 auto; overflow:hidden; margin-bottom:3cm; } / * Text */ #text { float: left; width: 780px; } #text p { margin:7px 0 7px 0; } #text li { background:url(images/li.gif) no-repeat 0px 7px; } h1 { margin:30px 0 0 0; padding:5px 0 7px 45px; text-transform:uppercase; font-size:24px; color:#fff; background:url(images/h1_bckg.jpg) no-repeat; float:left; } /* Footer */ #footer { background:url(images/footer_bckg.jpg) no-repeat top center; height:102px; clear:both; width:780px; margin:0 auto; } #left_footer { float:left; padding:60px 0 0 30px; color:#fff; font-size:12px; } #left_footer a { color:#fff; } #left_footer a:hover { text-decoration:none; } #right_footer { float:right; padding:60px 30px 0 0; color:#fff; font-size:12px; text-align:right; } #right_footer a { color:#fff; } #right_footer a:hover { text-decoration:none; } #content .inner_copy { border:0;color:#f00; float:left; width:50%!important; margin:-202px 0 0 0; overflow:hidden; line-height:0; padding:0; font-size:12px } /* Floats */ #leftFloat { float: left; width: 100px; } #rightFloat { float: right; width: 100px; } /* gallery */ .row img { margin: 2px; border: 1px solid #0000ff; clear: both; width: 100px; height: 90px; margin-left:3px; } .first { float: right; text-align: center; } .last { border: 1px solid #ffffff; float: right; } .desc { text-align: center; font-weight: normal; width: 120px; margin: 10px; } /* image */ #image { float: left; } /* paragraphs */ #p { float: right; margin-right: 4px; } /* Divider */ #div { float: right; width: 20px; margin-right: 1px; height: 200px; } /* Icon */ #icon { text-align:center; }
  17. Thanks for the help! I was thinking it something worse wrong with that line.
  18. Parse error: syntax error, unexpected T_VARIABLE in /home/a5143936/public_html/addguestbook.php on line 35 (line 35 is $result=mysql_query($sql) I got the following error. <?php $mysql_host = "myhost"; $mysql_database = "guest"; $mysql_user = "myusername"; $mysql_password = "mypassword"; $comment = stripslashes($comment); $email = stripslashes($email); $name = stripslashes($name); $comment = str_replace ("<","<",$comment); $comment = str_replace ("\n","<br>",$comment); $email = str_replace ("<","<",$email); $email = str_replace ("\n","<br>",$email); $name = str_replace ("<","<",$name); $name = str_replace ("\n","<br>",$name); $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server "); mysql_select_db("$mysql_database") or die("cannot select DB"); $name = $_POST['name']; $email = $_POST['email']; $comment = $_POST['comment']; $datetime=date("y-m-d h:i:s"); //date time if(empty($email) || empty($name) || empty($comment)) { echo "<h3>Sorry all fields are required</h3>"; } else { $sql="INSERT INTO $tbl_name (name, email, comment, datetime) VALUES ('$name', '$email', '$comment', CURRENT_TIMESTAMP())" $result=mysql_query($sql); //check if query successful if($result){ echo "Thank you for signing my guestbook!"; echo "<BR>"; echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); } ?> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>View Guestbook | <a href="guestbook.php">Sign Guestbook</a> </strong></td> </tr> </table> <br> <?php $mysql_host = "myhost"; $mysql_database = "guest"; $mysql_user = "myusername"; $mysql_password = "mypassword"; $tbl_name="guestbook"; // Table name $comment = stripslashes($comment); $email = stripslashes($email); $name = stripslashes($name); $comment = str_replace ("<","<",$comment); $comment = str_replace ("\n","<br>",$comment); $email = str_replace ("<","<",$email); $email = str_replace ("\n","<br>",$email); $name = str_replace ("<","<",$name); $name = str_replace ("\n","<br>",$name); // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server "); mysql_select_db("$mysql_database") or die("cannot select DB"); $sql="SELECT id, name,email,comment, DATE_FORMAT(`datetime`,'%b-%d-%y %r') as datetime FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td>ID</td> <td>:</td> <td><? echo $rows['id']; ?></td> </tr> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><? echo $rows['name']; ?></td> </tr> <tr> <td>Email</td> <td>:</td> <td><? echo $rows['email']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><? echo nl2br($rows['comment']); ?></td> </tr> <tr> <td valign="top">Date/Time </td> <td valign="top">:</td> <td><? echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <BR> <? } mysql_close(); //close database ?>
  19. Change this portion $sql="SELECT * FROM $tbl_name"; to $sql="SELECT id, name,email,comment, DATE_FORMAT(`datetime`,'%b-%d-%y %r') as datetime FROM $tbl_name"; correct?
  20. I try to adjust my date and time to ("M-d-Y h:i:s A"), but when I do, I get 0's for the both the date and time. <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>Test Sign Guestbook </strong></td> </tr> </table> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form id="form1" name="form1" method="post" action="addguestbook.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email" size="40" /></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td> </tr> </table> </td> </form> </tr> </table> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong><a href="viewguestbook.php">View Guestbook</a> </strong></td> </tr> </table> <?php $mysql_host = "myhost"; $mysql_database = "guest"; $mysql_user = "myusername"; $mysql_password = "mypassword"; //$db_name="guest"; This is not needed, as db_name is $mysql_database above, so please delete this line. $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server "); mysql_select_db("$mysql_database") or die("cannot select DB"); $name = $_POST['name']; $email = $_POST['email']; $comment = $_POST['comment']; $datetime=date("y-m-d h:i:s"); //date time $sql="INSERT INTO $tbl_name (name, email, comment, datetime) VALUES ('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); //check if query successful if($result){ echo "Successful"; echo "<BR>"; echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); ?> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>View Guestbook | <a href="guestbook.php">Sign Guestbook</a> </strong></td> </tr> </table> <br> <?php $mysql_host = "myhost"; $mysql_database = "guest"; $mysql_user = "myusername"; $mysql_password = "mypassword"; $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$mysql_host", "$mysql_user", "$mysql_password") or die("cannot connect server "); mysql_select_db("$mysql_database") or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td>ID</td> <td>:</td> <td><? echo $rows['id']; ?></td> </tr> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><? echo $rows['name']; ?></td> </tr> <tr> <td>Email</td> <td>:</td> <td><? echo $rows['email']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><? echo nl2br($rows['comment']); ?></td> </tr> <tr> <td valign="top">Date/Time </td> <td valign="top">:</td> <td><? echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <BR> <? } mysql_close(); //close database ?>
  21. I'll look into cause I would feel a lot safer using "localhost" than the username.
  22. Ok, I think I understand how it works. Thanks!
  23. 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?
×
×
  • 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.