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 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Undefined variables error or e_notice

    I can't get this code to work. What am i doing wrong? All the variations don't work.

    PHP Code:
    <?php
    // This page allows a logged-in user to add a profile.

    require_once ('includes/config.inc.php'); 
    $page_title 'Add a profile';
    include (
    'includes/header.html');

    // check if form is submitted already.
    if (!isset($_POST['submitted']));// handle the form
    else{


    require_once (
    'mysqli_connect.php');

    // Trim all the incoming data:
        
    $trimmed array_map('trim'$_POST);
        
        
    // Assume invalid values:
        
    $en $rn $b $f $r $pc $cn $c $po $e $pn FALSE;


    //validate the form data
    //check for  a establsihment name:
        
    if (!isset($_POST['est_name'])) 
    // name is entered
     
    @$en $_POST['est_name'];
    else{ 
    $en '' ;
    }
     
        
        
    //check for  a road name:
    if (!empty($_POST['road_name'])) //road name is entered 
    @$rn $_POST['road_name'];
    else {
    $rn '';}
        
         
    //check for  a building:
    if (!isset($_POST['building'])) 
    $b $_POST['building'];
    else {
    $_POST['building'] = NULL;}

     
    //check for  a floor:
    if (!empty($_POST['floor']))
    $f $_POST['floor'];
    else {
    $_POST['floor'] = NULL;}
         
    //check for  a room:
    if (!empty($_POST['room']))
    $r $_POST['room'];
    else {
    $_POST['room'] =  NULL;}
         
    //check for  a postal code:
    if (!empty($_POST['postal_code']))
    $pc $_POST['postal_code'];
    else {
    $_POST['postal_code'] =  NULL;}
         
    //check for  a city name:
    if(!empty($_POST['city_name']))
    $cn $_POST['city_name'];
    else {
    $_POST['city_name'] =  NULL;}


         
    //check for  a country name:
    if (!empty($_POST['country']))
    $c $_POST['country'];
    else {
    $_POST['country'] !=  NULL;}


         
    //check for  email:
    if (!empty($_POST['po_box']))
    $p $_POST['po_box'];
    else {
    $_POST['po_box'] =  NULL;}

         
    //check for  a phone number:
    if (!empty($_POST['email']))
    $e $_POST['email'];
    else {
    $_POST['email'] !=  NULL;}


         
    //check for  a establsihment name:
    if (!empty($_POST['phone_number']))
    $pn $_POST['phone_number'];
    else {
    $_POST['phone_number'] !=  NULL;}


    //End of main conditional
    }

    // Add profile to database.

                
    // line 99.    $q = "INSERT INTO addresses (user_id, est_name, road_name, building, floor, room, postal_code, city_name, country, po_box, email, phone_number) VALUES ('$_SESSION[user_id]', '$en', '$rn', '$b', '$f', '$r', '$pc', '$cn', '$c', '$pb', '$e', '$pn')";
            
    $r mysqli_query ($dbc$q) or trigger_error("Query: $q\n<br />MySQL Error: " mysqli_error($dbc));

    error_reporting(E_ALL E_NOTICE);

    if (
    mysqli_affected_rows($dbc) == 1); // If it ran OK.
    else{  // If it did not run OK.
                    
    echo '<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';

    mysqli_close ($dbc);
    // End of main submit conditional.
    ?>
    i get this error:

    An error occurred in script '/home/content/83/8042383/html/add_profile.php' on line 99: Undefined variable: en
    Date/Time: 9-15-2011 14:55:59

    By the way, line 99 is the query part!
    Last edited by Inigoesdr; 09-15-2011 at 10:27 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    What on earth are you doing here?

    PHP Code:
    //*** if name is NOT entered *** - ! means not
    if (!isset($_POST['est_name'])) 
    // name is entered
     
    @$en $_POST['est_name']; // Set $en to a value that doesn't exist because isset() returned false ?!?!?!?!?!
    else{ $en '' ;

    Get rid of the ! there before the isset for a start. Then remove @.

    Also consider taking a look at the coding styles link in my signature below.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!


  •  

    Posting Permissions

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