Jump to content

Recommended Posts

Hi everyone,

 

I put together a php page using a variety of resources to create a form that will populate my db from a questionnaire.

 

I used a format right out of a php guidebook.  Basically I am doing everything from the one page.  php code followed by the form.  I debugged a few basic syntax errors that appeared but once i got the page to load cleanly, I entered info into the form and hit submit... and it just reloaded an empty copy of the page.  I checked the db and no info was entered.

 

I have no idea where to look for the problem without error codes... and no idea why my error handling isn't catching it.

 

Can someone more capable than me point me to the right direction here?

Would it be ok to post my code?

Link to comment
https://forums.phpfreaks.com/topic/125571-solved-lost-on-how-to-troubleshoot/
Share on other sites

Thanks.  This is the code for the page

 

<link href="qform.css" rel="stylesheet" type="text/css">

<?php #2008 survey

if (isset($_POST['submitted'])) {

$errors = array(); //initialize error array.

if (empty($_POST['burlap'])) {
$errors[] = 'You did not enter your age.';
} 

if (empty($_POST['gender'])) {
$errors[] = 'Please indicate your gender.';
} 
if (empty($_POST['primarystyle'])) {
$errors[] = 'You did not enter your primary martial art.';
} 
if (empty($_POST['yearsprimary'])) {
$errors[] = 'You did not enter the number of years training you have in your primary martial art.';
} 
if (empty($_POST['yearsgrappling'])) {
$errors[] = 'You did not enter the number of years grappling experience you have.';
} 
if (empty($_POST['weekly'])) {
$errors[] = 'Please indicate the number of weekly training sessions you participate in.';
} 
if (empty($_POST['visitorsince'])) {
$errors[] = 'Please tell us how long you have been visiting this site.';
} 
if (empty($_POST['dvdpurchase'])) {
$errors[] = 'You forgot to indicate the number of DVDs you have purchased.';
} 

if (empty($erros)){ //if all is error-free

//then let's insert to database

require_once ('../includes/mysql_connect.php');

$query = "INSERT INTO formresults (qname, qemail, qaddress, burlap, gender, primarystyle, yearsprimary, yearsgrappling, weekly, stephanquestion, visitorsince, dvdpurchase) VALUES ('qname', 'qemail', 'qaddress', 'burlap', 'gender', 'primarystyle', 'yearsprimary', 'yearsgrappling', 'weekly', 'stephanquestion', 'visitorsince', 'dvdpurchase')";
$result = @mysql_query ($query); 
if ($result) {

echo '<h1 id="mainhead"> Thank You! </h1>
<p> Your results have been included in our study.  Please enjoy the rest of your visit to grapplearts.com </p>';

exit();

} else { 

echo '<h1 id="mainhead">System Error</h1>
   <p class="error"> Your submission could not be entered due to a server error.  We apologize for the inconvenience.</p>';
   
   echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; 
   exit();
   }
   
   mysql_close();
   
   } else {
   
   echo '<h1 id="mainhead">Error!</h1>
   <p class="error">The following error(s) occured: <br />';
   foreach ($errors as $msg) {
       echo " - $msg<br />\n";
   }
   echo '</p><p>Please try again. </p><p><br /></p>';
   }
  }
  
  ?>
      
<html>



<table border="0">


<tr>
<td width=20%> </td>
<td width="60%" valign="top">

<form action="2008GrappleartsSurvey.php" method="post" name="2008q" >
<div align="center"><span class="qheading">Grapplearts 2008  Questionnaire</span></div>
<blockquote>
  <p>Thank you for taking the time to help us with our research.  The information we receive from you, the MMA community, will help 
    us ensure that we can continue to provide the best in tailored content and instructional resources on the web as well as our DVD catalogue.</p>
<p><input name="qname" type="text" size="32" maxlength="32" /><br /> Your Name (optional)</p>
<p><input name="qemail" type="text" value="" size="32" maxlength="32" /> <br /> Your Email (optional)</p>
<p><textarea name="qaddress" cols="25" rows="5"></textarea> <br /> Shipping Address (optional)</p>
<p><input name="burlap" type="text" size="32" maxlength="2" /> 
  <br /> Your Age (Ex. 24) </p>
  <p> <select name="gender">
  <p> 
  <option>  I am female  </option>
  <option selected>  I am male  </option>
  </select> <br />  Your Gender</p>
  
<p><select name="primarystyle">  
  <option selected>Please Select Best Choice</option>
  <option>Submission Wrestling</option>
    <option>Mixed Martial Arts</option>
    <option>Wrestling</option>
