Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP/MySQL problem

    I have written a very messy very quick kiosk registration for a company that I work for. I wrote it in PHP so that we could use it in different locations. I have gotten it to print the information, but I am having problems getting it to send the information to a MySQL table that's formed for it... and it gives me 0 errors. Here is the code:
    PHP Code:
    <?php 
    include('db.php');

    $errors = array();

    if(!
    $_POST['fName'])
        
    $errors[] = "Please enter your first name";
    if(!
    $_POST['AgentCheck'])
        
    $errors[] = "Please answer the question regarding an agent";
       if (
    count($errors)>0){
          echo 
    "<strong>Required:<br>\n";
          foreach(
    $errors as $err)
            echo 
    "$err<br>\n";
       } else {
    $handle printer_open("\\\\192.168.1.123\print");
    mysql_query("INSERT INTO registration (firstName, lastName, streetAddress, city, state, phoneNumber, agent, emailAddress, lookingFor1, LookingFor2, date) values('$_POST[fName]','$_POST[lName]','$_POST[sAddress]','$_POST[City]','$_POST[State]',$_POST[ZipCode]','$_POST[PhoneNum]','$_POST[AgentCheck]','$_POST[Email]','$_POST[lookingfor]', now())");

    $guestRegister "A new guest has registered with Volente Realty on ".date("F j, Y")." at ".date("g:i a")."\n\r";
    switch(
    $_POST['AgentCheck'])
    {
     case 
    'Yes':
     
    $guestRegister .= $_POST[fName].' '.$_POST[lName]." is working with another Real Estate Agent.\n\r";
     break;
     case 
    'No':
      
    $guestRegister .= $_POST[fName].' '.$_POST[lName]." is not working with another Real Estate Agent.\n\r";
     break;
     default:
     echo 
    'Somethings wrong call Jason!';
     break;
    }

    if (!empty(
    $_POST['lookingfor']))
    {
     if (!empty(
    $_POST['lotPrice1']))
     {
         
    $guestRegister .= "Lot under $150,000\n\r";
     }
     if (!empty(
    $_POST['lotPrice2']))
     {
         
    $guestRegister .= "Lot above $150,000\n\r";
     }
     if (!empty(
    $_POST['lotPrice3']))
     {
         
    $guestRegister .= "Waterfront lot above $350,000\n\r";
     }
     if (!empty(
    $_POST['housePrice1']))
     {
        
    $guestRegister .= "House under $250,000\n\r";
     }
     if (!empty(
    $_POST['housePrice2']))
     {
         
    $guestRegister .= "House above $250,000\n\r"
     }
    }

    $guestRegister .= "\n\r".$_POST[fName]." ".$_POST[lName]."\n\r".$_POST[sAddress]."\n\r".$_POST[City]." ".$_POST[State].' '.$_POST[ZipCode]."\n\r";

    $guestRegister .= "\n\r".$_POST[PhoneNum];
    $guestRegister .= "\n\r".$_POST[Email];
    printer_start_doc($handle"Guest Registry"); 
    printer_set_option($handlePRINTER_MODE"RAW");
    printer_write($handle$guestRegister);
    printer_end_doc($handle);
    printer_close($handle);
    }
    ?>
    Any help and suggestions like nuke it and start over are more then welcome and I appreciate the input!

  • #2
    Regular Coder
    Join Date
    Jun 2003
    Location
    Australia
    Posts
    528
    Thanks
    8
    Thanked 8 Times in 8 Posts
    You're right, it is messy - so I haven't looked deep into it.. but perhaps change this line:

    mysql_query("INSERT INTO registration (firstName, lastName, streetAddress, city, state, phoneNumber, agent, emailAddress, lookingFor1, LookingFor2, date) values('$_POST[fName]','$_POST[lName]','$_POST[sAddress]','$_POST[City]','$_POST[State]',$_POST[ZipCode]','$_POST[PhoneNum]','$_POST[AgentCheck]','$_POST[email]','$_POST[lookingfor]', now())") or die(mysql_error());

    And then you'll find that this query is in a bad order:

    Eg. firstName, lastName, streetAddress, city, state AND

    '$_POST[fName]','$_POST[lName]','$_POST[sAddress]','$_POST[City]','$_POST[State]',$_POST[ZipCode]'

    The order is different.. Where is the field for ZipCode? You also have two LookingFor's (1 and 2) set only 1 in your values..

    You should get in practise of adding or die(mysql_error()); as you should have been able to pick this up yourself.

    Good luck


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •