www.webdeveloper.com
Results 1 to 9 of 9

Thread: variable table name/hidden form

  1. #1
    Join Date
    Mar 2011
    Posts
    8

    variable table name/hidden form

    the input

    PHP Code:
    <?php
    $name
    =$_POST['name'] ;
    $location=$_POST['location'];
    $comment=$_POST['comment'];
    $submit=$_POST['submit'];

    if (
    $submit)
    {
            if(
    $name&&$comment)
            {
                    
    $insert=mysql_query("INSERT INTO $table (name,location,comment) VALUES ('$name','$location','$comment')") ;
                    echo 
    mysql_error();
                    
    header('Location: succes.php');
            }
            else
            {
                    echo 
    "please fill all the fields";
            }
    }
    ?>

    the output


    PHP Code:
    <?php
    $getquery
    =mysql_query("SELECT * FROM $table ORDER BY id DESC");
    while(
    $rows=mysql_fetch_array($getquery))
    {
            
    $id=$rows['id'] ;
            
    $name=$rows['name'] ;
            
    $location=$rows['location'] ;
            
    $comment=$rows['comment'] ;

            
    $comment2=wordwrap($comment80"<br />"true);

            echo 
    "<div id='comment' align='left'><b>Name: </b>$name <br /><b>Location: </b>$location<br /><br /><b><i>Comment:</i></b><br />$comment2<br /><hr size='1'></div>"
    ;}
    echo 
    mysql_error();

    ?>

    action script

    PHP Code:
    <?php
    require('boondocksconnect.php');
    if(isset(
    $_POST['submit']))

    $name $_POST['name'] ;
    $location $_POST['location'];
    $comment $_POST['comment'];
    $submit $_POST['submit'];

    if((!
    $name) || (!$comment)){

    echo 
    "please fill all the fields";

    }else{

     
    mysql_query("INSERT INTO episode1 (name,location,comment) VALUES ('$name','$location','$comment')") ;
    header('Location: succes.php');

    }

    ?>

    the form

    HTML Code:
    <form action="comment_boondocks_episode1.php" method="post">
    <table>
    <tr><td colspan ="2"><h3>Add a Comment</h3></td></tr>
    <tr><td>Name:</td><td><input type="text" name="name" /></td></tr>
    <tr><td>Location:</td><td><input type="text" name="location" /></td></tr>
    <tr><td colspan ="2">Comment:</td></tr>
    <tr><td colspan ="2"><textarea name="comment" rows="10" cols="60" ></textarea></td></tr>
    <tr><td colspan ="2"><input type="submit" name="submit" value="comment" /></td></tr>
    </table>
    </form>


    is there any way I could use a single action script with a variable hidden form
    and call that hidden variable in the input output???

    thanks in advance skela

  2. #2
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    I'm not entirely sure what you are asking but you can always do something like

    <input type="hidden" name="epinum" value="1">

    Then just call that in the action via $_POST['epinum'] like any other field. You could populate this field by setting the link to the form to have the episode number in the url and use $_GET to insert it.

    Again I'm not sure what you are doing, but I hope thats along the lines of what you are looking for.

  3. #3
    Join Date
    Mar 2011
    Posts
    8
    I want every form to have its hidden value (episode number)
    but how do I call that in the Action Script? and in the input and output scripts?

  4. #4
    Join Date
    Mar 2011
    Posts
    8
    Quote Originally Posted by Derokorian View Post
    I'm not entirely sure what you are asking but you can always do something like

    <input type="hidden" name="epinum" value="1">

    Then just call that in the action via $_POST['epinum'] like any other field. You could populate this field by setting the link to the form to have the episode number in the url and use $_GET to insert it.

    Again I'm not sure what you are doing, but I hope thats along the lines of what you are looking for.
    Can you be a bit more clear on that part cause i think thats what I need.

  5. #5
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    Ok so you have a list (ideally pulled from you DB) of episodes and a number uniquely identifying each episode in that DB. The link to comment on that episode might be

    <a href="comment_form.php">comment on this episode</a>

    you could change it to

    <a href="comment_form.php?episode=EPISODE_ID">

    I dont know how you get printing your episodes or getting that info so I can't really do that for ya off hand but then in the form file you would do at the top something like:
    PHP Code:
    <?
    $episode 
    = ISSET($_GET['episode']) ? $_GET['episode'] : "";
    ?><form action="comment_boondocks_episode1.php" method="post">
    <input type="hidden" name="episode" value="<?=$episode?>" />
    <table>
    <tr><td colspan ="2"><h3>Add a Comment</h3></td></tr>
    <tr><td>Name:</td><td><input type="text" name="name" /></td></tr>
    <tr><td>Location:</td><td><input type="text" name="location" /></td></tr>
    <tr><td colspan ="2">Comment:</td></tr>
    <tr><td colspan ="2"><textarea name="comment" rows="10" cols="60" ></textarea></td></tr>
    <tr><td colspan ="2"><input type="submit" name="submit" value="comment" /></td></tr>
    </table>
    </form>
    Then in your action script you would add $episide = $_POST['episode'];

    To be able to retirve that data later you would need to add an episode_id column to your comment table, and insert this number there... then on a page viewing that episodes comments you could write your sql like:
    SELECT * FROM <<COMMENT TABLE>> WHERE episode_id=<<EPISODE ID>>

    I hope you get the drift of what I'm saying, I'm not the best at explaining things.

  6. #6
    Join Date
    Mar 2011
    Posts
    8
    Quote Originally Posted by skela View Post
    the input

    PHP Code:
    <?php
    $name
    =$_POST['name'] ;
    $episode =$_POST['epinum'];
    $location=$_POST['location'];
    $comment=$_POST['comment'];
    $submit=$_POST['submit'];

    if (
    $submit)
    {
            if(
    $name&&$comment)
            {
                    
    $insert=mysql_query("INSERT INTO $episode (name,location,comment) VALUES ('$name','$location','$comment')") ;
                    echo 
    mysql_error();
                    
    header('Location: succes.php');
            }
            else
            {
                    echo 
    "please fill all the fields";
            }
    }
    ?>

    the output


    PHP Code:
    <?php
    $getquery
    =mysql_query("SELECT * FROM $episode ORDER BY id DESC");
    while(
    $rows=mysql_fetch_array($getquery))
    {
            
    $id=$rows['id'] ;
            
    $name=$rows['name'] ;
            
    $location=$rows['location'] ;
            
    $comment=$rows['comment'] ;

            
    $comment2=wordwrap($comment80"<br />"true);

            echo 
    "<div id='comment' align='left'><b>Name: </b>$name <br /><b>Location: </b>$location<br /><br /><b><i>Comment:</i></b><br />$comment2<br /><hr size='1'></div>"
    ;}
    echo 
    mysql_error();

    ?>

    action script

    PHP Code:
    <?php
    require('boondocksconnect.php');
    if(isset(
    $_POST['submit']))

    $name $_POST['name'] ;
    $episode =$_POST['epinum];
    $location = $_POST['
    location'];
    $comment = $_POST['
    comment'];
    $submit = $_POST['
    submit'];

    if((!$name) || (!$comment)){

    echo "please fill all the fields";

    }else{

     mysql_query("INSERT INTO $episode (name,location,comment) VALUES ('
    $name','$location','$comment')") ;
    header('
    Locationsucces.php');

    }

    ?>

    the form

    HTML Code:
    <form action="comment_boondocks_episode1.php" method="post">
    <table>
    <tr><td colspan ="2"><h3>Add a Comment</h3></td></tr>
    <input type="hidden" name="epinum" value="1">
    <tr><td>Name:</td><td><input type="text" name="name" /></td></tr>
    <tr><td>Location:</td><td><input type="text" name="location" /></td></tr>
    <tr><td colspan ="2">Comment:</td></tr>
    <tr><td colspan ="2"><textarea name="comment" rows="10" cols="60" ></textarea></td></tr>
    <tr><td colspan ="2"><input type="submit" name="submit" value="comment" /></td></tr>
    </table>
    </form>


    is there any way I could use a single action script with a variable hidden form
    and call that hidden variable in the input output???

    thanks in advance skela
    what should I use in the output file?

  7. #7
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    also why do you have an action script AND an input script? they are (especially in this example) doing the same thing.

  8. #8
    Join Date
    Mar 2011
    Posts
    8
    So I don't need an input script at all?

  9. #9
    Join Date
    Mar 2011
    Posts
    8
    Issue Resolved.

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



Recent Articles