Hi all

If anyone can provide some light on this one it would be very much appreciated!

I have spent a few hours on this one trying to figure out why, when i try and submit a form via HTML to a PHP script it seems to fail and not forward anything to the PHP script.

Unfortuntly it has been a while since i have done HTML / PHP coding so i have opted for a HTML template (please bear with me!).

The code i have for the HTML:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Item Dispatch</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>

</head>
<body id="main_body">

    <img id="top" src="top.png" alt="">
    <div id="form_container">

        <h1><a>Item Dispatch</a></h1>
        <form id="form_379825" class="appnitro" action="action.php" method="post">

        <div class="form_description">
            <h2>Item Dispatch</h2>
            <p>Please fill out the required details...
            </p>
        </div>
        <ul >

        <li id="li_1" >
        <label class="description" for="element_1">Item Model </label>
        <span>
            <input id="element_1_1" name="router_model" class="element radio" type="radio" value="1" checked="checked"/>
            <label class="choice" for="element_1_1">Item 1</label>
            <input id="element_1_2" name="router_model" class="element radio" type="radio" value="2" />
            <label class="choice" for="element_1_2">Item 2</label>
            <input id="element_1_3" name="router_model" class="element radio" type="radio" value="3" />
            <label class="choice" for="element_1_3">Item 3</label>

        </span> 
        </li>

        <li id="li_9" >
        <label class="description" for="element_9">Stock Status </label>
        <span>
            <input id="element_9_1" name="router_status" class="element radio" type="radio" value="1" checked="checked"/>
            <label class="choice" for="element_9_1">Dispatched</label>
            <input id="element_9_2" name="router_status" class="element radio" type="radio" value="2" />
            <label class="choice" for="element_9_2">On Loan</label>
            <input id="element_9_3" name="router_status" class="element radio" type="radio" value="3" />
            <label class="choice" for="element_9_3">In Stock</label>

        </span> 
        </li>
        <li id="li_2" >
            <label class="description" for="element_2">Username </label>
        <div>
            <input id="element_2" name="element_2" class="element text medium" type="text" name="username" maxlength="255" value="Hello World!"/>
        </div>
        </li>
        <li id="li_3" >
            <label class="description" for="element_3">Password </label>
        <div>
            <input id="element_3" name="element_3" class="element text medium" type="text" name="password" maxlength="255" value="qwerty123"/> 
        </div> 
        </li>
        <li id="li_4" >
            <label class="description" for="element_4">Serial Number </label>
        <div>
            <input id="element_4" name="element_4" class="element text medium" type="text" name="serial" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_5" >
            <label class="description" for="element_5">MAC </label>
        <div>
            <input id="element_5" name="element_5" class="element text medium" type="text" name="mac" maxlength="255" value=""/> 
        </div> 
        </li>
        <li class="buttons">
                <input type="hidden" name="form_id" value="379825" />

                <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
            </li>
            </ul>
        </form> 


        <form action="action.php" method="post">
        Please enter your username?
        <input type="text" name="router_username" maxlength="50" value="random-username-1234">
        <input type="submit" name="Submit" value="Submit">
        </form>


        <div id="footer">
            Generated by <a href="http://www.google.co.uk">pForm</a>
        </div>
    </div>
    <img id="bottom" src="bottom.png" alt="">


    </body>
</html>

On the PHP side i have:

<?php

// Obtain information from form into variables
$user = $_POST['username'];
$password = $_POST['password'];
$serial = $_POST['serial'];
$mac = $_POST['mac'];

// Post the details to the new webpage
echo $user;
echo $password;

?>

I have added a small snippet of code beneth just to check to see if a normal form works okay and it does appear to. Any ideas welcome, i'm sure it's something glaringly obvious...

Thanks in advance :]

Recommended Answers

All 2 Replies

Hey,
Bold Text Here
Why are you repeating name in all of the fields you are trying to process?

 <label class="description" for="element_2">Username </label>
    <div>
            <input id="element_2" **name="element_2"** class="element text medium" type="text" **name="username"**
            maxlength="255" value="Hello World!"/>

Could be your problem. Only have one name, in this case "username" then the PHP will know which texfield to get data from.

D'oh!! I knew it was bound to be something simple like that... Worked a treat! Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.