Jump to content

insert values from a form inside the table


ksp22

Recommended Posts

I dont know why I am not able to insert the values of form inside the table..neither I am not getting any error nor values are getting inserted.. I dont know where I lack.. please help me..i am stucked in this place and not able to proceed further :(

 

HTML code is

<body onload="javascript:start();">
    
        <div></div>
        <table align="center" border="0"><tr><td>

        <div id="dlg">
        <!--div class="fld" align="center" valign="top"><h3>Free Sweepstakes Form</h3></div-->
                <div id="regFormOn">
              <form name="regForm" method="post" action="login.php" onsubmit="return validation(this);">
              

                    <table border="0" cellpadding="5" width="10%">
                    <tr><td align="center" valign="top" colspan="3">  <h3>Free Sweepstakes Form</h3></td></tr>
                    
                    
                        <tr><td class="fld" nowrap>Email Address</td><td colspan="2"><input type="text" size="50" name="email1" id="email1"></td></tr>
                        <tr><td class="fld" nowrap>Name</td><td colspan="2"><input type="text" size="50" name="nme" id="nme"></td></tr>
                        <tr><td class="fld" nowrap>Address1</td><td colspan="2"><input type="text" size="50" name="address1" id="address1"></td></tr>
                        <tr><td class="fld" nowrap>Address2</td><td colspan="2"><input type="text" size="50" name="address2" id="address2"></td></tr>
                        <tr><td class="fld" nowrap>Town/City/Suburb</td><td colspan="2"><input type="text" size="50" name="city" id="city"></td></tr>
                        <tr><td class="fld" nowrap>State/Province/County</td><td colspan="2"><input type="text" size="50" name="province" id="province"></td></tr>
                        <tr><td class="fld" nowrap>Zip/Postal Code</td><td colspan="2"><input type="text" size="50" name="zip" id="zip"></td></tr>
                        <tr><td class="fld" nowrap>Country</td><td align="left"><select name="ctry" onchange="javascript:setOther();" id="ctry"><option value="0" selected>Select Country</option>
                           
                           <option value="1">Australia</option>
                                <option value="2">Austria</option>
                                <option value="3">Belgium</option>
                                <option value="4">Canada</option>
                                <option value="5">Denmark</option>
                                <option value="6">Finland</option>
                                <option value="7">France</option>
                                <option value="8">Germany</option>
                                <option value="9">Ireland</option>
                                <option value="10">Italy</option>
                                <option value="11">Japan</option>  
                                <option value="12">Mexico</option>
                                <option value="13">Netherlands</option>
                                <option value="14">New Zealand</option>
                                <option value="15">Norway</option>
                                <option value="16">Poland</option>
                                <option value="17">Portugal</option>
                                <option value="18">Singapore</option>
                                <option value="19">South Africa</option>
                                <option value="20">Spain</option>
                                <option value="21">Sweden</option>
                                <option value="22">Switzerland</option>
                                <option value="23">United Kingdom</option>
                                <option value="24">United States</option>
                                <option value="25">Other</option>
                            </select> </td>
                            <td><input type="text" id="other_ctry" size="27" style="display:none;"></td></tr>
                        
                        <tr><td class="fld" nowrap>Choose Password</td><td colspan="2"><input type="password" size="50" name="pwd1" id="pwd1"></td></tr>
                            
                        <tr><td class="fld" nowrap>Confirm Password</td><td colspan="2"><input type="password" size="50" name="pwd2" id="pwd2"></td></tr>

                        <tr><td colspan="3" align="center"><input type="submit" name="Submit1" value="Submit" >  <input type="button" name="exac" value="Existing User..." onclick="javascript:toggleOnOff('regForm',false)">  <input type="button" name="Cancel1" value="Cancel" onclick="javascript:toggle('dlg')"></td></tr>
                        
                       </table>
                        </form>
                </div>
    

login.php is

$con = mysql_connect('localhost','root','');
if (!$con)
  {

  die('Could not connect: ' . mysql_error());

  }
  else
  {

  echo 'Connected successfully';
   }
mysql_select_db("player_information") or die(mysql_error());


   $email1      = $_POST['email1'];
   $nme         = $_POST['nme'];
   $address1    = $_POST['address1'];
   $address2    = $_POST['address2'];
   $city        = $_POST['city'];
   $province    = $_POST['province'];
   $zip         = $_POST['zip'];
   $ctry        = $_POST['ctry'];
   $other_ctry  = $_POST['other_ctry'];
   $pwd1        = $_POST['pwd1'];
   $cash_credit = $_POST['cash_credit'];*/


  $q=("INSERT INTO player (email1, nme, address1, address2, city, province, zip, ctry, other_ctry, pwd1, cash_credit)
VALUES('$nme','$email1','$address1','$address2','$city','$province','$zip','$ctry','$other_ctry','$pwd1','$cash_credit')");
mysql_query($q,$con) or die(mysql_error());


mysql_close($con)

?>

 

I need help..Please help me :(

Thanx in advance

It might be useful if you could post the error that you are getting.  But right off the bat, there's a couple of things you should check:

 

  • email1 and nme are switched in the insert statement (you list the columns as nme, email1 - but the strings are '$email1', '$nme')
  • you really should be verifying the results from the form to make sure they are what you expect
  • you should be escaping the strings with mysql_real_escape_string()
  • I'm not 100% on this one, but you don't need the parentheses around the query string, off the top of my head, I'm not sure how PHP will handle that['li]

 

 

Thanx for the help..

I tried this also but still i am not able to insert the values inside the table and i am not getting any error..its working correctly without any error....but not giving me the desired result :(

and now login.php is

<?php

$con = mysql_connect('localhost','root','');
if (!$con)
  {

  die('Could not connect: ' . mysql_error());

  }
  else
  {

  echo 'Connected successfully';
   }
mysql_select_db("player_information") or die(mysql_error());


    $nme    = $_POST['nme'];
   $email1   = $_POST['email1'];
   $address1     = $_POST['address1'];
   $address2 = $_POST['address2'];
     $city    = $_POST['city'];
   $province   = $_POST['province'];
   $zip     = $_POST['zip'];
   $ctry = $_POST['ctry'];
     $other_ctry    = $_POST['other_ctry'];
   $pwd1   = $_POST['pwd1'];
   $cash_credit     = $_POST['cash_credit'];



$q=("INSERT INTO player (email1, nme, address1, address2, city, province, zip, ctry, other_ctry, pwd1, cash_credit)
VALUES('$nme','$email1','$address1','$address2','$city','$province','$zip','$ctry','$other_ctry','$pwd1','$cash_credit')");

$sql=sprintf("INSERT INTO player (email1, nme, address1, address2, city, province, zip, ctry, other_ctry, pwd1, cash_credit) VALUES ('%s','%s',%s','%s',%s','%s',%s','%s',%s','%s',%s','%s')",
  mysql_real_escape_string($_POST['email1']),
  mysql_real_escape_string($_POST['nme']),
  mysql_real_escape_string($_POST['address1']),
  mysql_real_escape_string($_POST['address2']),
  mysql_real_escape_string($_POST['city']),
  mysql_real_escape_string($_POST['province']),
  mysql_real_escape_string($_POST['zip']),
  mysql_real_escape_string($_POST['ctry']),
  mysql_real_escape_string($_POST['other_ctry']),
  mysql_real_escape_string($_POST['pwd1']),
  mysql_real_escape_string($_POST['cash_credit']));

mysql_query($q , $con) or die(mysql_error());
mysql_close($con)

?>

still no output :(

you dont really need to list the table colums.. not sure that its causing the problem but try this

 

<?php
$q=("INSERT INTO player VALUES('$email1','$nme','$address1','$address2','$city','$province','$zip','$ctry','$other_ctry','$pwd1','$cash_credit')");
?>

yes i get connection successful echo whwn i run login.php individually..and when i run newslot.html file then nothing is displayed... not even any error..

if i use

$sql=sprintf("INSERT INTO player (email1, nme, address1, address2, city, province, zip, ctry, other_ctry, pwd1, cash_credit) VALUES ('%s','%s',%s','%s',%s','%s',%s','%s',%s','%s',%s','%d')",
  mysql_real_escape_string($_POST['email1']),
  mysql_real_escape_string($_POST['nme']),
  mysql_real_escape_string($_POST['address1']),
  mysql_real_escape_string($_POST['address2']),
  mysql_real_escape_string($_POST['city']),
  mysql_real_escape_string($_POST['province']),
  mysql_real_escape_string($_POST['zip']),
  mysql_real_escape_string($_POST['ctry']),
  mysql_real_escape_string($_POST['other_ctry']),
  mysql_real_escape_string($_POST['pwd1']),
  mysql_real_escape_string($_POST['cash_credit']));

this code then one erroe occurs ans that is :

Connected successfully

Warning: sprintf() [function.sprintf]: Too few arguments in C:\xampp\htdocs\3slot\login.php on line 46

Query was empty

 

and if i use

$q=("INSERT INTO player (email1, nme, address1, address2, city, province, zip, ctry, other_ctry, pwd1, cash_credit)
VALUES('$email1','$nme','$address1','$address2','$city','$province','$zip','$ctry','$other_ctry','$pwd1','$cash_credit')");

this query then o error occurs it displays : Connected successfully

 

still no result :( where I am lacking i dont knw :(

Hey Thanx for replying :) I had posted my html file in my first post..but anyways..i"ll post my html file again :)

<body onload="javascript:start();">
    
        <div></div>
        <table align="center" border="0"><tr><td>

        <div id="dlg">
        <!--div class="fld" align="center" valign="top"><h3>Free Sweepstakes Form</h3></div-->
                <div id="regFormOn">
              <form name="regForm" onsubmit="return validation(this);" action="login.php" method="post">
              

                    <table border="0" cellpadding="5" width="10%">
                    <tr><td align="center" valign="top" colspan="3">  <h3>Free Sweepstakes Form</h3></td></tr>
                    
                    
                        <tr><td class="fld" nowrap>Email Address</td><td colspan="2"><input type="text" size="50" name="email1" id="email1"></td></tr>
                        <tr><td class="fld" nowrap>Name</td><td colspan="2"><input type="text" size="50" name="nme" id="nme" value=""></td></tr>
                        <tr><td class="fld" nowrap>Address1</td><td colspan="2"><input type="text" size="50" name="address1" id="address1"></td></tr>
                        <tr><td class="fld" nowrap>Address2</td><td colspan="2"><input type="text" size="50" name="address2" id="address2"></td></tr>
                        <tr><td class="fld" nowrap>Town/City/Suburb</td><td colspan="2"><input type="text" size="50" name="city" id="city"></td></tr>
                        <tr><td class="fld" nowrap>State/Province/County</td><td colspan="2"><input type="text" size="50" name="province" id="province"></td></tr>
                        <tr><td class="fld" nowrap>Zip/Postal Code</td><td colspan="2"><input type="text" size="50" name="zip" id="zip"></td></tr>
                        <tr><td class="fld" nowrap>Country</td><td align="left"><select name="ctry" onchange="javascript:setOther();" id="ctry"><option value="0" selected>Select Country</option>
                           
                           <option value="1">Australia</option>
                                <option value="2">Austria</option>
                                <option value="3">Belgium</option>
                                <option value="4">Canada</option>
                                <option value="5">Denmark</option>
                                <option value="6">Finland</option>
                                <option value="7">France</option>
                                <option value="8">Germany</option>
                                <option value="9">Ireland</option>
                                <option value="10">Italy</option>
                                <option value="11">Japan</option>  
                                <option value="12">Mexico</option>
                                <option value="13">Netherlands</option>
                                <option value="14">New Zealand</option>
                                <option value="15">Norway</option>
                                <option value="16">Poland</option>
                                <option value="17">Portugal</option>
                                <option value="18">Singapore</option>
                                <option value="19">South Africa</option>
                                <option value="20">Spain</option>
                                <option value="21">Sweden</option>
                                <option value="22">Switzerland</option>
                                <option value="23">United Kingdom</option>
                                <option value="24">United States</option>
                                <option value="25">Other</option>
                            </select> </td>
                            <td><input type="text" id="other_ctry" size="27" style="display:none;"></td></tr>
                        
                        <tr><td class="fld" nowrap>Choose Password</td><td colspan="2"><input type="password" size="50" name="pwd1" id="pwd1"></td></tr>
                            
                        <tr><td class="fld" nowrap>Confirm Password</td><td colspan="2"><input type="password" size="50" name="pwd2" id="pwd2"></td></tr>

                        <tr><td colspan="3" align="center"><input type="submit" name="Submit1" value="Submit" onclick="sendRequest()">  <input type="button" name="exac" value="Existing User..." onclick="javascript:toggleOnOff('regForm',false)">  <input type="button" name="Cancel1" value="Cancel" onclick="javascript:toggle('dlg')"></td></tr>
                        
                       </table>
                        </form>
                </div>
                <div id="regFormOff" style="display:none;">
                
                
                <table border="0" colspan="2">
                    <tr><td class="fld">Email Address</td><td><input type="text" name="email2" id="email2"></td></tr>
                    <tr><td class="fld">Choose a Password</td><td><input type="password" name="pwd3" id="pwd3"></td></tr>
                    <tr><td align="center" colspan="2"><input type="button" name="Submit2" value="Login...">  <input type="button" name="newac" value="Create new account" onclick="javascript:toggleOnOff('regForm',true)">  <input type="button" name="Cancel2" value="Cancel" onclick="javascript:toggle('dlg')"></td></tr>
                </table>
                
                </div>
            </div>


   $cash_credit = $_POST['cash_credit'];*/

 

Why do you close a comment at that part, is the comment block opened in another part of the script?

 

Also you could use:


array_map("mysql_real_escape_string", $_POST);
   $email1      = $_POST['email1'];
   $nme         = $_POST['nme'];
   $address1    = $_POST['address1'];
   $address2    = $_POST['address2'];
   $city        = $_POST['city'];
   $province    = $_POST['province'];
   $zip         = $_POST['zip'];
   $ctry        = $_POST['ctry'];
   $other_ctry  = $_POST['other_ctry'];
   $pwd1        = $_POST['pwd1'];
   $cash_credit = $_POST['cash_credit'];


 

As all of the postdata is being used for a query.

<body onload="javascript:start();">
    
        <div></div>
        <table align="center" border="0"><tr><td>

        <div id="dlg">
        <!--div class="fld" align="center" valign="top"><h3>Free Sweepstakes Form</h3></div-->
                <div id="regFormOn">
              <form name="regForm" onsubmit="return validation(this);" action="login.php" method="post">
              

                    <table border="0" cellpadding="5" width="10%">
                    <tr><td align="center" valign="top" colspan="3">  <h3>Free Sweepstakes Form</h3></td></tr>
                    
                    
                        <tr><td class="fld" nowrap>Email Address</td><td colspan="2"><input type="text" size="50" name="email1" id="email1"></td></tr>
                        <tr><td class="fld" nowrap>Name</td><td colspan="2"><input type="text" size="50" name="nme" id="nme" value=""></td></tr>
                        <tr><td class="fld" nowrap>Address1</td><td colspan="2"><input type="text" size="50" name="address1" id="address1"></td></tr>
                        <tr><td class="fld" nowrap>Address2</td><td colspan="2"><input type="text" size="50" name="address2" id="address2"></td></tr>
                        <tr><td class="fld" nowrap>Town/City/Suburb</td><td colspan="2"><input type="text" size="50" name="city" id="city"></td></tr>
                        <tr><td class="fld" nowrap>State/Province/County</td><td colspan="2"><input type="text" size="50" name="province" id="province"></td></tr>
                        <tr><td class="fld" nowrap>Zip/Postal Code</td><td colspan="2"><input type="text" size="50" name="zip" id="zip"></td></tr>
                        <tr><td class="fld" nowrap>Country</td><td align="left"><select name="ctry" onchange="javascript:setOther();" id="ctry"><option value="0" selected>Select Country</option>
                           
                           <option value="1">Australia</option>
                                <option value="2">Austria</option>
                                <option value="3">Belgium</option>
                                <option value="4">Canada</option>
                                <option value="5">Denmark</option>
                                <option value="6">Finland</option>
                                <option value="7">France</option>
                                <option value="8">Germany</option>
                                <option value="9">Ireland</option>
                                <option value="10">Italy</option>
                                <option value="11">Japan</option>  
                                <option value="12">Mexico</option>
                                <option value="13">Netherlands</option>
                                <option value="14">New Zealand</option>
                                <option value="15">Norway</option>
                                <option value="16">Poland</option>
                                <option value="17">Portugal</option>
                                <option value="18">Singapore</option>
                                <option value="19">South Africa</option>
                                <option value="20">Spain</option>
                                <option value="21">Sweden</option>
                                <option value="22">Switzerland</option>
                                <option value="23">United Kingdom</option>
                                <option value="24">United States</option>
                                <option value="25">Other</option>
                            </select> </td>
                            <td><input type="text" id="other_ctry" size="27" style="display:none;"></td></tr>
                        
                        <tr><td class="fld" nowrap>Choose Password</td><td colspan="2"><input type="password" size="50" name="pwd1" id="pwd1"></td></tr>
                            
                        <tr><td class="fld" nowrap>Confirm Password</td><td colspan="2"><input type="password" size="50" name="pwd2" id="pwd2"></td></tr>

                        <tr><td colspan="3" align="center"><input type="submit" name="Submit1" value="Submit" onclick="sendRequest()">  <input type="button" name="exac" value="Existing User..." onclick="javascript:toggleOnOff('regForm',false)">  <input type="button" name="Cancel1" value="Cancel" onclick="javascript:toggle('dlg')"></td></tr>
                        
                       </table>
                        </form>
                </div>
                <div id="regFormOff" style="display:none;">
                
                
                <table border="0" colspan="2">
                    <tr><td class="fld">Email Address</td><td><input type="text" name="email2" id="email2"></td></tr>
                    <tr><td class="fld">Choose a Password</td><td><input type="password" name="pwd3" id="pwd3"></td></tr>
                    <tr><td align="center" colspan="2"><input type="button" name="Submit2" value="Login...">  <input type="button" name="newac" value="Create new account" onclick="javascript:toggleOnOff('regForm',true)">  <input type="button" name="Cancel2" value="Cancel" onclick="javascript:toggle('dlg')"></td></tr>
                </table>
                
                </div>
            </div>
            <div class="slot-main" align="center">
        <div class="slot-main-body">
            <div class="slot-well">
                    <div class="slot-payline"></div>
                    <div id="slot-reel0"><div id="slot00"></div><div id="slot01"></div></div>
                    <div id="slot-reel1"><div id="slot10"></div><div id="slot11"></div></div>
                    <div id="slot-reel2"><div id="slot20"></div><div id="slot21"></div></div>
                    <div class="slot-shadow"></div>
             </div>
             <div class="slot-reel-point">
                    <div id="paid">
                        <div id="paid0"></div>
                        <div id="paid1"></div>
                        <div id="paid2"></div>
                        <div id="paid3"></div>
                    </div>
                    <div id="credits">
                        <div id="credits0"></div>
                        <div id="credits1"></div>
                        <div id="credits2"></div>
                        <div id="credits3"></div>
                    </div>
                    <div id="coins">
                        <div id="coins3"></div>
                    </div>
                    <div id="links">
                        <table border="0"><tr valign="middle">
                           <td id="sound" width="50%"></td>
                            <td><a onclick="javascript:addMoreCredits()" id="add_credits" style="display:none;" border="0"><img src="images/addcredits_small.png"></a> </td>
                        </tr></table>
                    </div>
             </div>
             <div class="slot-button-body" align="center">
                <table border="0"> <tr>
                      <td align="center">
                        <a class="slot-button-left-on" href="#" id="cashCreditOn" onclick="javascript:toggle('dlg');">
                            <img src="images/cash_credit_button_text.png" alt="Cash / Credit" class="slot-button-text">
                        </a>
                         <a class="slot-button-left-off" id="cashCreditOff" style="display:none;">
                          <img src="images/cash_credit_button_text.png" alt="Cash / Credit" class="slot-button-text">
                         </a>
                    </td>
                    <!-- -->
                    <td align="center">
                    <a class="slot-button-left-on" href="#" id="betOneOn" onclick="javascript:betOne()">
                            <img src="images/bet_one_button_text.png" alt="Bet One" class="slot-button-text">
                     </a>
                     <a class="slot-button-left-off" id="betOneOff" style="display:none;">
                            <img src="images/bet_one_button_text.png" alt="Bet One" class="slot-button-text">
                         </a>
                    </td>
                    <!-- -->
                      <td align="center">
                        <a class="slot-button-right-on" href="#" id="betMaxOn" onclick="javascript:betMax()">
                            <img src="images/bet_max_button_text.png" alt="Bet Max" class="slot-button-text">
                         </a>
                         <a class="slot-button-right-off" id="betMaxOff" style="display:none;">
                          <img src="images/bet_max_button_text.png" alt="Bet Max" class="slot-button-text">
                          </a>
                    </td>
                    <!-- -->
                    <td align="center">
                    <a class="slot-button-right-on" href="#" id="spinReelsOn" onclick="javascript:spinReels();" >
                            <img src="images/spin_reels_button_text.png" alt="Spin Reels" class="slot-button-text">
                     </a>
                     <a class="slot-button-right-off" id="spinReelsOff" style="display:none;">
                            <img src="images/spin_reels_button_text.png" alt="Spin Reels" class="slot-button-text">
                         </a>
                    </td>

                     </tr></table>
               <!-- -->
            </div>
             <div class="slot-paytable"></div>
        </div>
</div></td></tr></table>
</body>
</html>

this is my complete html file... i have used togglr function to display the form after cliking the form button and this form appears like a pop up..is this method is creating problem :(

Archived

This topic is now archived and is closed to further replies.

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