Jump to content

Need help with my PHP and database issue


Big_R

Recommended Posts

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";
}
}
?>

Link to comment
Share on other sites

err? your missing part and email from your post declarations

indeed!

 

this part

if ($_POST['submit']) 
{

$date = date("Y-m-d");
$name = $_POST['name'];
$comments = $_POST['comments'];
        // you need to set the other variables here too.

Link to comment
Share on other sites

As Gristoi said, you're not setting a value to all of the variable that you're trying to insert into the database.

 

Replace:

 

$date = date("Y-m-d");
$name = $_POST['name'];
$comments = $_POST['comments'];

 

With:

 

$date = date("Y-m-d");
$name = $_POST['name'];
$email = $_POST['email'];
$song = $_POST['song'];
$part = $_POST['part'];
$comments = $_POST['comments'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.