Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

form data isn't making it to the database. any help?

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
rcayea



Joined: Sun Apr 19, 2009 1:51 am
Posts: 60

PostPosted: Tue Aug 16, 2011 12:48 am    Post subject: form data isn't making it to the database. any help? Reply with quote

Hey everyone,

I am in need of that high quality help I receive when visiting this website. In short, I have a php script that is supposed to automatically submit data to a MySQL database but the data doesn't seem to make it to the database. I am not good at debugging and I am not getting any errors on the pages when I submit an entry.

Basically I have this code which takes in the information and as you know/can tell it calls on another php script to do the auto submit to the database. Here is this code:


</head>


<?php
include('../templates/bodyandlogo.htm');
?>


<?php
include('../templates/navmenu.htm');
?>
<br />
<br />


<h1>PoemScribe: Order Form</h1>
<br />
<br />
<p>Please complete the form below and click submit to order your personalized poem.</p>
<br />
<br />

<div id="form">
<form action="../php_scripts/orderform.php" method="post">

<label for="firstname">First Name:</label>
<div class="input"><input type="text" id="firstname" name="firstname" /></div><br />

<label for="lastname">Last Name:</label>
<div class="input"><input type="text" id="lastname" name="lastname" /></div><br />

<label for="email">Email:</label>
<div class="input"><input type="text" id="email" name="email" /></div><br />

<label for="selectpoemtype">Select Poem Type:<br />
4-Line Poem: $15
8-Line Poem: $25
12-Line Poem: $40
16-Line Poem: $50
20-Line Poem: $75
Please type in your desired poem length. Example: "4line".
</label><br />
<div class="input"><input type="text" id="selectpoemtype" name="selectpoemtype" /><br />

<br />
<br />

<label for="keynames">"Key names to include?"</label>
<div class="input"><input type="text" id="keynames" name="keynames"/></div><br />

<label for="specificwords">Any specific words you would like to include in your poem?</label>
<div class="input"><input type="text" id="specificwords" name="specificwords" /></div><br />

<label for="poemisfor">Who is the poem for?</label>
<div class="input"><input type="text" id="poemisfor" name="poemisfor" /></div><br />

<label for="relationship">Relationship to you?</label>
<div class="input"><input type="text" id="relationship" name="relationship" /></div><br />

<label for="occasion">What is the occasion for this poem?</label>
<div class="input"><input type="text" id="occasion" name="occasion" /></div><br />

<label for="overallmessage">What do you want the overall message of this poem to be?</label>
<div class="input"><input type="text" id="overallmessage" name="overallmessage" /></div><br />

<label for="anythingelse">Any other information you would like for me to know?</label>
<div class="input"><input type="text" id="anythingelse" name="anythingelse" /></div><br />

<div class="input"><input type="submit" value="Submit" name="submit"</div>
</form>
</div><!--form-->

<br />
<br />

<?php
include('../templates/footer.htm');




And then the code that is called on (the script called orderform.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" xml:lang="en" lang="en">
<head><title>PoemScribe Order Form</title>
</head>
<body>

<h2>PoemScribe</h2>

<?php
$email = "myemail@gmail.com"; // Email to notify on error
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];
$select_poem_type = $_POST['selectpoemtype'];
$key_names = $_POST['keynames'];
$specific_words = $_POST['specificwords'];
$poem_is_for = $_POST['poemisfor'];
$relationship = $_POST['relationship'];
$occasion = $_POST['occasion'];
$over_all_message = $_POST['overallmessage'];
$anything_else = $_POST['anythingelse'];


$dbc = mysqli_connect('localhost', 'login', 'password', 'database'); " .
or die('Error connecting to MySQL server.');

$query = INSERT INTO poem_orders '(firstname, lastname, email, selectpoemtype, keynames, specificwords, poemisfor, " .
"relationship, occasion, overallmessage, anythingelse)" .

"VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', " .
"'$relationship', '$occasion', '$over_all_message', '$anything_else')";


echo 'Thank you, ' . $firstname . $lastname;
echo 'Thanks for submitting the form.<br />';
echo ' Poem Type: ' . $selectpoemtype;
echo ' Key names to include: ' . $keynames . '<br />';
echo 'Specific Words To Include: '. $specificwords . '<br />';
echo 'Poem is for: ' . $poemisfor . '<br />';
echo 'Relationship: ' . $relationship . '<br />';
echo 'Occasion: ' . $occasion . '<br />';
echo 'Overall Message: ' . $overallmessage . '<br />';
echo 'You also added: ' . $anything_else;



mysqli_close($dbc);
?>
</body>
</html>


Again, I am trying to figure out why my database isn't being populated when someone clicks on the submit button.

Thanks in advance,
Randy
0
Back to top
View user's profile Send private message
johnhudson
LXF regular


Joined: Wed Aug 03, 2005 2:37 pm
Posts: 871

PostPosted: Tue Aug 16, 2011 7:49 am    Post subject: Reply with quote

