 |
Linux Format forums Help, discussion, magazine feedback and more
|
| View previous topic :: View next topic |
| Author |
Message |
rcayea
Joined: Sun Apr 19, 2009 1:51 am Posts: 60
|
Posted: Tue Aug 16, 2011 12:48 am Post subject: form data isn't making it to the database. any help? |
|
|
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 |
|
 |
johnhudson LXF regular
Joined: Wed Aug 03, 2005 2:37 pm Posts: 767
|
Posted: Tue Aug 16, 2011 7:49 am Post subject: |
|
|
| 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 |
|
 |
rcayea
Joined: Sun Apr 19, 2009 1:51 am Posts: 60
|
Posted: Tue Aug 16, 2011 2:54 pm Post subject: |
|
|
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 |
|
 |
bobthebob1234 LXF regular

Joined: Thu Jan 03, 2008 9:38 pm Posts: 1356 Location: A hole in a field
|
Posted: Tue Aug 16, 2011 5:41 pm Post subject: |
|
|
| 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 |
|
 |
johnhudson LXF regular
Joined: Wed Aug 03, 2005 2:37 pm Posts: 767
|
Posted: Tue Aug 16, 2011 7:18 pm Post subject: |
|
|
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 |
|
 |
ollie Moderator

Joined: Mon Jul 25, 2005 12:26 pm Posts: 2749 Location: Bathurst NSW Australia
|
Posted: Wed Aug 17, 2011 3:55 am Post subject: |
|
|
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 |
|
 |
rcayea
Joined: Sun Apr 19, 2009 1:51 am Posts: 60
|
Posted: Fri Aug 19, 2011 8:13 pm Post subject: |
|
|
| Thanks for the tips. They helped solve the problem. |
|
| Back to top |
|
 |
| View previous topic :: View next topic |
|
|
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
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|