dcsimg
www.webdeveloper.com
Results 1 to 8 of 8

Thread: page doesn't send Post into to another page

  1. #1
    Join Date
    May 2017
    Posts
    5

    page doesn't send Post into to another page

    I have two PHP pages that interact. The first one I select data and present it to th epage for editing. Each row has a submit that references an update page. Every submit works to update the DB EXCEPT for the first row. I set the update page to print the post data and to refresh for 1 second so I could see the post data. Editing the first row does not produce any post data in the second page. So I must have an error in the 1st page?

    Here is the 1st page:
    HTML Code:
    <!DOCTYPE html>
    <html>
    <head>
    <Title>Edit Template Settings</title>
    </head>
    <body>
    <p>CQ Simple Phone Provisioning System</p>
    <hr>
    
    <form action="" method="post">
    Template name to edit: <input type="text" name="tname"><br><input type="submit">
    
    <?php
    $tempname = $_POST['tname'];
    echo $tempname;
    $con = mysqli_connect('localhost','root','');
    $sql = "Select * from cqadmin.keys where templatename = '$tempname'";
    $records = mysqli_query($con,$sql);
    ?>
    <table>
    <tr>
    <th></th>
    <th></th>
    <th>Key Name</th>
    <th>Key Type</th>
    <th>Value</th>
    <th>Label</th>
    </tr>
    <?php
    while($row = mysqli_fetch_array($records))
    {
        echo "<tr><form action=update.php method=post>"; 
        echo"<td><input type=hidden name=id value='".$row['id']."'></td>";   
        echo"<td><input type=hidden name=name value='".$row['templatename']."'></td>";
        echo"<td><input type=hidden name=keyid value='".$row['keyid']."'></td>";
        echo"<td><input type=text name=key value='".$row['keyname']."'><Readonly></td>";
        echo"<td><input type=text name=type value='".$row['keytype']."'></td>";
        echo"<td><input type=text name=value value='".$row['keyvalue']."'></td>";
        echo"<td><input type=text name=label value='".$row['keylabel']."'></td>";
        echo "<td><input type=submit>";
        echo"</form></tr>";
    }
    
    ?>
    </body>
    </html>
    And the UPdate page
    HTML Code:
    <?php
    
    //Connect to MYSQL
    $conn = mysqli_connect("localhost","root","");
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    
    
    print_r($_POST);
    
    $sql = "UPDATE cqadmin.keys SET templatename='$_POST[name]',keyname='$_POST[key]',keyid='$_POST[keyid]',keytype='$_POST[type]',keyvalue='$_POST[value]',keylabel='$_POST[label]' where id='$_POST[id]'";
    
       //Execute the query
    if ($conn->query($sql) === TRUE) {
        header("refresh:10; url=keys.php");
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
    $conn->close();
    
    ?>
    Can someone tell me what is going on? I have tried different browsers. There are no errors

    Thanks

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,848
    You are missing a TON of quotes in your html. You might want to clean that up.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    May 2017
    Posts
    5
    Quote Originally Posted by ginerjm View Post
    You are missing a TON of quotes in your html. You might want to clean that up.
    I know My table is messed up. What quotes? the page works, well except for the main reason I posted..

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,543
    You should also format your form attributes, a <form tag in many servers needs the action to point to the receiving page, the enctype needs specifying and all good forms have a name (not an id) and some use the onsubmit to run a client side check to see if fields required are set (although now you can specify that in HTML5 inputs these days, its good for a fallback position where an older browser is used to view your site) before allowing the form to post, it is also good to have these details set so that if JavaScript is not available then the form will still post.

    Sanitize, Sanitize, Sanitize... NEVER!!! use $_POST directly in a database setting, a good method of dealing with web data is to only accept specific fields, check that the form is present and the request method is a post and I use a system of salting my forms so that I know where and when the form was issued and to what IP address. Always put sanitized data into an array so that you know that anything you access in that sanitized array is safe(er) and hasn't updated the form field as can happen when the server is bombarded with multiple requests.

    I would also use a session object per page to pass data relating to the current user, the time they got the page (so you can know how long and expire the page) and push them to login after 5 minutes inactivity (for example)
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  5. #5
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,848
    Proper HTML calls for attributes to be wrapped in quotes. In your example, this
    HTML Code:
      echo "<tr><form action=update.php method=post>"; 
        echo"<td><input type=hidden name=id value='".$row['id']."'></td>";   
    should be:
    HTML Code:
      echo "<tr><form action='update.php' method='post'>"; 
        echo"<td><input type='hidden' name='id' value='" . $row['id'] . "'></td>";   
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  6. #6
    Join Date
    May 2017
    Posts
    5
    Well, I wrapped all the html attributes as suggested. Still the first record cannot be edited/updated. All of what I am doing is on a closed system. The final goal here it to have a single button on the page to update all the records that are changed.

  7. #7
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,543
    After spending some time looking at your code, there are some strande construction going on, for a start you're nesting a form in a form, your supposed to seperate forms if you have more than one per page.

    PHP Code:
    <form action="" method="post">
    Template name to edit: <input type="text" name="tname"><br><input type="submit">

    <?php
    $tempname 
    $_POST['tname'];
    echo 
    $tempname;
    $con mysqli_connect('localhost','root','');
    $sql "Select * from cqadmin.keys where templatename = '$tempname'";
    $records mysqli_query($con,$sql);
    ?>
    is later followed on in the script
    PHP Code:
    <?php
    while($row mysqli_fetch_array($records))
    {
        echo 
    "<tr><form action=update.php method=post>"
        echo
    "<td><input type=hidden name=id value='".$row['id']."'></td>";   
        echo
    "<td><input type=hidden name=name value='".$row['templatename']."'></td>";
    which is clearly a form


    I would look at reworking the page.

    You should also go on to the PHP website and read up about mysqli_ type queries, they are no like mysql_ function, instead of forming a statement, opening the database, running the query and then fetching the results as needed, you have to make your open your database, create the statement, execute the query, bind the result to variables then you can fetch your results.

    http://php.net/manual/en/mysqli-stmt.fetch.php

    Also, when using naming conventions, it is advised that you avoid using a reserved word or a keyword like calling the name of an input <input name="name" can lead to problems, I find my server hates "submit" as the name of the submit button, if I call it Submit, then the server is happy, so finding out about any requirements your host is imposing on you is an important step because your web form may require additional scripting from the hosting server, one host I used insisted that you used a library that they wrote for their servers to ensure that your webform, if using email, your email had to exist on the server if sending a confirmation form.

    So in short, if something doesn't work on the server, then theres possibly a config issue, but looking at your script, you have some way to go in regards to outputing a web page and web form that isn't nested or likely to conflict with other forms (through nesting and overlapping of tags)
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  8. #8
    Join Date
    May 2017
    Posts
    5
    Thank you for taking the extra time to look at my mess. I admit I have limited know how in this area. Ideally I want to keep all the work needed to be done on a single page. I will see if I can wrap my head around the link you provided

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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