<option>Boxing</option>
    <option>Chinese Martial Arts (Trad.)</option>
<option>Filipino/Indonesian Martial Arts</option>
<option>Japanese Martial Arts (Traditional)</option>
    <option>JKD</option>
<option>Judo</option>
    <option>Kickboxing / Muay Thai</option>
<option>Korean Martial Arts</option>
    <option>Other</option>
  </select> <br />  Your Primary Martial Art  </p>
  
  <p>
    
    <input name="yearsprimary" type="text" id="years primary" size="32" maxlength="3" />
    <br />  Years trained in primary martial art<br />
     (Less that one year, enter 0.5)  </p>
  <p>
    
    <input name="yearsgrappling" type="text" id="years grappling" size="32" maxlength="3" /><br />  Years trained in grappling
    <br />  (Less than one year, enter 0.5  </p>
  <p>    <input name="weekly" type="text" id="years grappling" size="32" maxlength="3" /><br />  Number of weekly Martial Arts training sessions.</p>
  <p>
  <textarea name="stephanquestion" cols="25" rows="5"></textarea><br /> The single question about grappling you would most like to see Stephan Kesting answer.</p> 
  <p>  <textarea name="stephanquestion" cols="25" rows="5"></textarea><br /> The subject or topic you would most like to see covered in a future DVD release.</p> 
<p><select name="visitorsince" id="visitorsince" >
    <option selected>Joined less than one month ago</option>
    <option>one month to one year ago</option>
    <option>one year to three years ago  </option>
    <option>more than three years ago</option>
  </select> <br /> 
   I first visited grapplearts.com....</p>
  <p> <select name="dvdpurchase">  
  <option selected> One DVD </option>
  <option> Two DVDs</option>
  <option> Three DVDs</option>
  <option> Four DVDs</option>
  <option>Five DVDs </option>
  <option>Six DVDs </option>
  <option>Seven DVDs </option>
  <option>All Eight DVDs</option></select>
  
  <br />How many Grapplearts DVDs have you purchased?  (Here or elsewhere. Please enter a number)
  </p>
  
  <p>
    <input name ="submit" type="submit" value="Submit  Answers" />
    </p>
   
  <p> <input name="reset" type="reset" value="   Clear All Info   " />
  </p>
  <p> </p>
</blockquote>
  </form>  </td>
  
  <td width="20%"></td>

</tr>
</table>

</html>

Still reloads the blank form afterwards with no errors.

 

 

is the following where you wanted the second snippet?

 

 $query = "INSERT INTO formresults (qname, qemail, qaddress, burlap, gender, primarystyle, yearsprimary, yearsgrappling, weekly, stephanquestion, visitorsince, dvdpurchase) VALUES ('qname', 'qemail', 'qaddress', 'burlap', 'gender', 'primarystyle', 'yearsprimary', 'yearsgrappling', 'weekly', 'stephanquestion', 'visitorsince', 'dvdpurchase')";
$result = @mysql_query ($query)

//maq suggestion
  or die("WTF?!" . mysql_error()); 
  //maq done 2
  
if ($result) {

No, first snippet:

 

error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

if (isset($_POST['submitted'])) {

$errors = array(); //initialize error array.

if (empty($_POST['burlap'])) {

 

Second snippet like this, for every MySQL query you want to display errors (if there are any):

 

$query = "INSERT INTO formresults (qname, qemail, qaddress, burlap, gender, primarystyle, yearsprimary, yearsgrappling, weekly, stephanquestion, visitorsince, dvdpurchase) VALUES ('qname', 'qemail', 'qaddress', 'burlap', 'gender', 'primarystyle', 'yearsprimary', 'yearsgrappling', 'weekly', 'stephanquestion', 'visitorsince', 'dvdpurchase') or die(mysql_error())";

thanks.  Got it in the right spot now.

 

it returned error:

Parse error: syntax error, unexpected T_IF in /home/jgrapple/public_html/2008GrappleartsSurvey.php on line 49

 

line 49:

if ($result) {

 

in context below:

 

'yearsgrappling', 'weekly', 'stephanquestion', 'visitorsince', 'dvdpurchase') or die(mysql_error())";
$result = @mysql_query ($query)

if ($result) {

echo '<h1 id="mainhead"> Thank You! </h1>
<p> Your results have been included in our study.  Please enjoy the rest of your visit to grapplearts.com </p>';

exit();

Maq, you told him to put the or die() thing on the wrong line...  It should actually read:

 

'yearsgrappling', 'weekly', 'stephanquestion', 'visitorsince', 'dvdpurchase')";
$result = mysql_query ($query) or die(mysql_error());  //HERE

if ($result) {

echo '<h1 id="mainhead"> Thank You! </h1>
<p> Your results have been included in our study.  Please enjoy the rest of your visit to grapplearts.com </p>';

exit();

 

Also, remove every single @ in your code before a function name.

Maq, you told him to put the or die() thing on the wrong line...

 

I wouldn't call it wrong, you can put it on that line and it will still return error feedback.

 

maddcow26, glad I could help, let me know if the fixes DarkWater and I posted got your script to work.

 

 

changed the code to DarkWater's suggestion. 

 

I still get the blank form on submit and no info is being written to the db

 

 



<link href="qform.css" rel="stylesheet" type="text/css">

<?php #2008 survey
// maq suggestion
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
//maq done 1

if (isset($_POST['submitted'])) {

$errors = array(); //initialize error array.

if (empty($_POST['burlap'])) {
$errors[] = 'You did not enter your age.';
} 

if (empty($_POST['gender'])) {
$errors[] = 'Please indicate your gender.';
} 
if (empty($_POST['primarystyle'])) {
$errors[] = 'You did not enter your primary martial art.';
} 
if (empty($_POST['yearsprimary'])) {
$errors[] = 'You did not enter the number of years training you have in your primary martial art.';
} 
if (empty($_POST['yearsgrappling'])) {
$errors[] = 'You did not enter the number of years grappling experience you have.';
} 
if (empty($_POST['weekly'])) {
$errors[] = 'Please indicate the number of weekly training sessions you participate in.';
} 
if (empty($_POST['visitorsince'])) {
$errors[] = 'Please tell us how long you have been visiting this site.';
} 
if (empty($_POST['dvdpurchase'])) {
$errors[] = 'You forgot to indicate the number of DVDs you have purchased.';
} 

if (empty($erros)){ //if all is error-free

//then let's insert to database

require_once ('../includes/mysql_connect.php');

$query = "INSERT INTO formresults (qname, qemail, qaddress, burlap, gender, primarystyle, yearsprimary, yearsgrappling, weekly, stephanquestion, visitorsince, dvdpurchase) VALUES ('qname', 'qemail', 'qaddress', 'burlap', 'gender', 'primarystyle', 'yearsprimary', 'yearsgrappling', 'weekly', 'stephanquestion', 'visitorsince', 'dvdpurchase')";
$result = mysql_query ($query) or die(mysql_error());  //HERE

if ($result) {

echo '<h1 id="mainhead"> Thank You! </h1>
<p> Your results have been included in our study.  Please enjoy the rest of your visit to grapplearts.com </p>';

exit();

} else { 

echo '<h1 id="mainhead">System Error</h1>
   <p class="error"> Your submission could not be entered due to a server error.  We apologize for the inconvenience.</p>';
   
   echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; 
   exit();
   }
   
   mysql_close();
   
   } else {
   
   echo '<h1 id="mainhead">Error!</h1>
   <p class="error">The following error(s) occured: <br />';
   foreach ($errors as $msg) {
       echo " - $msg<br />\n";
   }
   echo '</p><p>Please try again. </p><p><br /></p>';
   }
  }
  
  ?>
      
<html>



<table border="0">


<tr>
<td width=20%> </td>
<td width="60%" valign="top">

<form action="2008GrappleartsSurvey.php" method="post" name="2008q" >
<div align="center"><span class="qheading">Grapplearts 2008  Questionnaire</span></div>
<blockquote>
  <p>Thank you for taking the time to help us with our research.  The information we receive from you, the MMA community, will help 
    us ensure that we can continue to provide the best in tailored content and instructional resources on the web as well as our DVD catalogue.</p>
<p><input name="qname" type="text" size="32" maxlength="32" /><br /> Your Name (optional)</p>
<p><input name="qemail" type="text" value="" size="32" maxlength="32" /> <br /> Your Email (optional)</p>
<p><textarea name="qaddress" cols="25" rows="5"></textarea> <br /> Shipping Address (optional)</p>
<p><input name="burlap" type="text" size="32" maxlength="2" /> 
  <br /> Your Age (Ex. 24) </p>
  <p> <select name="gender">
  <p> 
  <option>  I am female  </option>
  <option selected>  I am male  </option>
  </select> <br />  Your Gender</p>
  
<p><select name="primarystyle">  
  <option selected>Please Select Best Choice</option>
  <option>Submission Wrestling</option>
    <option>Mixed Martial Arts</option>
    <option>Wrestling</option>
<option>Boxing</option>
    <option>Chinese Martial Arts (Trad.)</option>
<option>Filipino/Indonesian Martial Arts</option>
<option>Japanese Martial Arts (Traditional)</option>
    <option>JKD</option>
<option>Judo</option>
    <option>Kickboxing / Muay Thai</option>
<option>Korean Martial Arts</option>
    <option>Other</option>
  </select> <br />  Your Primary Martial Art  </p>
  
  <p>
    
    <input name="yearsprimary" type="text" id="years primary" size="32" maxlength="3" />
    <br />  Years trained in primary martial art<br />
     (Less that one year, enter 0.5)  </p>
  <p>
    
    <input name="yearsgrappling" type="text" id="years grappling" size="32" maxlength="3" /><br />  Years trained in grappling
    <br />  (Less than one year, enter 0.5  </p>
  <p>    <input name="weekly" type="text" id="years grappling" size="32" maxlength="3" /><br />  Number of weekly Martial Arts training sessions.</p>
  <p>
  <textarea name="stephanquestion" cols="25" rows="5"></textarea><br /> The single question about grappling you would most like to see Stephan Kesting answer.</p> 
  <p>  <textarea name="stephanquestion" cols="25" rows="5"></textarea><br /> The subject or topic you would most like to see covered in a future DVD release.</p> 
<p><select name="visitorsince" id="visitorsince" >
    <option selected>Joined less than one month ago</option>
    <option>one month to one year ago</option>
    <option>one year to three years ago  </option>
    <option>more than three years ago</option>
  </select> <br /> 
   I first visited grapplearts.com....</p>
  <p> <select name="dvdpurchase">  
  <option selected> One DVD </option>
  <option> Two DVDs</option>
  <option> Three DVDs</option>
  <option> Four DVDs</option>
  <option>Five DVDs </option>
  <option>Six DVDs </option>
  <option>Seven DVDs </option>
  <option>All Eight DVDs</option></select>
  
  <br />How many Grapplearts DVDs have you purchased?  (Here or elsewhere. Please enter a number)
  </p>
  
  <p>
    <input name ="submit" type="submit" value="Submit  Answers" />
    </p>
   
  <p> <input name="reset" type="reset" value="   Clear All Info   " />
  </p>
  <p> </p>
</blockquote>
  </form>  </td>
  
  <td width="20%"></td>

</tr>
</table>

</html>

You bet, thanks for looking:

 



<link href="qform.css" rel="stylesheet" type="text/css">

<?php #2008 survey

ini_set('display_errors', 1);
error_reporting(E_ALL);


if (isset($_POST['submitted'])) {

$errors = array(); //initialize error array.

if (empty($_POST['burlap'])) {
$errors[] = 'You did not enter your age.';
} 

if (empty($_POST['gender'])) {
$errors[] = 'Please indicate your gender.';
} 
if (empty($_POST['primarystyle'])) {
$errors[] = 'You did not enter your primary martial art.';
} 
if (empty($_POST['yearsprimary'])) {
$errors[] = 'You did not enter the number of years training you have in your primary martial art.';
} 
if (empty($_POST['yearsgrappling'])) {
$errors[] = 'You did not enter the number of years grappling experience you have.';
} 
if (empty($_POST['weekly'])) {
$errors[] = 'Please indicate the number of weekly training sessions you participate in.';
} 
if (empty($_POST['visitorsince'])) {
$errors[] = 'Please tell us how long you have been visiting this site.';
} 
if (empty($_POST['dvdpurchase'])) {
$errors[] = 'You forgot to indicate the number of DVDs you have purchased.';
} 

if (empty($errors)){ //if all is error-free

//then let's insert to database

require_once ('../includes/mysql_connect.php');

$query = "INSERT INTO formresults (qname, qemail, qaddress, burlap, gender, primarystyle, yearsprimary, yearsgrappling, weekly, stephanquestion, visitorsince, dvdpurchase) VALUES ('qname', 'qemail', 'qaddress', 'burlap', 'gender', 'primarystyle', 'yearsprimary', 'yearsgrappling', 'weekly', 'stephanquestion', 'visitorsince', 'dvdpurchase')";
$result = mysql_query ($query) or die(mysql_error());  //HERE

if ($result) {

echo '<h1 id="mainhead"> Thank You! </h1>
<p> Your results have been included in our study.  Please enjoy the rest of your visit to grapplearts.com </p>';

exit();

} else { 

echo '<h1 id="mainhead">System Error</h1>
   <p class="error"> Your submission could not be entered due to a server error.  We apologize for the inconvenience.</p>';
   
   echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; 
   exit();
   }
   
   mysql_close();
   
   } else {
   
   echo '<h1 id="mainhead">Error!</h1>
   <p class="error">The following error(s) occured: <br />';
   foreach ($errors as $msg) {
       echo " - $msg<br />\n";
   }
   echo '</p><p>Please try again. </p><p><br /></p>';
   }
  }
  
  ?>
      
<html>



<table border="0">


<tr>
<td width=20%> </td>
<td width="60%" valign="top">

<form action="2008GrappleartsSurvey.php" method="post" name="2008q" >
<div align="center"><span class="qheading">Grapplearts 2008  Questionnaire</span></div>
<blockquote>
  <p>Thank you for taking the time to help us with our research.  The information we receive from you, the MMA community, will help 
    us ensure that we can continue to provide the best in tailored content and instructional resources on the web as well as our DVD catalogue.</p>
<p><input name="qname" type="text" size="32" maxlength="32" /><br /> Your Name (optional)</p>
<p><input name="qemail" type="text" value="" size="32" maxlength="32" /> <br /> Your Email (optional)</p>
<p><textarea name="qaddress" cols="25" rows="5"></textarea> <br /> Shipping Address (optional)</p>
<p><input name="burlap" type="text" size="32" maxlength="2" /> 
  <br /> Your Age (Ex. 24) </p>
  <p> <select name="gender">
  <p> 
  <option>  I am female  </option>
  <option selected>  I am male  </option>
  </select> <br />  Your Gender</p>
  
<p><select name="primarystyle">  
  <option selected>Please Select Best Choice</option>
  <option>Submission Wrestling</option>
    <option>Mixed Martial Arts</option>
    <option>Wrestling</option>
<option>Boxing</option>
    <option>Chinese Martial Arts (Trad.)</option>
<option>Filipino/Indonesian Martial Arts</option>
<option>Japanese Martial Arts (Traditional)</option>
    <option>JKD</option>
<option>Judo</option>
    <option>Kickboxing / Muay Thai</option>
<option>Korean Martial Arts</option>
    <option>Other</option>
  </select> <br />  Your Primary Martial Art  </p>
  
  <p>
    
    <input name="yearsprimary" type="text" id="years primary" size="32" maxlength="3" />
    <br />  Years trained in primary martial art<br />
     (Less that one year, enter 0.5)  </p>
  <p>
    
    <input name="yearsgrappling" type="text" id="years grappling" size="32" maxlength="3" /><br />  Years trained in grappling
    <br />  (Less than one year, enter 0.5  </p>
  <p>    <input name="weekly" type="text" id="years grappling" size="32" maxlength="3" /><br />  Number of weekly Martial Arts training sessions.</p>
  <p>
  <textarea name="stephanquestion" cols="25" rows="5"></textarea><br /> The single question about grappling you would most like to see Stephan Kesting answer.</p> 
  <p>  <textarea name="stephanquestion" cols="25" rows="5"></textarea><br /> The subject or topic you would most like to see covered in a future DVD release.</p> 
<p><select name="visitorsince" id="visitorsince" >
    <option selected>Joined less than one month ago</option>
    <option>one month to one year ago</option>
    <option>one year to three years ago  </option>
    <option>more than three years ago</option>
  </select> <br /> 
   I first visited grapplearts.com....</p>
  <p> <select name="dvdpurchase">  
  <option selected> 1 </option>
  <option> 2</option>
  <option> 3</option>
  <option> 4</option>
  <option>5 </option>
  <option>6 </option>
  <option>7 </option>
  <option>8</option></select>
  
  <br />How many Grapplearts DVDs have you purchased?  (Here or elsewhere. Please enter a number)
  </p>
  
  <p>
    <input name ="submit" type="submit" value="Submit  Answers" />
    </p>
   
  <p> <input name="reset" type="reset" value="   Clear All Info   " />
  </p>
  <p> </p>
</blockquote>
  </form>  </td>
  
  <td width="20%"></td>

</tr>
</table>

</html>

Ok, finally got the error issue squared away.  The problem was related to my submit button.  I was posting 'submit' but looking for post 'submitted.'

 

It's now picking up errors and telling visitors to fill out necessary fields if they miss them.  Unfortunately, when you fill it out properly, I get the error: 

Could not connect to MySQL: Access denied for user 'username'@'localhost' (using password: YES)

 

I have it set to look to a separate file for the connection info

require_once ('../includes/mysql_connect.php');

 

this line is right above my insert.

 

anyone see anything wrong with that?

 

the info in the mysql_connect.php file is correct with the actual user and password

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.