Jump to content


Photo

Help with form


  • Please log in to reply
9 replies to this topic

#1 Bee

Bee
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 13 May 2006 - 10:31 AM

Hi,

Does anyone know what's wrong with this form please? It should write data to a database; however, it doesn't.


<html>
<head>
<title>order website</title>
</head>

<body>
<?php

//$Send = $_GET['Send']; 

if ($Send) {

  // process form

  $db = mysql_connect("localhost", "root", ""); if($db == false) echo "Failed to connect!"; 
  
 if(mysql_select_db("aimredaco",$db)== false) echo "Failed to select database!"; 

  $sql = "INSERT INTO orders (order_ID, name, email, company_name, address, post_code, city, tel, mobile, website, redesign_website, website_to_redesign, no_pages, web_design, flash_graphics, flash_programming, programming, shopping_cart, comments) VALUES (NULL, '$name', '$email', '$company_name', '$address', '$post_code', '$city', '$tel', '$mobile', '$website', '$redesign_website', '$website_to_redesign', '$no_pages', '$web_design', '$flash_graphics', '$flash_programming', '$programming', '$shopping_cart', '$comments')";

  $result = mysql_query($sql);

  echo "Thank you! Information entered.\n";

} else{



  // display form

?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table width="100%" height="0%" border="1" cellpadding="0" cellspacing="0" bordercolor="#999999">
  <tr> 
    <td height="833"> 
    
    <!-- inside table header -->
      <table width="100%" height="0%"  border="0" align="center" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
        <tr> 
          <td height="2%" colspan="2" valign="middle" background="company/images/index_15.gif" bgcolor="#EFEFEF"><strong><font color="#333333">Order 
            your website</font></strong></td>
        </tr>
        <tr> 
          <td height="5%" colspan="2" valign="middle" bgcolor="#EFEFEF"> 
            <p>If you are interested in our services then please fill out the form below to request a quote.</p>
            <p><br>
            </p></td>
        </tr>
        <tr>
        
        <!-- text boxes --> 
          <td width="47%" height="2%" valign="middle" bgcolor="#EFEFEF"> 
            <div align="right"> 
              <div align="right">*Name:</div>
            </div></td>
          <td width="53%" bgcolor="#EFEFEF"><span> 
            <input name="name" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr> 
          <td width="47%" valign="middle" bgcolor="#EFEFEF"><div align="right"> 
              <div align="right">*Email:</div>
            </div></td>
          <td width="53%" height="2%" bgcolor="#EFEFEF" class="style112"><span class="formName style45"> 
            <input name="email" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr bgcolor="#FFFFFF" class="style112"> 
          <td width="47%" height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style182"> 
              <div align="right" class="style174">Company:</div>
            </div></td>
          <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> 
            <input name="company_name" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr> 
          <td width="47%" bgcolor="#EFEFEF" class="style112"><div align="right" class="style183"><span class="style174">Address:</span></div></td>
          <td width="53%" height="2%" bgcolor="#EFEFEF"><span class="formName style45"> 
            <input name="address" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr class="style112"> 
          <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Postcode:</span></div></td>
          <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> 
            <input name="post_code" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr> 
          <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">City: 
              </span></div></td>
          <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> 
            <input name="city" class="style174" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr class="style112"> 
          <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Telephone:</span></div></td>
          <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> 
            <input name="tel" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr class="style112"> 
          <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Mobile: 
              </span></div></td>
          <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> 
            <input name="mobile" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!--------------------->
        <tr class="style112"> 
          <td height="2%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">Website:</span></div></td>
          <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> 
            <input name="website" style="VERTICAL-ALIGN: middle" size="35" />
            </span></td>
        </tr>
        
        <!-- radio buttons>
        <tr class="style112"> 
          <td height="8%" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">What service would you like us to offer?</span></div></td>
          <td width="53%" bgcolor="#EFEFEF" class="style112 style150"><span class="formName style45"> 
            <input onClick="" type="radio" checked="checked" value="y" name="redesign_website" /><span class="style174">Redesign website</span> <span class="style180"><br />
            <input onClick="" type="radio" value="n" name="redesign_website" /><span>New website design</span></span></span><span class="formName style180"><br />
            <br />
            
            <!-- text box -->
            </span><span class="style174">If you choose redesign option, what's your website's address?&nbsp;</span><span class="style178">&nbsp; 
            </span><span class="formName style45"> 
            <input name="website_to_redesign" style="VERTICAL-ALIGN: middle" value="http://" size="60" />
            </span></td>
        </tr>
        
        <!-- combobox -->
        <tr> 
          <td height="30" bgcolor="#EFEFEF"> <div align="right"><span>Approximately how many pages do you anticipate the site having?</span></div></td>
          <td width="53%" bgcolor="#EFEFEF"><span> 
            <select style="VERTICAL-ALIGN: middle" name="no_pages">
              <option value="">Please select an option.</option>
              <option value="1">1 page</option>
              <option value="2to5">2-5 pages</option>
              <option value="5to10">5-10 pages</option>
              <option value="10+">10+</option>
            </select>
            </span></td>
        </tr>
        
        <!-- checkboxes -->
        <tr class="style112"> 
          <td height="139" bgcolor="#EFEFEF" class="style112"> <div align="right" class="style183"><span class="style174">What services are you interested in? (Check all that apply)</span></div></td>
          <td width="53%" valign="baseline" bgcolor="#EFEFEF" class="style112 style180"><dl>
              <dt><span class="formName "> 
                <input type="checkbox" value="y" name="web_design" />
                </span><span class="style179">Web Design</span></dt><dt>
                <span class="style179"> 
                <input type="checkbox" value="y" name="flash_graphics" />Flash Graphics</span> </dt>
              <dt> 
                <input type="checkbox" value="y" name="flash_programming" />Flash Programming<br />
                <input type="checkbox" value="y" name="programming" />Programming<br />
                <input type="checkbox" value="y" name="shopping_cart" />Shopping cart </dt>
            </dl></td>
        </tr>
        
        <!-- comments textbox -->
        <tr> 
          <td height="21%" bgcolor="#EFEFEF"> <div align="right"><span>Questions & comments:</span></div></td>
          <td width="53%" bgcolor="#EFEFEF"><span> 
            <textarea name="comments" cols="50" rows="10" style="VERTICAL-ALIGN: middle"></textarea>
            </span></td>
        </tr>
        
        <!-- send button -->
        <tr> 
          <td height="30" bgcolor="#EFEFEF">&nbsp;</td>
          <td width="53%" bgcolor="#EFEFEF"><span> 
            <input name="Send" type="Submit" value="Send" />
            </span></td>
        </tr>
      </table></td>
  </tr>
</table>
</form>
</body>
</html>
<?php
}
?>


#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 15 May 2006 - 03:07 PM

if your Order_ID is auto-increment, just leave it out of your INSERT query (instead of sending NULL). See if that works and reply.

#3 Bee

Bee
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 17 May 2006 - 10:15 PM

[!--quoteo(post=374020:date=May 15 2006, 10:07 AM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ May 15 2006, 10:07 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if your Order_ID is auto-increment, just leave it out of your INSERT query (instead of sending NULL). See if that works and reply.
[/quote]

Thanks for your reply. I took null away; however, it still doesn't write to the table!
that field was auto_increment.

#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 17 May 2006 - 10:22 PM

Don't even send that field.

$sql = "INSERT INTO orders (name, email, company_name, address, post_code, city, tel, mobile, website, redesign_website, website_to_redesign, no_pages, web_design, flash_graphics, flash_programming, programming, shopping_cart, comments) VALUES ('$name', '$email', '$company_name', '$address', '$post_code', '$city', '$tel', '$mobile', '$website', '$redesign_website', '$website_to_redesign', '$no_pages', '$web_design', '$flash_graphics', '$flash_programming', '$programming', '$shopping_cart', '$comments')";


#5 Houdini

Houdini
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 20 May 2006 - 12:54 AM

This is commented out //$Send = $_GET['Send'];
then unless you have register_globals ON then this wont work if ($Send) and it is a $_POST variable because of the method in your form so try changing if ($Send) to
if(isset($_POST['Send'])){
and see what it does.
We the unwilling, led by the unknowing,
have done so much, for so long, with so little,
that we are now quqlified to do anything, with nothing!

#6 Bee

Bee
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 21 May 2006 - 09:48 PM

[!--quoteo(post=375409:date=May 19 2006, 07:54 PM:name=Houdini)--][div class=\'quotetop\']QUOTE(Houdini @ May 19 2006, 07:54 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This is commented out //$Send = $_GET['Send'];
then unless you have register_globals ON then this wont work if ($Send) and it is a $_POST variable because of the method in your form so try changing if ($Send) to
if(isset($_POST['Send'])){
and see what it does.
[/quote]

Thank you:)
That's slightly worked. it created a new record in the table, but left all fields empty except from the auto_increment PK.

#7 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 May 2006 - 11:31 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]That's slightly worked. it created a new record in the table, but left all fields empty except from the auto_increment PK.[/quote]
Probably because all of the data POSTed from the form were not abstracted from the $_POST array. Your script assumes that register_globals is ON (the default in much earlier versions of php and/or found in outdated scripts). You'll need to retrieve each of the POSTed values using a syntax such as:
$name = $_POST['name'];

That should work for you, although there are faster/better ways of doing it.
Legend has it that reading the manual never killed anyone.
My site

#8 Bee

Bee
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 22 May 2006 - 08:35 AM

[!--quoteo(post=375894:date=May 21 2006, 06:31 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 21 2006, 06:31 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Probably because all of the data POSTed from the form were not abstracted from the $_POST array. Your script assumes that register_globals is ON (the default in much earlier versions of php and/or found in outdated scripts). You'll need to retrieve each of the POSTed values using a syntax such as:
$name = $_POST['name'];

That should work for you, although there are faster/better ways of doing it.
[/quote]

It would help very much if you can show me a faster better way of doing it actually.
Thanks.

#9 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 22 May 2006 - 02:21 PM

if (isset($_POST['Send'])) {
    // retrieve all POSTed variables
    foreach ($_POST as $key=>$val) {
        $$key = trim(strip_tags($val)); // remove spaces at ends and strip html/php tags from input
    }
    ... the rest of your form processing ...

Legend has it that reading the manual never killed anyone.
My site

#10 Bee

Bee
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 01 June 2006 - 11:21 PM

[!--quoteo(post=376035:date=May 22 2006, 09:21 AM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 22 2006, 09:21 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
if (isset($_POST['Send'])) {
    // retrieve all POSTed variables
    foreach ($_POST as $key=>$val) {
        $$key = trim(strip_tags($val)); // remove spaces at ends and strip html/php tags from input
    }
    ... the rest of your form processing ...
[/quote]

Thank you for that it worked well with it.

I wonder why you used two $$ on key?





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users