ball420 Posted April 23, 2007 Share Posted April 23, 2007 i keep getting error but i can't find anyhting wrong here's the three different pages guestbook.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title></head> <body> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>Rate this Restaurant </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>Subject</td> <td>:</td> <td><input name="subject" type="text" id="subject" 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">Check out everyones comments</a> </strong></td> </tr> </table> </body> </html> and here is addguestbook.php <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $datetime=date("y-m-d h:i:s"); //date time $sql="INSERT INTO $tbl_name(name, email, subject, comment, datetime)VALUES('$name', '$email', '$comment','$subject' '$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(); ?> please help i just don't understand Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 23, 2007 Author Share Posted April 23, 2007 please help Quote Link to comment Share on other sites More sharing options...
Mr. R Posted April 23, 2007 Share Posted April 23, 2007 Whats the error your getting? Just gotta do this <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $datetime=date("y-m-d h:i:s"); //date time $sql="INSERT INTO $tbl_name(name, email, subject, comment, datetime)VALUES('$name', '$email', '$comment','$subject' '$datetime')"; $result=mysql_query($sql); //check if query successful if($result){ echo "Successful"; echo "<BR>"; echo "<a href='viewguestbook.php'>View guestbook[/url]"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
Mr. R Posted April 23, 2007 Share Posted April 23, 2007 BTW you dont need the "" around the $host, $username and $password Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 23, 2007 Author Share Posted April 23, 2007 the error i'm getting is the last line else { echo "ERROR" } when i put in my localhost i need http://ect..... or can i just say localhost and my password i don't have one set can these be any problems? i'm using WAMP to test this on my cpu thanks Quote Link to comment Share on other sites More sharing options...
Mr. R Posted April 23, 2007 Share Posted April 23, 2007 I think its because on the line where you have the link, you have put [/url] instead on </ a>. EDIT no, this is just me being stupid, this automaticall changes [/url] to </ a>? Yeah sure you can just put localhost and your username and password, i dont think theres any probelms with it. You can have the variables you just dont need the "" around them. Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 23, 2007 Author Share Posted April 23, 2007 now if i put</a> instead of [/url] what's the differance?? thanks a ton for your help Quote Link to comment Share on other sites More sharing options...
Mr. R Posted April 23, 2007 Share Posted April 23, 2007 sorry that was me bein stupid.. Try this... Change: mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); To.. $connect = mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db($db_name, $connect)or die("cannot select DB"); Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 23, 2007 Author Share Posted April 23, 2007 not that doesn't work i'm stuck? it's connecting to the databse but i'm getting the end error Quote Link to comment Share on other sites More sharing options...
Mr. R Posted April 23, 2007 Share Posted April 23, 2007 Argh this is annoying, i set it up on my wampserver and it isnt working on mine either.. i'll keep trying. Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 23, 2007 Author Share Posted April 23, 2007 thanks a million man this is driving me nuts!!1 mabey its somthing on the initial sign up sheet guestbook.php i won't give up!!!! Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 23, 2007 Author Share Posted April 23, 2007 no luck on this side yet but i won't give up Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 23, 2007 Share Posted April 23, 2007 replace $result=mysql_query($sql); with $result=mysql_query($sql) or die("query error:".mysql_error() ); atleast then your see the error personally it looks like and error here $sql="INSERT INTO $tbl_name(name, email, subject, comment, datetime)VALUES('$name', '$email', '$comment','$subject' '$datetime')"; change to $sql="INSERT INTO $tbl_name (name, email, subject, comment, datetime) VALUES ('$name', '$email', '$comment','$subject', '$datetime')"; Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 23, 2007 Author Share Posted April 23, 2007 that little was comma was the problem!!! thanks now the next issue it doesn't write any of the info in the database. the id is there cause it's an auto inc and the date and time but none of the other info is there?? thanks for so much help everyone Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 add <?php $name = $_POST['name']; $email = $_POST['email ']; $comment = $_POST['comment']; $subject = $_POST['subject']; ?> after $datetime=date("y-m-d h:i:s"); //date time Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 24, 2007 Author Share Posted April 24, 2007 dude you are awsome i would love to give you a donation for your help!!! one more issue now the viewguestbook doesn't work. here's the code. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>Jelly Beans | <a href="guestbook.php">Rate the Bean</a> </strong></td> </tr> </table> <br> <?php $host="localhost"; // Host name $username = me; // Mysql username $password = too; // Mysql password $db_name = test; // Database name $tbl_name=clearbook; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")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 valign="top">Subject</td> <td valign="top">:</td> <td><? echo $rows['subject']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><? echo $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 ?> </body> </html> now here is the error Parse error: parse error, unexpected $end in C:\wamp\www\clear\viewguestbook.php on line 75 but seriously i'll throw ya a few bucks if you can help me along the way with this project and i'll donate to phpfreaks thanks a million Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 humm i can't see any errors Yet some WAMP servers don't support <? and must have <?php so try <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>Jelly Beans | <a href="guestbook.php">Rate the Bean </a> </strong></td> </tr> </table> <?php $host="localhost"; // Host name $username = me; // Mysql username $password = too; // Mysql password $db_name = test; // Database name $tbl_name=clearbook; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")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><?php echo $rows['id']; ?></td> </tr> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><?php echo $rows['name']; ?></td> </tr> <tr> <td valign="top">Subject</td> <td valign="top">:</td> <td><?php echo $rows['subject']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><?php echo $rows['comment']; ?></td> </tr> <tr> <td valign="top">Date/Time </td> <td valign="top">:</td> <td><?php echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <BR> <?php } mysql_close(); //close database ?> </body> </html> Note i assume you have set $username = me; // Mysql username $password = too; // Mysql password $db_name = test; // Database name $tbl_name=clearbook; // Table name correctly ie with quotes Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 24, 2007 Author Share Posted April 24, 2007 that was it thanks! thanks a million again now on to the next tasks of the spam filter and curse word filter. any good suggestions? thanks again Quote Link to comment Share on other sites More sharing options...
rcorlew Posted April 24, 2007 Share Posted April 24, 2007 This should get you going: if(preg_match("[href|</A>|</a>|<script]",$g_name,$nm,PREG_OFFSET_CAPTURE) > 0) { echo"No spam allowed"; exit(); } Much luck. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 <?php function filter($string) { $pattern[0] = "/badword1/"; $pattern[1] = "/badword2/"; $pattern[2] = "/badword3/"; $replacement[0] = "####"; $replacement[1] = "####"; $replacement[2] = "####"; return preg_replace($pattern, $replacement, $string); } ?> Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 24, 2007 Author Share Posted April 24, 2007 wow thanks everyone let me just clarify what i'm looking at here. for the spam filter i should place the if statement right under the text box for the comments and the bad word filter on the view guestbook page or would this be placed on the page that puts it into the sql database? again i can't express how much these posts have helped me in the learning process of the wonderfu world of php!! Cheers! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 can be used for either, as you could have the bad works enter the database so you can review later, and filter on display or just filter before entering the database Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 24, 2007 Author Share Posted April 24, 2007 awsome, i don't mean to be such a pain in the butt i'm just in the learning process and trying to understand PHP. what's the best way to hide your username password ect. put in a separate config.php file? but if someone found outthe url to it they could still view the source. right? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 nope try this <?php $user = "ME"; $password "TEST"; if($password == "TEST") { echo "hello world"; } ?> create that as a file and view source Quote Link to comment Share on other sites More sharing options...
ball420 Posted April 24, 2007 Author Share Posted April 24, 2007 oh i see!! nice, i was worried about that but i knew there was a way to mask it. also that bad word filter seems to be giving me a problem i don't think i'm putting it in my code right <table width="400" border="0" align="center" cellpadding="3" cellspacing="0"> <tr> <td><strong>11111 | <a href="guestbook.php">Rate</a> </strong></td> </tr> </table> <br> <?php $host=localhost; // Host name $username = tony; // Mysql username $password = billy; // Mysql password $db_name = test; // Database name $tbl_name=clearbook; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); while($rows=mysql_fetch_array($result)){ ?> <?php function filter($string) { $pattern[0] = "ass"; $pattern[1] = "/badword2/"; $pattern[2] = "/badword3/"; $replacement[0] = "####"; $replacement[1] = "####"; $replacement[2] = "####"; return preg_replace($pattern, $replacement, $string); } ?> <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><?php echo $rows['id']; ?></td> </tr> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><?php echo $rows['name']; ?></td> </tr> <tr> <td valign="top">Subject</td> <td valign="top">:</td> <td><?php echo $rows['subject']; ?></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><?php echo $rows['comment']; ?></td> </tr> <tr> <td valign="top">Date/Time </td> <td valign="top">:</td> <td><?php echo $rows['datetime']; ?></td> </tr> </table></td> </tr> </table> <BR> <?php } mysql_close(); //close database ?> </body> </html> 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.