Jump to content

Big_R

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Everything posted by Big_R

  1. Thank you so much. Sorry for my nievity. I'm very new to php and head been following a tutorial.
  2. okay I redid my guestbook (yet again) and it is technically function how ever some of the variables are not being placed in the database and therefore not being displayed after the form is submitted When some one fills out the form and presses "submit" the name and comments are being placed in the database and displayed on the page but the email, song, and part art not being placed in the data base or displayed. So for example if someone comes in and fills out the form like this: Your name: Bob Email Address: bob@bobs.com Your Favorite Pat Song?: all Your Favorite Part of my Site?: the galleries Comments: Testing 1 2 3 and presses submit it looks like this: Posted by Bob () 05/18/2011 Favorite Pat Song: Favorite Part of the Site: Testing 1 2 3 it does not post the email in the brackets next to the name like it should, It does not post the song they liked, it does not post the part of the site they like the most but it does post the name and comments. I check the database and it doesn't even put the email, favorite song or favorite part of the site into the database. Why is it that it'll display the name and comments fine (and put them in the database) but it won't do so for the other 3 fields....? I don't get it... What am I doing wrong? Here's the form: <form name="guestbook" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table width="545" border="0" cellspacing="2" cellpadding="0"> <tr valign="top"> <td width="215" class="what"><span style="color:#ff0000"><b>*</b></span>Your Name:</td> <td width="500"> <input name="name" type="text" id="name" name="name" size="32" maxlength="90" /> </td> </tr> <tr valign="top"> <td width="215" class="what"><span style="color:#ff0000"><b>*</b></span>Email Address:</td> <td width="500"> <input name="email" type="text" id="email" size="32" maxlength="125" /> </td> </tr> <tr valign="top"> <td width="215" class="what">Your Favorite Pat Song?:</td> <td width="500"> <input name="song" type="text" id="song" size="32" maxlength="125" /></td> </tr> <tr valign="top"> <td width="290" class="what">Your Favorite Part of my Site?:</td> <td width="500"> <input name="part" type="text" id="part" size="32" maxlength="125" /> </td> </tr><tr valign="top"> <td width="215" class="what"><span style="color:#ff0000"><b>*</b></span> Comment:</td> <td width="500"> <textarea name="comments" cols="28" rows="6" id="comments" name="comments" class="bodytext"></textarea></td> </tr> <tr> <td class="bodytext"> </td> <td align="left" valign="top"><input name="submit" type="submit" class="btn" value="Sign" /></td> </tr> </table> </form> and here's the PHP: <?php //connecting to the Database $connect = mysql_connect("127.0.0.1","patben_admin","pepsi_1990") or die("Error"); //selecting the table mysql_select_db("patben_db") or die("Error"); //selecting ALL data $queryget = mysql_query("SELECT * FROM guestbook") or die("Error"); //sort the data while($row = mysql_fetch_array($queryget)) { $id = $row['id']; $date = $row['date']; $name = $row['name']; $email = $row['email']; $song = $row['song']; $part = $row['part']; $comments = $row['comments']; //processing data echo " <table id='gb'> <tr> <td> <b>Posted by:</b> $name ($email)<br /> <b>$date</b><br /> <b>Favorite Pat Song:</b> $song<br /> <b>Favorite Part of the Site:</b> $part </td> </tr> <tr> <td> ".nl2br(strip_tags($comments))." <hr /> </td> </tr> </table> "; } if ($_POST['submit']) { $date = date("Y-m-d"); $name = $_POST['name']; $comments = $_POST['comments']; if ($name&&$comments) { $queryget = mysql_query("INSERT INTO guestbook (id,date, name, email, song, part, comments) VALUES ('','$date','$name','$email','$song','$part','$comments')"); echo "<p>Please wait... <meta http-equiv='refresh' content='2'></p>"; echo mysql_error(); }else{ echo "Please enter your name and comments"; } } ?>
  3. okay I added the validation script suggested and I have no idea why I am getting this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 62 It's probably something I did stupid, what am I doing wrong? I added the "private" field to my database, its a tinyint data type. Is that the write data type? Thank you for all the help and thank you in advance. my edited guestbook script: <?php $error = array(); if(isset($_GET['page'])) { echo " <span style='color:#ff0000'><b>*</b></span><span> = required field</span><br /><br /> <form name='guestbook' action='process.php' method='post'> <table width='550' border='0' cellspacing='2' cellpadding='0'> <tr valign='top'> <td width='550px' class='what'><span style='color:#ff0000'><b>*</b></span> Your Name:</td> <td width='550px'><input name='name' type='text' id='name' size='32' /><?php if (empty(!$_POST['name'])) { $error[] = "Please enter your name"; } ?></td> </tr> <tr valign='top'> <td width='550px' class='what'><span style='color:#ff0000'><b>*</b></span> Email Address</td> <td width='550px'><input name='email' type='text' id='email' size='32' />if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {$error[] = "The email address you have entered is invalid!";} <input type='checkbox' name='private' value='private' />Keep Private</td> </tr> <tr valign='top'> <td width='550px' class='what'>Your Favorite Pat Song?:</td> <td width='550px'><input name='song' type='text' id='song' size='32' /></td> </tr> <tr valign='top'> <td width='550px' class='what'>Your Favorite Part of my Site?:</td> <td width='550px'><input name='part' type='text' id='part' size='32' /></td> </tr> <tr valign='top'> <td width='550px' class='what'><span style='color:#ff0000'><b>*</b></span> Comment:</td> <td width='550px'><textarea name='comments' cols='28' rows='6' id='comments' class='bodytext'><?php if (empty(!$_POST['comments'])) { $error[] = "Please enter a comment"; } ?></textarea></td> </tr> <tr> <td class='bodytext'> </td> <td align='left' valign='top'><input name='submit' type='submit' class='btn' value='Sign' /></td> </tr> </table> </form>"; }else{ $connect = mysql_connect("127.0.0.1","patben_admin","pepsi_1990") or die('Error connecting'); $db = mysql_select_db("patben_db") or die('Error selecting db'); $query = mysql_query("SELECT * FROM guestbook order by id desc"); $num_rows = mysql_num_rows($query); if($num_rows > 0) { //display entries while($row = mysql_fetch_array($query)){ echo ' <table> <tr> <td> <b>Posted by:</b> '.$row['name'].' if ($private == "yes"){ echo "Private"; } else { echo "$email"; }<br /> <b>'.$row['date'].'</b><br /> <b>Favorite Pat Song:</b> if (empty($_POST['song'])) { $song = "--"; } else { $song = $_POST['song']; } <b>Favorite Part of the Site:</b> if (empty($_POST['part'])) { $part = "--"; } else { $part = $_POST['part]; } </td> </tr> <tr> <td> '.nl2br($row['comments']).' <hr /> </td> </tr> </table>'; } }else{ echo "No Entries... <a href='guestbook.php?page=sign'>Be the first!</a>"; } } ?> and my edited data processing script to put form input into the database (separate file): <?php if($_POST['submit']) { $connect = mysql_connect('127.0.0.1','patben_admin','pepsi_1990') or die('Error connecting'); $db = mysql_select_db('patben_db') or die('Error selecting db'); $date = date("Y-m-d"); $name = strip_tags($_POST['name']); $email = strip_tags($_POST['email']); $song = strip_tags($_POST['song']); $part = strip_tags($_POST['part']); private='$private' $comments = nl2br($_POST['comments']); if (empty($error)) { mysql_query("insert into guestbook values('','$date','$name','$email','$song','$part','$comments')"); header("location: guestbook.php");} if (isset($_POST['private'])){ $private = "yes"; } else { $private = "no"; } else { echo implode($error); }else{ header("location: guestbook.php"); } ?> any help will be greatly appriciated!
  4. thank you for all your help, I look forward to trying this. I just have 2 quick questions 1. What data type would the field "private" need to be in my data base? 2. Since my form is already in <?php ?> tags and just echoed out than do I have to put the <?php ?> tags around the bits you add for the error messages like this: <td width='550px'><input name='name' type='text' id='name' size='32' /><?php if (empty(!$_POST['field_name'])) { $error[] = "Please enter your name"; } ?></td> or do I leave those tags out since the entire form is already wrapped in <?php ?> tags? thank you again.
  5. Okay with some help I was able to create a working guestbook! How ever I need a bit of help with validation. I would like to have it so that when someone doesn't fill out a required field a message is displayed next to the improperly filled out field. How would I go about adding this to my form or process code? So for example: if someone doesn't fill out the "name" field and clicks "sign" it will not submit but instead will display a message such as "Please fill out your name" next to the form field. Also will I am here I wanted to ask. How can I make it so that when a non-required field is left empty and posted it will fill that section out with default text? So for example: if someone decides they do not wish to fill out the "Favorite part of my site" or "Favorite Pat Song" field than submits the form than it will fill that section with a default message like this: Posted by: someone (someone@domain.com) 2011/04/09 Favorite Pat Song: -- Favorite Part of the Site: -- comments here And I promise this is my very last question. I would like for email to be required but would like to allow the user to decide whether it is kept private or not. How do I make it so that when someone doesn't type their email in it does like what I stated above, it will show a message next to the field telling them to fill out a valid email but also if they select to keep their email private it will than post a default value in place of where the email would have been. for example: if the email field is left empty or is an invalid email it will display a message such as "Please fill out a valid email address" next to the form field. and than if they do so but also check the "private" box it will post their message in the guestbook with a default value in place of the email like this: Posted by: someone (Private) 2011/04/09 Favorite Pat Song: -- Favorite Part of the Site: -- comments here so that was a lot here's my guestbook code: <?php <span style='color:#ff0000'><b>*</b></span><span> = required field</span><br /><br /> <form name='guestbook' action='process.php' method='post'> <table width='550' border='0' cellspacing='2' cellpadding='0'> <tr valign='top'> <td width='550px' class='what'><span style='color:#ff0000'><b>*</b></span> Your Name:</td> <td width='550px'><input name='name' type='text' id='name' size='32' /></td> </tr> <tr valign='top'> <td width='550px' class='what'><span style='color:#ff0000'><b>*</b></span> Email Address:</td> <td width='550px'><input name='email' type='text' id='email' size='32' /><input type='checkbox' name='private' value='Private' />Private</td> </tr> <tr valign='top'> <td width='550px' class='what'>Your Favorite Pat Song?:</td> <td width='550px'><input name='song' type='text' id='song' size='32' /></td> </tr> <tr valign='top'> <td width='550px' class='what'>Your Favorite Part of my Site?:</td> <td width='550px'><input name='part' type='text' id='part' size='32' /></td> </tr> <tr valign='top'> <td width='550px' class='what'><span style='color:#ff0000'><b>*</b></span> Comment:</td> <td width='550px'><textarea name='comments' cols='28' rows='6' id='comments' class='bodytext'></textarea></td> </tr> <tr> <td class='bodytext'> </td> <td align='left' valign='top'><input name='submit' type='submit' class='btn' value='Sign' /></td> </tr> </table> </form>"; }else{ $connect = mysql_connect("127.0.0.1","patben_admin","pepsi_1990") or die('Error connecting'); $db = mysql_select_db("patben_db") or die('Error selecting db'); $query = mysql_query("SELECT * FROM guestbook order by id desc"); $num_rows = mysql_num_rows($query); if($num_rows > 0) { //display entries while($row = mysql_fetch_array($query)){ echo ' <table> <tr> <td> <b>Posted by:</b> '.$row['name'].' ('.$row['email'].')<br /> <b>'.$row['date'].'</b><br /> <b>Favorite Pat Song:</b> '.$row['song'].'<br /> <b>Favorite Part of the Site:</b> '.$row['part'].' </td> </tr> <tr> <td> '.nl2br($row['comments']).' <hr /> </td> </tr> </table>'; } }else{ echo "No Entries... <a href='guestbook.php?page=sign'>Be the first!</a>"; } } ?> and here's the code that processes the form (separate file): <?php if($_POST['submit']) { $connect = mysql_connect('127.0.0.1','patben_admin','pepsi_1990') or die('Error connecting'); $db = mysql_select_db('patben_db') or die('Error selecting db'); $date = date("Y-m-d"); $name = strip_tags($_POST['name']); $email = strip_tags($_POST['email']); $song = strip_tags($_POST['song']); $part = strip_tags($_POST['part']); $comments = nl2br($_POST['comments']); $query = mysql_query("insert into guestbook values('','$date','$name','$email','$song','$part','$comments')"); header("location: guestbook.php"); }else{ header("location: guestbook.php"); } ?> I have not added a section in my database for the check box so I am also unsure how to do that (if I need to). Any help would be greatly appreciated! Thank you
  6. Okay I am extremely new to PHP and am trying to make a 2 page guestbook, where one page has the form to submit a message to the guestbook and the other page displays the messages. However I am having some errors, one being that when I submit a test message it still shows the "please enter your name and comments" thing I have set when people don't fill the required fields. The other error I'm having is if I put two test messages into the guestbook some of the info from the last message fills in the fields of the other one instead of what was actually filled into the form. For example, if I insert the name "Pat" and the comment "testing 1 2 3" into one message and than insert the name "Bob" and the comment "hi" for another message when I submit the second message it may instead of putting "hi" it'll put "testing 1 2 3" so I get: Posted by: Pat testing 1 2 3 ________________ Posted by: Bob testing 1 2 3 instead of: Posted by: Pat testing 1 2 3 ________________ Posted by: Bob hi Like it should.... What am I doing wrong???? My PHP code for submition is: <?php //connecting to the Database $connect = mysql_connect("127.0.0.1","patben_guestbook","") or die("Error"); //selecting the table mysql_select_db("patben_guestbookdatabase") or die("Error"); //selecting ALL data $queryget = mysql_query("SELECT * FROM guestbook") or die("Error"); //sort the data while ($row = mysql_fetch_assoc($queryget)) { $id = $row['id']; $date = $row['date']; $name = $row['name']; $email = $row['email']; $song = $row['song']; $part = $row['part']; $comments = $row['comments']; //processing data echo " <table> <tr> <td> <b>Posted by:</b> $name ($email)<br /> <b>$date</b><br /> <b>Favorite Pat Song:</b> $song<br /> <b>Favorite Part of the Site:</b> $part </td> </tr> <tr> <td> ".nl2br(strip_tags($comments))." <hr /> </td> </tr> </table> "; } if ($_POST['submit']); { $date = date("Y-m-d"); $name = $_POST['name']; $comments = $_POST['comments']; if ($name&&$comments) { $queryget = mysql_query("INSERT INTO guestbook (id,date, name, email, song, part, comments) VALUES ('','$date','$name','$email','$song','$part','$comments')"); echo "Please wait... <meta http-equiv='refresh' content='2'>"; echo mysql_error(); } else echo "Please enter your name and comments"; } ?> And my HTML form is: <form action="process.php" method="post"> <table width="500" border="0" cellspacing="2" cellpadding="0"> <tr valign="top"> <td width="500px" class="name"><span style="color:#ff0000"><b>*</b></span>Name:</td> <td width="500px"><input name="name" type="text" id="name" size="32" /></td> </tr> <tr valign="top"> <td width="500px" class="bodytext"> Email Address:</td> <td width="500px"><input name="email" type="text" id="email" size="32" /></td> </tr> <tr valign="top"> <td width="500px" class="pat"> Your Favorite Pat Song?:</td> <td width="500px"><input name="song" type="text" id="song" size="32" /></td> </tr> <tr valign="top"> <td width="500px" class="part"> Your Favorite Part of my Site?:</td> <td width="500px"><input name="part" type="text" id="part" size="32" /></td> </tr> <tr valign="top"> <td width="500px" class="comments"><span style="color:#ff0000"><b>*</b></span> Comment:</td> <td width="500px"><textarea name="comments" id="comments" cols="28" rows="6" class="comments"></textarea></td> </tr> <tr valign="top"> <td class="bodytext"> </td> <td align="left" valign="top"><input type="submit" name="Submit" value="Post" class="btn" /></td> </tr> </table> </form>
×
×
  • 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.