#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    6
    Rep Power
    0

    Php script not posting


    Hi dear ,

    I am facing one issue with the following code
    <?php
    //include db configuration file
    include_once("config.php");

    if(isset($_POST['content_txt'])|| $_POST['test'] && strlen($_POST["content_txt"])>0)
    { //check $_POST["content_txt"] is not empty

    //sanitize post value, PHP filter FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH Strip tags, encode special characters.
    $contentToSave = filter_var($_POST["content_txt"],FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
    $vr=$_POST['test'];
    // Insert sanitize string in record
    if(mysql_query("INSERT INTO add_delete_record(content,content1) VALUES('$contentToSave','$vr')"))


    {
    //Record was successfully inserted, respond result back to index page
    $my_id = mysql_insert_id(); //Get ID of last inserted row from MySQL
    echo '<li id="item_'.$my_id.'">';
    echo '<div class="del_wrapper"><a href="#" class="del_button" id="del-'.$my_id.'">';
    echo '<img src="images/icon_del.gif" border="0" />';
    echo '</a></div>';
    echo $contentToSave.'</li>';
    mysql_close($connecDB); //close db connection

    }else{


    header('Looks like mysql error, could not insert record!');
    exit();
    }

    }
    elseif(isset($_POST["recordToDelete"]) && strlen($_POST["recordToDelete"])>0 && is_numeric($_POST["recordToDelete"]))
    { //do we have a delete request? $_POST["recordToDelete"]

    //sanitize post value, PHP filter FILTER_SANITIZE_NUMBER_INT removes all characters except digits, plus and minus sign.
    $idToDelete = filter_var($_POST["recordToDelete"],FILTER_SANITIZE_NUMBER_INT);

    //try deleting record using the record ID we received from POST
    if(!mysql_query("DELETE FROM add_delete_record WHERE id=".$idToDelete))
    {
    //If mysql delete query was unsuccessful, output error
    header('Could not delete record!');
    exit();
    }
    mysql_close($connecDB); //close db connection
    }
    else
    {
    //Output error
    header('Error occurred, Could not process request!');
    exit();
    }
    ?>


    ----

    it is showing Undefined index: test in D:\wamp\www\response.php on line 10

    kindly help more than week i am trying
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,003
    Rep Power
    376
    if(isset($_POST['content_txt'])|| $_POST['test'] && strlen($_POST["content_txt"])>0)

    here is the error, notice that the error doesnt mention anything about content_txt just test, so just think what is happening and why the error would show up. Error is very SIMPLE and easy to understand (in this case anyway!)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    50
    Rep Power
    2
    You make it really difficult for people to want to help you... no indent, no PHP wrap...

    And yet I always get the popup

    "You appear to be posting some code, but have omitted [code] or [php] tags from your message."
    All generalizations are false, including this one. Free hosting
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    @freak: His post didn't have proper whitespace to begin with, the popup isn't perfect.

    @paul: That line is not the line throwing the error, see #2 below

    albattashi, please read the new user guide, located below this message. As other posters have said, your code is incorrectly formatted and difficult to read. In addition, your error is very easy to understand. Why have you been working a week on this problem? What do you think the error means? What did you try to fix it?

    Line 10 is mentioned in the error. Line 10 is:
    PHP Code:
    $vr=$_POST['test']; 
    (note that the line is properly colored since I used the correct tags)

    So that means that $_POST['test'] doesn't exist. You must either:
    1) Check for its existence directly before you use it.

    2) Alter the larger IF statement that bounds your whole data, so that it properly validates your data:
    PHP's operators do not have the precedence you think they do. They do not take any "hints", they are explicit. You have:
    PHP Code:
    if(isset($_POST['content_txt'])|| $_POST['test'] && strlen($_POST["content_txt"])>0
    That means "if $_POST['content_txt'] is set, it's ok. If it's not set, then $_POST['test'] AND the length of content_txt is longer than zero both have to be true." Since $_POST['content_txt'] is always set, the rest of the line is skipped entirely and $_POST['test'] isn't even touched. That's incorrect, no matter what you're doing here. What were you actually trying to do with this line?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo