SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    changing dtat in an autopopulating form

    I have a form which is autopopulated. I need my users to be able to make changes to it when necessary. The problem is my users can change whatever needs to be changed but when they hit submit it doesn't change anything in the database.
    PHP Code:
    <form name="FormName" action="<?=$PHP_SELF;?>" enctype="multipart/form-data" method="post">

    $query="SELECT * FROM abc_tables WHERE table_id=$table_id";
    $result=mysql_query($query);
    while ($row = mysql_fetch_assoc($result))
    {
    $rest_name = $row['rest_name'];

    <input type="text" class="formTextbox" name="rest_name" size="24" value="<?="$rest_name"?>">

    <input type="submit" name="submit" class="formTextbox" value="Submit">

  2. #2
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're going to need to do an update on the next page to set the columns in the database. You'll have to store the id for the row in a hidden field so that you know which row to update.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  3. #3
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres what I have now:
    At the top:
    PHP Code:
    function update_db()
    {
    if (
    $_POST['submit']){
    $contact_fname $_POST['contact_fname'];
    mysql_query("UPDATE abc_tables SET contact_fname='$contact_fname'");
    }} 
    Then:
    PHP Code:
    <input type="text" class="formTextbox" name="contact_fname" size="24" value="<?="$contact_fname"?>">
    At the bottom:
    PHP Code:
    <input type="submit" name="submit" class="formTextbox" value="Submit" onsubmit="<?=update_db();?>">
    But it still dosen't update the database.

  4. #4
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you calling the function?

    Also that query's not good; you'll update all your rows if you do that. YOu have to add a where clause to restrict the update to one row.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  5. #5
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to call the function with onsubmit="<?=update_db();?>"

    Here is the new query:
    PHP Code:
    function update_db()
    {
    if (
    $_POST['submit']){
    $contact_fname $_POST['contact_fname'];
    mysql_query("UPDATE abc_tables SET contact_fname='$contact_fname' WHERE table_id=$table_id");
    }} 

  6. #6
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have to use java. I just thought it might be easier. Here is all the relevent code:


    PHP Code:
    $update_query="UPDATE abc_tables SET contact_fname=$contact_fname WHERE tabel_id=$table_id";
    <form name="FormName" action="<?=$_server['PHP_SELF'];?>" enctype="multipart/form-data" method="post">
    <?php
    $query
    ="SELECT * FROM abc_tables WHERE table_id=$table_id";
    $result=mysql_query($query);
    while (
    $row mysql_fetch_assoc($result))
    {
    $contact_fname $row['contact_fname'];
    }
    ?>
    <table>
    <tr>
    <td>Contact First Name</td>
    </tr>
    <tr>
    <td>
    <input type="text" class="formTextbox" name="contact_fname" size="24" value="<?="$contact_fname"?>"></td>
    </tr>
    //////////////////////
    <tr>
    <td>
    <input type="submit" name="submit" class="formTextbox" value="Submit">
    </td>
    </tr>
    </table>
    <?
    mysql_close
    ();
    ?>

  7. #7
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Create you a form handler page, go to this page on submission.
    Do whatever data processing you need to (ie; add, update, delete)
    Return to your form page via header();
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.

  8. #8
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK so I changed this:
    PHP Code:
    <form name="FormName" action="<?=$_server['PHP_SELF'];?>" enctype="multipart/form-data" method="post">
    to this:
    PHP Code:
    <form name="FormName" action="table_order_handler.php" enctype="multipart/form-data" method="post"
    and added this:
    table_order_handler.php
    PHP Code:
    <?php
    error_reporting
    (0); 
    include(
    'include/user_check.php'); 
    include(
    'include/db_con.php');

    $query="SELECT * FROM abc_tables WHERE table_id=$table_id";
    $result=mysql_query($query);
    while (
    $row mysql_fetch_assoc($result))
    {
    $rest_name $row['rest_name'];
    }

    $query_update="UPDATE abc_tables SET contact_fname=$contact_fname WHERE tabel_id=$table_id";
    mysql_query($query_update);

    echo 
    "The Table Order Form for $rest_name has been updated.";
    ?>
    but still nothing

  9. #9
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where's this $table_id coming from?

    Also you have a typo in your second query; it should be table_id, not tabel_id.
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  10. #10
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    table_id comes from here

    PHP Code:
    <?php
        
    include('include/user_check.php');
        include(
    'include/db_con.php');
        
    $id $_SESSION['track_id'];
            
        
    $abc_current_tables mysql_query("SELECT table_id , rest_name , set_no , status_3, dist_id FROM abc_tables WHERE status_2<'6' order by rest_name"$db_link);
            
    $num_current_tables mysql_num_rows($abc_current_tables);
    ?>

    <HTML>
    <HEAD>
    <link rel="stylesheet" type="text/css" href="main.css">
    <link rel="stylesheet" type="text/css" href="styles.css">
    <TITLE>:: In-House Projects ::</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    </HEAD>
    <BODY BGCOLOR=#FFFFFF leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
            <div align="center">
                <TABLE WIDTH=758 BORDER=0 CELLPADDING=0 CELLSPACING=0>
                
                    <? include('include/top.php'); ?>
                    <TR height="516">
                        <TD valign="top" height="516">
                            <div align="center">
                                <form name="FormName" action="update_table_order_form.php" method="post">
                                    <b>Restaurants </b>(<? echo $num_current_tables?>)<br>
                                    <select name="table_id" class="formTextbox" size="1">
                                        <option value="">-- Select a Restaurant --</option>
                                    <?  while($row_current_tables mysql_fetch_array($abc_current_tables)) {    

                                            
    $table_id $row_current_tables['table_id'];
                                            
    $rest_name $row_current_tables['rest_name'];
                                            
    $set_no $row_current_tables['set_no'];
                                            
    $dist_id $row_current_tables['dist_id'];
                                            
    $query_dist mysql_query("SELECT fname, lname, sales_id FROM sales_rep WHERE sales_id = '$dist_id'"$db_link);
                                            while (
    $row_dist_name mysql_fetch_array($query_dist)){
                                            
                                            
    $dist_lname $row_dist_name['lname'];
                                            
    $dist_fname $row_dist_name['fname'];
                                            } 
                                            
                                    
    ?>
                                        <option value="<?=$table_id;?>"><? echo $rest_name" Set " .$set_no"--" .$dist_lname", " .$dist_fname;?></option>
                                        <? ?>
                                    </select><br>
                                    <input type="submit" class="formTextbox" name="submit" value="Get Table Info"><br>
                                    </form>
                        </TD>
                    </TR>
                    <TR>
                        <TD COLSPAN=3><IMG SRC="images/inside_08.gif" WIDTH=758 HEIGHT=2></TD>
                    </TR>
                </TABLE>                                
    </body>
    </html>

  11. #11
    SitePoint Wizard bronze trophy devbanana's Avatar
    Join Date
    Apr 2006
    Location
    Pennsylvania
    Posts
    1,736
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then you are relying upon register globals? You shouldn't do that. Use $_POST['table_id']
    Laudetur Iesus Christus!
    Christ's Little Flock
    Jesus is the Good Shepherd

  12. #12
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As it turns out I needed to add a hidden field to my form
    PHP Code:
    <input type="hidden" name="table_id" value="<?="$table_id"?>">
    that way $table_id gets posted to the handler page

    thanks for all your help!


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
  •