There are some obvious imbalances of single and double quotes in the INSERT command; I also don't understand why the values are not part of the same paragraph of text.
Back to top
View user's profile Send private message
rcayea



Joined: Sun Apr 19, 2009 1:51 am
Posts: 60

PostPosted: Tue Aug 16, 2011 2:54 pm    Post subject: Reply with quote

Thanks for the reply. Here is some corrected code. It is getting better but I still get error that query wasn't successful. I fixed the quotes issue, I think.

Code:

<?php
      $email = "email@gmail.com"; // Email to notify on error
        $first_name = $_POST['firstname'];
        $last_name = $_POST['lastname'];
      $email = $_POST['email'];
      $select_poem_type = $_POST['selectpoemtype'];
      $key_names = $_POST['keynames'];
        $specific_words = $_POST['specificwords'];
      $poem_is_for = $_POST['poemisfor'];
      $relationship = $_POST['relationship'];
        $occasion  = $_POST['occasion'];
      $over_all_message = $_POST['overallmessage'];
      $anything_else = $_POST['anythingelse'];








      

$dbc = mysqli_connect('localhost', 'login', 'password', 'database')
   or die('Error connecting to MySQL server.');

$query = "INSERT INTO poem_orders (firstname, lastname, email, selectpoemtype, keynames, specificwords, poemisfor, relationship, occasion, overallmessage, anythingelse) VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', '$relationship', '$occasion', '$over_all_message', '$anything_else')";

"VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', " .
"'$relationship', '$occasion', '$over_all_message', '$anything_else')";

$insert = mysqli_query($dbc, $query);




// if query was successful, display message to user:
if($success)
{
     echo 'Thank you, ' . $firstname . $lastname;
     echo 'Thanks for submitting the form.<br />';
     echo ' Poem Type: ' . $selectpoemtype;
     echo ' Key names to include: ' . $keynames . '<br />';
     echo 'Specific Words To Include: '. $specificwords . '<br />';
     echo 'Poem is for: ' . $poemisfor . '<br />';
     echo 'Relationship: ' . $relationship . '<br />';
     echo 'Occasion: ' . $occasion . '<br />';
     echo 'Overall Message: ' . $overallmessage . '<br />';
     echo 'You also added: ' . $anything_else;
}
else
{
     echo 'Error: Query failed.';
}




mysqli_close($dbc);
   ?>
</body>
</html>


Back to top
View user's profile Send private message
bobthebob1234
LXF regular


Joined: Thu Jan 03, 2008 9:38 pm
Posts: 1369
Location: A hole in a field

PostPosted: Tue Aug 16, 2011 5:41 pm    Post subject: Reply with quote

Code:

$query = "INSERT INTO poem_orders (firstname, lastname, email, selectpoemtype, keynames, specificwords, poemisfor, relationship, occasion, overallmessage, anythingelse) VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', '$relationship', '$occasion', '$over_all_message', '$anything_else')";

"VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', " .
"'$relationship', '$occasion', '$over_all_message', '$anything_else')";


I think something is not quite right here.... if you print $query I think you will find that it just says
Code:
INSERT INTO poem_orders (firstname, lastname, email, selectpoemtype, keynames, specificwords, poemisfor, relationship, occasion, overallmessage, anythingelse) VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', '$relationship', '$occasion', '$over_all_message', '$anything_else')


I don't think that is what you want...
_________________
For certain you have to be lost to find the places that can't be found. Elseways, everyone would know where it was
Back to top
View user's profile Send private message
johnhudson
LXF regular


Joined: Wed Aug 03, 2005 2:37 pm
Posts: 871

PostPosted: Tue Aug 16, 2011 7:18 pm    Post subject: Reply with quote

Try this: I don't understand the point of the second VALUES statement and I have made one subtle change, putting the semi-colon inside the quotation marks around the query. Your previous query was incomplete because the semi-colon was not part of it.

Quote:
Code:
$query = "INSERT INTO poem_orders (firstname, lastname, email, selectpoemtype, keynames, specificwords, poemisfor, relationship, occasion, overallmessage, anythingelse) VALUES ('$first_name', '$last_name', '$email', '$select_poem_type' '$key_names', '$specific_words', '$poem_is_for', '$relationship', '$occasion', '$over_all_message', '$anything_else');"
Back to top
View user's profile Send private message
ollie
Moderator


Joined: Mon Jul 25, 2005 12:26 pm
Posts: 2749
Location: Bathurst NSW Australia

PostPosted: Wed Aug 17, 2011 3:55 am    Post subject: Reply with quote

You are also using the variable $email twice. You are setting $email to "myemail@gmail.com" and then 4 lines later setting $email to the submitted email from the form - "$email = $_POST['email'];"

Are you sure this is what you want to do?
Back to top
View user's profile Send private message
rcayea



Joined: Sun Apr 19, 2009 1:51 am
Posts: 60

PostPosted: Fri Aug 19, 2011 8:13 pm    Post subject: Reply with quote

Thanks for the tips. They helped solve the problem.
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast