Markota Posted January 7, 2011 Share Posted January 7, 2011 Hello! I am trying to make a Guestbook with help from the internet. I have created all sites what i need, but i have some problems with the Input. For example here is the Name inputfrom the "sign.php" <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> And here is the "insert sequence" from the "guestbook.php": $sql="INSERT INTO $tbl_name(name, email, comment, datetime) VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); If i open the guestbook.php i just can see the datetime. What went wrong? Thanks, Mark p.S.: sorry for my english. Quote Link to comment Share on other sites More sharing options...
Markota Posted January 7, 2011 Author Share Posted January 7, 2011 Hello! I am trying to make a Guestbook but. Everything works fine, but at the end i just can see the date and the id. Please help. addguestbook.php: Insert sequence <?php $host="localhost"; // Host name $username="lxxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxxx"; // Database name $tbl_name="xxxx"; // 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("d-m-y 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(); ?> viewguestbook.php: See the Guestbook <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 $host="localhost"; // Host name $username="lxxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="xxxx"; // 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>Email</td> <td>:</td> <td><? echo $rows['email']; ?></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 ?> guestbook.php: Sign in the Guestbook <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">Komment</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> Thanks, Mark Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 7, 2011 Share Posted January 7, 2011 addguestbook.php <?php $host="localhost"; // Host name $username="lxxxx"; // Mysql username $password="xxxx"; // Mysql password $db_name="xxxxx"; // Database name $tbl_name="xxxx"; // 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"); //DO NOT RELY ON GLOBALS, instead set your own variables. $name = (isset($_POST['name'])) ? mysql_real_escape_string($_POST['name']) : NULL; $email = (isset($_POST['email'])) ? mysql_real_escape_string($_POST['email']) : NULL; $comment = (isset($_POST['comment'])) ? mysql_real_escape_string($_POST['comment']) : NULL; $error = 0; //UN-COMMENT THIS BLOCK TO REQUIRE DATA// //NAME //if($name == NULL) { $error = 1; $tell[] = 'You MUST have a name!'; } //EMAIL //if($email == NULL || preg_match('~^\w+[\w-\.]*\@\w+((-\w+)|(\w*))\.[a-z]{2,3}$~',$email)) { $error = 1; $tell[] = 'Invalid email address'; } //COMMENT //if($comment == NULL) { $error = 1; $tell[] = 'Please type a comment'; } //END OF CHECKS. if($error != 0) { foreach($tell as $value) { echo $value . '<br />'; } } else { $sql="INSERT INTO $tbl_name(name, email, comment, datetime) VALUES('$name', '$email', '$comment', NOW())"; //NOW() is a database function that inserts the current timestamp. $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(); ?> Does your database table even have an 'id' column? Quote Link to comment Share on other sites More sharing options...
Markota Posted January 7, 2011 Author Share Posted January 7, 2011 yes it has. the id number can i see too. Quote Link to comment Share on other sites More sharing options...
Markota Posted January 7, 2011 Author Share Posted January 7, 2011 Thankyou!!! Now it works!!! :o ;D ;D ;) :D Quote Link to comment Share on other sites More sharing options...
shayward2003 Posted January 7, 2011 Share Posted January 7, 2011 can you show me more code... Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 7, 2011 Share Posted January 7, 2011 This has been fixed through another thread. Quote Link to comment Share on other sites More sharing options...
Markota Posted January 7, 2011 Author Share Posted January 7, 2011 How can i change the timestamp, because my regional time is other than the server time. (GMT +1) Can i change the datum format to: d-m-y ? Thanks, Mark Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 8, 2011 Share Posted January 8, 2011 No, MySQL DateTime accepts dates stored in the following format: YYYY-MM-DD HH:MM:SS. You can set MySQL's timezone for the client (if your build has a timezone table) by running a query of SET SESSION time_zone = $timezone You can pass the parameter to MySQL using PHP's date() function(if you can't by MySQL), as long as it is in the MySQL format. You can set PHP's timezone at runtime with date_default_timezone_set(). Quote Link to comment Share on other sites More sharing options...
revraz Posted January 8, 2011 Share Posted January 8, 2011 Please keep your questions to just 1 thread. 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.