+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: How come PHP is not insertting my data into MySQL?

  1. #1
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    How come PHP is not insertting my data into MySQL?

    register.php
    PHP Code:
    <?php include ('config.php'); ?>
    <html>
    <head>
      <title>Menu Maniac</title>
      <LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
    </head>
    <body>
    <div id="width">
    <?php
    if (isset($_POST['Submit'])) {
      
    $fName check_input($_POST['fName']);
      
    $lName check_input($_POST['lName']);
      
    $address check_input($_POST['address']);
      
    $city check_input($_POST['city']);
      
    $state check_input($_POST['state']);
      
    $zipcode check_input($_POST['zipcode']);
      
    $phone check_input($_POST['phone']);
      
    $email check_input($_POST['email']);
      
    $cardNum check_input($_POST['cardNum']);
      
    $securityCode check_input($_POST['securityCode']);
      
    $expMonth check_input($_POST['expMonth']);
      
    $expYear check_input($_POST['expYear']);
      
      
    $sql "INSERT INTO members (id, password, ipaddress, fName, lName, address, city, zipcode, phone, email, cardNum, securityCode, expMonth, expYear, organizations) VALUES (NULL, NULL, NULL, $fName,$lName,$address,$city,$zipcode,$phone,$email,$cardNum,$securtiyCode,$expMonth,$expYear, NULL)";
      
    $query mysql_query($sql);
      if(
    $query) { echo "Information has been registered.";
      }
      echo 
    check_input($_POST['fName']);
      echo 
    $fName;
      
      unset(
    $_POST['Submit']);
      
    } else {
    ?>
    <form action="" method="post">
      <table width="500" cellpadding="4" cellspacing="0" border="0">
        <tr>
          <td align="right" valign="top"><span class="style3">First Name*:</span></td>
          <td valign="top"><input type="text" name="fName" size="30" /></td>
        </tr>
        <tr>
          <td align="right" valign="top"><span class="style3">Last Name*:</span></td>
          <td valign="top"><input type="text" name="lName" size="30" /></td>
        </tr>
        <tr>
          <td align="right" valign="top"><span class="style3">Address:</span></td>
          <td valign="top"><input type="text" name="address" size="50" /><br /></td>
        </tr>
        <tr>

          <td align="right" valign="top"><span class="style3">City:</span></td>
          <td valign="top"><input type="text" name="City" size="30" value="" id="City" /></td>
        </tr>
        <tr>
              <td align="right" valign="top"><span class="style3">State:</span></td>
              <td valign="top"><input type="text" name="state" size="10" value="" id="State" /></td>
            </tr>
            <tr>

              <td align="right" valign="top"><span class="style3">Zipcode:</span></td>
              <td valign="top"><input type="text" name="zipcode" size="10" value="" id="Zipcode" /></td>
            </tr>
            <tr>
              <td align="right" valign="top"><span class="style3">Phone*:</span></td>
              <td valign="top"><input type="text" name="phone" size="15" value="" id="Phone" /></td>
            </tr>
            <tr>

              <td align="right" valign="top"><span class="style3">E-mail*:</span></td>
              <td valign="top"><input type="text" name="email" size="50" value="" id="Email Address" /><br />
                <span class="style3"><i>Please provide your e-mail address so we may better serve you.</i></span><br />
              </td>
            </tr>
          </table>
          <br />
          <br />
          <div style="padding:4px; background:#270000;">
            <span class="boldTitle"><font color="white">Credit Card Information</font></span></div>

          <table width="537" border="0">
            <tr>
              <td width="128">

                <div align="right">
                  <span class="style3">Amount $</span></div>
              </td>
              <td width="379"><input type="text" name="xamount2" size="15" /></td>
              <td> </td>
            </tr>
            <tr>
              <td>

                <div align="right">
                  <span class="style3">Debit/Credit Card #:</span></div>
              </td>
              <td><span class="style3"><input type="text" size="25" name="Debit Credit Card" id="Debit Credit Card" /> </span></td>
              <td> </td>
            </tr>
            <tr>

              <td>
                <div align="right">
                  <span class="style3">Security Code:</span></div>
              </td>
              <td><span class="style3"><input type="text" name="Security Code" size="6" id="Security Code" /></span></td>
            </tr>

            <tr>
              <td>
                <div align="right">
                  <span class="style3">Expiration Month:</span></div>
              </td>
              <td><span class="style3"><select name="Expiration Month" id="Expiration Month">
                    <option></option>
                    <option>01</option>

                    <option>02</option>
                    <option>03</option>
                    <option>04</option>
                    <option>05</option>
                    <option>06</option>
                    <option>07</option>

                    <option>08</option>
                    <option>09</option>
                    <option>10</option>
                    <option>11</option>
                    <option>12</option>
                  </select> </span></td>

              <td> </td>
            </tr>
            <tr>
              <td>
                <div align="right">
                  <span class="style3">Expiration Year:</span></div>
              </td>
              <td><span class="style3"><select name="Expiration Year" id="Expiration Year">

                    <option selected="selected"></option>
                    <option>2007</option>
                    <option>2008</option>
                    <option>2009</option>
                    <option>2010</option>
                    <option>2011</option>

                    <option>2012</option>
                    <option>2013</option>
                    <option>2014</option>
                    <option>2015</option>
                    <option>2016</option>
                    <option>2017</option>

                    <option>2018</option>
                    <option>2019</option>
                    <option>2020</option>
                  </select> </span></td>
              <td> </td>
            </tr>

            <tr>
              <td><span class="style3"><img src="../images/creditCards.gif" alt="Credit Cards" width="139" height="30" border="0" /></span></td>
              <td> </td>
              <td> </td>
            </tr>
          </table>
          <br />
          <div align="center">
            <input type="reset" value="Reset" />     <input type="submit" name="Submit" value="Submit"></div>

        </form>
    <?}?>


    </div>
    </body>
    </html>
    config.php (censored)
    PHP Code:
    <?php 
    $DBhost 
    "";
    $DBuser "";
    $DBpassword "";

    $con mysql_connect($DBhost,$DBuser,$DBpassword);
    if (!
    $con) {
      die(
    'Could not connect: ' mysql_error());
    }
    mysql_select_db(""$con);

    function 
    check_input($value) {
      if (
    get_magic_quotes_gpc()) {
        
    $value stripslashes($value);
      }
      if (!
    is_numeric($value)) {
        
    $value "'" mysql_real_escape_string($value) . "'";
      }
    return 
    $value;
    }
    ?>
    PHP Code:
    echo check_input($_POST['fName']);
      echo 
    $fName
    gives me what I want, but when it goes to
    insert it into the database, it fails.
    PHP Code:
    $query mysql_query($sql);
      if(
    $query) { echo "Information has been registered.";
      } 

  2. #2
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: How come PHP is not insertting my data into MySQL?

    Try to add:

    PHP Code:
    mysql_select_db(""$con) or die("could not select db"); 
    and:

    PHP Code:
    $query mysql_query($sql) or die("error:"mysql_error()); 
    Last edited by galaxyAbstractor; 08-13-2009 at 09:32 AM.

  3. #3
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How come PHP is not insertting my data into MySQL?

    that was a smart idea. get php to tell me whats going wrong xP

    PHP Code:
    error:You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near ''','', NULL)' at line 1 
    I think i am using MySQL 5?
    yes, I am using 5.0
    Last edited by diabolo; 08-13-2009 at 09:39 AM.

  4. #4
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: How come PHP is not insertting my data into MySQL?

    Quote Originally Posted by diabolo View Post
    that was a smart idea. get php to tell me whats going wrong xP

    PHP Code:
    error:You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near ''','', NULL)' at line 1 
    I think i am using MySQL 5?
    yes, I am using 5.0
    try to replace all NULL's with 2 single quotes like ''

  5. #5
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How come PHP is not insertting my data into MySQL?

    PHP Code:
    $sql "INSERT INTO members (id, password, ipaddress, fName, lName, address, city, zipcode, phone, email, cardNum, securityCode, expMonth, expYear, organizations) VALUES ('NULL', 'NULL', 'NULL', $fName,$lName,$address,$city,$zipcode,$phone,$email,$cardNum,$securtiyCode,$expMonth,$expYear, 'NULL')"
    I still get the error code.
    Code:
    error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''','', 'NULL')' at line 1

  6. #6
    TechAsh's Avatar
    TechAsh is offline Retired TechAsh is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    UK
    Posts
    5,853

    Re: How come PHP is not insertting my data into MySQL?

    I think Vigge meant something like this:

    PHP Code:
    $sql "INSERT INTO members (id, password, ipaddress, fName, lName, address, city, zipcode, phone, email, cardNum, securityCode, expMonth, expYear, organizations) VALUES ('', '', '', $fName,$lName,$address,$city,$zipcode,$phone,$email,$cardNum,$securtiyCode,$expMonth,$expYear, '')"
    Useful Links:
    Terms of Service | Server News | Buy a Domain
    Free Domains: co.cc | Dot.tk -- Free File Storage: Dropbox -- Website Monitoring: Service Uptime


    My Websites:
    Earthtime Games & TechAsh's Blog

  7. #7
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How come PHP is not insertting my data into MySQL?

    o keyword, replace.
    but still no avail.


    PHP Code:
    $sql "INSERT INTO members (id, password, ipaddress, fName, lName, address, city, zipcode, phone, email, cardNum, securityCode, expMonth, expYear, organizations) VALUES ('', '', '', $fName,$lName,$address,$city,$zipcode,$phone,$email,$cardNum,$securtiyCode,$expMonth,$expYear, '')"
    Code:
    error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''','', '')' at line 1

  8. #8
    z_killemall's Avatar
    z_killemall is offline x10Hosting Member z_killemall is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    47

    Re: How come PHP is not insertting my data into MySQL?

    Try putting the PHP variables between single quotes:

    PHP Code:
    $sql "INSERT INTO members (id, password, ipaddress, fName, lName, address, city, zipcode, phone, email, cardNum, securityCode, expMonth, expYear, organizations) VALUES ('', '', '', '$fName','$lName','$address','$city','$zipcode','$phone','$email','$cardNum','$securtiyCode','$expMonth','$expYear', '')"

  9. #9
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: How come PHP is not insertting my data into MySQL?

    To debug, put an echo "\$sql = ->$sql <--" statement so you can see what mySQL sees as your query.

    And as mentioned, when you insert strings into mySQL, they must be 'quoted'.
    Nothing is always absolutely so.

  10. #10
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: How come PHP is not insertting my data into MySQL?

    the check_input function already puts in the single quotes if the string is not numeric.

    please read the whole thing before commenting.

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. New Site-Suggestions?
    By mnoutside in forum Review My Site
    Replies: 9
    Last Post: 08-27-2008, 07:01 AM
  3. Replies: 2
    Last Post: 11-20-2007, 11:15 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  5. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers