+ Reply to Thread
Results 1 to 2 of 2

Thread: help with php

  1. #1
    goldy300's Avatar
    goldy300 is offline x10Hosting Member goldy300 is an unknown quantity at this point
    Join Date
    Jul 2008
    Location
    Australia
    Posts
    33

    Post help with php

    I'm here all night to try and get this done. I have to fix a form up to take petition title, petition, category, duation, target, short title (for url) and keywords and insert them into a database.

    I need the form to validate. No empty fields and the form has to pass to a preview page before its inserted into the database for review. The petition should not submit if the user has not signed up and logged in.

    I can show you some of what I have but its the basics as I'm not very well versed on php and need the help urgently.

    I would appreciate if you contact me via msn and I can work, chat and upload files as we go. Add me airbrushkits@live.com

    Here is a link to the page: http://daniel.classroomonline.info/g...=startpetition

    Heres what I have:
    HTML Code:
    <?php
    
        
        mysql_query("INSERT INTO petitons SET petitions_id='',members_id='',short_name='$_POST[short_name]',p_title='$_POST[p_title]',target='$_POST[target]',petition='$_POST[petition]',duration='$_POST[duration]',category='$_POST[category]',keywords='$_POST[keywords]'");
       
    
    ?>
                        <p>&nbsp;</p>
    
                        <form method="post" name="form1" action="insertpetition.php"> 
    
                        
                        <b>The petition of citizens and residents of Australia call on the Australian Government to...</b><br>
                            <input type="text" name="p_title" size="60" class="normtext"></p>
    
                        <p>&nbsp;</p>
    
                        More details about your petition (1000 characters maximum):<br>
                            <textarea rows="6" cols="60" class="normtext" name="petition"></textarea><p>
                        <p>&nbsp;</p>
    
                        Select Duration:    <select name="duration">
                                                            <option value="1month">1 Month</option>
                                                             <option value="3months">3 Months</option>
                                                            <option value="6months">6 Months</option>
                                                            <option value="1year">1 Year</option>
                                                        </select>
                                                            
                        
                        <p>&nbsp;</p>    
    
                        Select a short name for your petition (Max 20 characters): <input type="text" name="short_name" class="normtext"><br>
                            <span class="smalltext">This gives your petition an easy web address. e.g. (http://www.govpetitions.com.au/newpark)</span><p>
                        
                        <p>&nbsp;</p>
    
                                Please select a category for your petition<br>
                                <select class="normtext" name="category">
                                    <OPTION>Select a category</OPTION>
                                    <option value="counsel">Counsel</option>
                                    <option value="roads">Roads & Traffic</option>
                                    <option value="aboriginal">Aboriginal Affairs</option>
                                    <option value="health">Health</option>
                                    <option value="rural">Rural</option>
                                    <option value="residential">Residential</option>
                                    <option value="education">Education</option>
                                    <option value="law_enforcement">Law Enforcement</option>
                                    <option value="correctional">Correctional</option>
                                    <option value="development">Development</option>
                                    <option value="work_rights">Work Rights</option>
                                    <option value="religion">Religion</option>
                                    <option value="imigration">Imigration</option>
                                    <option value="national">National</option>
                                    <option value="state">State</option>
                                    <option value="other">Other</option>
                                </select>
    
                        <p>&nbsp;</p>
                            
                        Please enter keyword which are relevant to what your petition is about:<br>
                        <span class="smalltext">Separate keywords with comma only. E.g. license,driving,disqalified</span><br>
                        <input type="text" name="keywords" size="50">
                        <br>&nbsp;</br>
    
                        <center><input type="image" name="submit" src="http://forums.x10hosting.com/images/preview.gif" ></center>
    
                        </form>
    My table in the db is like this:

    Table name is petitions

    Fields:
    • petitions_id
    • members_id
    • short_name
    • p_title
    • target
    • petition
    • duration
    • category
    • keywords
    In that order
    Last edited by goldy300; 12-03-2008 at 07:21 AM.

  2. #2
    freecrm's Avatar
    freecrm is offline x10 Elder freecrm is an unknown quantity at this point
    Join Date
    May 2008
    Location
    UK
    Posts
    629

    Re: help with php

    First off, you already have a form validation topic running at http://forums.x10hosting.com/program...lp-needed.html

    The petition should not submit if the user has not signed up and logged in.
    Simple - just have a bit of code like this at the top of the page (after session_start();)

    PHP Code:
    <?php

    if (isset($_SESSION['username'])) { //ask if a user is logged in by checking if a username variable is in session memory

    ****put your form and processing code here****
    } else {
    // if a user is not logged in then...
    echo "You need to be logged in to do this";
    ?>
    the form has to pass to a preview page before its inserted into the database
    If you want to do this, forget about inserting anything on this page. (i.e. remove the mysql_query) and just stick to the form.

    The form action will simply be the URL of a preview page (we'll call it "formpreview.php"

    To create your preview page, simply put your mysql_query at the top with a condition that the entries have been confirmed and then echo each value to be inserted from the $_POST values from the previous page.

    i.e.

    PHP Code:
    <?php

    echo $_POST['p_title']."</br>";
    echo 
    $_POST['petition']."</br>";
    echo 
    $_POST['duration']."</br>";
    echo 
    $_POST['category']."</br>";
    echo 
    $_POST['keywords']."</br>";
    ?>
    Then create a form at the base.

    Put in a hidden field with a name like "form_submitted" and a default value of "Y".

    Put in a "confirm" or "submit" button) and form action is "" (submit only)

    I haven't checked the following code but its along the right lines for your preview page.

    PHP Code:
    <?php
    session_start
    ();
    if (isset(
    $_SESSION['username'])) { //ask if a user is logged in by checking if a username variable is in session memory
    $post_form $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $post_form .= "?" $_SERVER['QUERY_STRING'];
    }
    if ((isset(
    $_POST["form_submitted"])) && ($_POST["form_submitted"] == "form1")) {
      
    mysql_query("INSERT INTO ... blah blah values from $_POST") or die(mysql_error());
    }
    ?>
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <h1>Preview</h1>
    <?php
    echo $_POST['p_title']."</br>";
    echo 
    $_POST['petition']."</br>";
    echo 
    $_POST['duration']."</br>";
    echo 
    $_POST['category']."</br>";
    echo 
    $_POST['keywords']."</br>";
    ?>
    <form name="form1" method="POST" action="<?php echo $post_form?>">
    <input name="form_submitted" type="hidden" id="form_submitted" value="Y">
    <input type="submit" name="Submit" value="Submit">
    </form>
    </body>
    </html>
    <?php } else {// if a user is not logged in then...
    echo "You need to be logged in to do this";
    ?>

+ Reply to Thread

Similar Threads

  1. Ever Been Suspended For Using PHP?
    By dragoneye_xp in forum Off Topic
    Replies: 26
    Last Post: 08-16-2009, 07:17 PM
  2. [PHP] Variables in PHP
    By Bryon in forum Tutorials
    Replies: 15
    Last Post: 01-29-2009, 09:46 AM
  3. currently have an application pending php
    By biomasti in forum Free Hosting
    Replies: 1
    Last Post: 09-03-2008, 01:58 PM
  4. php errors galore
    By DMG Online in forum Scripts & 3rd Party Apps
    Replies: 9
    Last Post: 05-17-2008, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers