SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP + MySQL + HTML

    I am having an issue that I can not seem to resolve, I have a page that queries a database, from this query it lists information so that a report can be input into the database. The problem I am having is that with the current code it is not submitting the "report" section due to a conflict of html naming attribute. here is the current code

    PHP Code:

    <?php 

    <?php

     mysql_connect
    ("*","*","*") or die(mysql_error()); 
     
    mysql_select_db("*") or die(mysql_error()); 
     
     
    $sql "Select form_id,Location, dateofexam, Pfirstname, Plastname, dob, examtype, views, history, notes, orderingphysician, contactphone, statread, priors, stattranscribe, dtrcompleted, rcompletedby From formdata WHERE rcompleted ='y' and tcompleted =''";
    $result MYSQL_QUERY($sql);


    while (
    $row=mysql_fetch_array($result))

    if (
    $row[statread] == 'yes'){echo "<tr>
    <td class='c22' bgcolor='red'><center><input type='checkbox' name='tcompleted[]' value='
    $row[form_id]'></center></td>
    <td class='c1' bgcolor='red'>
    $row[form_id]</td>
    <td class='c2' bgcolor='red'>
    $row[Location]</td>
    <td class='c3' bgcolor='red'>
    $row[dateofexam]</td>
    <td class='c4' bgcolor='red'>
    $row[Plastname]</td>
    <td class='c5' bgcolor='red'>
    $row[Pfirstname]</td>
    <td class='c6 ' bgcolor='red'>
    $row[dob]</td>
    <td class='c7' bgcolor='red'>
    $row[examtype]</td>
    <td class='c8' bgcolor='red'>
    $row[views]</td>
    <td class='c9' bgcolor='red'>
    $row[history]</td>
    <td class='c10' bgcolor='red'>
    $row[notes]</td>
    <td class='c11' bgcolor='red'>
    $row[orderingphysician]</td>
    <td class='c12' bgcolor='red'>
    $row[contactphone]</td>
    <td class='c13' bgcolor='red'>
    $row[rcompletedby]</td>
    <td class='c14' bgcolor='red'>
    $row[priors]</td>
    <td class='c15' bgcolor='red'>
    $row[dtrcompleted]</td>
    <td class='c16' bgcolor='red'><textarea id='report' name='report' cols='40' rows='1' tabindex='1'></textarea></td>
    <td class='c23' bgcolor='red'><center><select name='rcompleted' tabindex='7'>
                                    <option value='' selected='yes'></option>
                                             </select></center>
                            </td>
    </tr>"
    ;}


    ?>
    After you Submit this "form" it is supposed to update four things, and here is the script for that

    PHP Code:

    <?php

    session_start
    ();

    if (!(isset(
    $_SESSION['role']) && $_SESSION['role'] != '')) {
    header ("Location: main_login.php");
    }

    if(
    $_SESSION['role'] !== 'Transcriptionist')  {
    header ("Location: access.php");
    }

     
    mysql_connect("*","*","*") or die(mysql_error()); 
     
    mysql_select_db("*") or die(mysql_error()); 
     
    $com = @implode(','array_map('intval'$_POST['tcompleted']));
    $user=$_SESSION["myusername"];
    $rcompleted=mysql_escape_string($_POST['rcompleted']);
    $report=mysql_escape_string($_POST['report']);


    // update all the checked exams

    $sqlc "UPDATE formdata SET tcompleted='y' where form_id IN ($com)";
    $sqlct "UPDATE formdata SET tcompletedby='$user' where form_id IN ($com)";
    $sqlrc "UPDATE formdata SET rcompletedby='$rcompleted' where form_id IN ($com)";
    $sqlrep"UPDATE formdata SET report='$report' where form_id IN ($com)";


    mysql_query($sqlc);
    mysql_query($sqlct);
    mysql_query($sqlrep);
    mysql_query($sqlrc);

    ?>
    So again my issue is that because the name attribute for "report" is the same for every SQL row it causes conflict with the $_POST data.

    I had a thought to add this code to the query page
    PHP Code:
    <td class='c16' bgcolor='red'><textarea id='report' name='$row[form_id]report' cols='40' rows='1' tabindex='1'></textarea></td
    But the problem I couldnt figure out is how to have the mysql query update using that Variable POST name

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Karchion View Post
    PHP Code:
    <td class='c16' bgcolor='red'><textarea id='report' name='$row[form_id]report' cols='40' rows='1' tabindex='1'></textarea></td
    But the problem I couldnt figure out is how to have the mysql query update using that Variable POST name
    Add that code, do a print_r($_POST) on the form data handling script and see what is in there.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The array accessing is not going to work without dropping in and out of string concatenation.

    example:
    PHP Code:
    $a = array('this'=>'that');

    echo 
    "string with ".  $a['this']. " in it";

    // gives: string with that in it

    echo "string with  $a['this'] in it";
    // gives: error 
    Also you are not correctly quoting the result array keys.
    PHP Code:
    {echo "<tr>
    <td class='c22' bgcolor='red'><center><input type='checkbox' name='tcompleted[]' value='
    $row[form_id]'></center></td>
    <td class='c1' bgcolor='red'>
    $row[form_id]</td>
    // ad nauseum 
    SB:
    PHP Code:
    {echo "<tr>
    <td class='c22' bgcolor='red'><center><input type='checkbox' name='tcompleted[]' value='"
    $row['form_id'] ."'></center></td>
    <td class='c1' bgcolor='red'>" 
    $row['form_id'] . "</td>
    // ad nauseum 

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,995
    Mentioned
    100 Post(s)
    Tagged
    0 Thread(s)
    You can wrap { } around them eg. {$row['form_id']} which saves having to drop in and out of string concatenation
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    .. nice one - but readability is why I prefer using the object notation in my result sets:

    "number $row->form_id"


Bookmarks

Posting Permissions

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