0

I need to get the form to send to two different tables in my MySQL, it always stops at my if(!$_POST['submit']) location. I really need your help have been trying different things for almost 24 hours straight.

HTML

<form action="php/createhemerb.php" method="post">

            <input  type="text" name="inputName" value="" id=""> </input> </br>
            <input  type="text" name="inputPage" value="http://" id=""> </input> </br>
            <textarea type="text" name="inputComment" value="" id="" size="50" style="height:100px; width:400px;"> </textarea>  
            <input type="checkbox" name="inputFs" value="checked" id=""/>
            <input type="checkbox" name="inputFsn" value="checked" id=""/>
            <input type="checkbox" name="inputFsj" value="checked" id=""/>
            <input type="checkbox" name="inputFsjn" value="checked" id=""/>
            <input type="text" name="inputBeS" value="" id="" size="50"> </input>
            <input type="text" name="inputBeK" value="" id="" size="50"> </input>

            <a href="http://digsitesvalue.com/" target="_new"></a><br/><br/>

            </br><input type="checkbox" name="inputAll" value="checked" id=""/>Alla
            </br><input type="checkbox" name="inputKun" value="checked" id=""/>Kundtjänstarbeten
            </br><input type="checkbox" name="inputByg" value="checked" id=""/>Bygg, Anläggning
            </br><input type="checkbox" name="inputEko" value="checked" id=""/>Ekonomi, Finans, Försäkring
            </br><input type="checkbox" name="inputFor" value="checked" id=""/>Försäljning, marknad, reklam
            </br><input type="checkbox" name="inputHR" value="checked" id=""/>HR, juridik
            </br><input type="checkbox" name="inputHal" value="checked" id=""/>Hälso-, Sjukvård, Omsorg
            </br><input type="checkbox" name="inputInd" value="checked" id=""/>Industri, produktion
            </br><input type="checkbox" name="inputInk" value="checked" id=""/>Inköp, Transport, Logistik
            </br><input type="checkbox" name="inputIT" value="checked" id=""/>IT, data
            </br><input type="checkbox" name="inputKon" value="checked" id=""/>Kontor, Administration
            </br><input type="checkbox" name="inputKul" value="checked" id=""/>Kultur, Media
            </br><input type="checkbox" name="inputKva" value="checked" id=""/>Kvalitet, miljö
            </br><input type="checkbox" name="inputMan" value="checked" id=""/>Management
            </br><input type="checkbox" name="inputPed" value="checked" id=""/>Pedagogiska arbeten
            </br><input type="checkbox" name="inputSer" value="checked" id=""/>Service, detaljhandel, butik
            </br><input type="checkbox" name="inputTek" value="checked" id=""/>Teknik, Naturvetenskap
            </br><input type="checkbox" name="inputBen" value="checked" id=""/>Bemanningsföretag
            </br><input type="checkbox" name="inputOff" value="checked" id=""/>Offentlig sektor

            <input type="text" name="inputFon" value="" id="fnid" hidden/>
            <input  type="text" name="inputJob" value="" id="fnid" hidden/>
            <br/><input  type="text" name="inputHem" value="" id="" style="width:300px;"/>          <br/>
            <br/><input  type="text" name="inputPla" value="" id="" style="width:300px;"/>          <br/>
            <br/><textarea name="inputKom" id="" style="height:100px; width:300px;"></textarea> <br/>
            <br/><input type="text" name="inputPri" value="" style="width:100px;" id=""/>sek        <br/>
            <input type="text" name="inputFid" value="" id="idet" hidden/>
            <input hidden type="text" name="inputDat" value="" id="dat" hidden/>
            <input hidden type="text" name="inputabe" value="" id="abe" hidden/>
            <br/><textarea name="inputKth" id="" style="width:300px;"></textarea><br/>  
            <br/><input type="checkbox" name="inputOmk" value="checked" id=""/>

    <input type="submit" value="Button" />

</form>

The PHP

<?php
ob_start();
include 'connection.php';

    // textboxes
$name = $_POST['inputName'];
$desc = $_POST['inputComment'];
$Page = $_POST['inputPage'];
$BeS = $_POST['inputBeS'];
$BeK = $_POST['inputBeK'];
// checkboxes
$fs = $_POST['inputFs'];
$fsn = $_POST['inputFsn'];
$fsj = $_POST['inputFsj'];
$fsjn = $_POST['inputFsjn'];
$Kun = $_POST['inputKun'];
$Byg = $_POST['inputByg'];
$Eko = $_POST['inputEko'];
$For = $_POST['inputFor'];
$HR = $_POST['inputHR'];
$Hal = $_POST['inputHal'];
$Ind = $_POST['inputInd'];
$Ink = $_POST['inputInk'];
$IT = $_POST['inputIT'];
$Kon = $_POST['inputKon'];
$Kul = $_POST['inputKul'];
$Kva = $_POST['inputKva'];
$Man = $_POST['inputMan'];
$Ped = $_POST['inputPed'];
$Ser = $_POST['inputSer'];
$Tek = $_POST['inputTek'];
$Ben = $_POST['inputBen'];
$Off = $_POST['inputOff'];
$All = $_POST['inputAll'];

$Namn = $_POST['inputJob'];
$Hem = $_POST['inputHem'];
$Kom = $_POST['inputKom'];
$Fid = $_POST['inputFid'];
$Dat = $_POST['inputDat'];
$Pri = $_POST['inputPri'];
$Job = $_POST['inputFon'];
$Abe = $_POST['inputabe'];
$Kth = $_POST['inputKth'];
$Omk = $_POST['inputOmk'];
$Pla = $_POST['inputPla'];



if(!$_POST['submit']) {
echo "please fill out the form";
header ('Location: ../index.php '); 

} else {

    mysql_query("INSERT INTO hemsida (`ID`,`Namn`,`Comment`,`Fs`,`Fsn`,`Fsj`,`Fsjn`,`Kon`,`Kul`,`Kva`,`Man`,`Ped`,`Ser`,`Tek`,`Ben`,`Off`,`Kun`,`Byg`,`Eko`,`For`,`HR`,`Hal`,`Ind`,`Ink`,`IT`,`BeS`,`BeK`,`All`,`Page`) 
            VALUES(NULL,'$name','$desc','$fs','$fsn','$fsj','$fsjn','$Kon','$Kul','$Kva','$Man','$Ped','$Ser','$Tek','$Ben','$Off','$Kun','$Byg','$Eko','$For','$HR','$Hal','$Ind','$Ink','$IT','$BeS','$BeK','$All','$Page')") or die(mysql_error());


    mysql_query("INSERT INTO erbjudande (`ID`,`Namn`,`Hem`,`Kom`,`Fid`,`Dat`,`Pri`,`Job`,`abe`,`Kth`,`Omk`,`Pla`) 
            VALUES(NULL,'$Namn','$Hem','$Kom','$Fid','$Dat','$Pri','$Job','$Abe','$Kth','$Omk','$Pla')") or die(mysql_error());

    echo "User has been addad";
    header('Location: ' . $_SERVER['HTTP_REFERER']);
}

?>
2
  • On a side note, mysql_ functions deprecated/data validation issues, you could also gorup the checkbox values into an array rather than handling them as seperate variables Commented Jan 29, 2014 at 14:16
  • also, you can't send header information using header() after output. Commented Jan 29, 2014 at 14:19

3 Answers 3

3

There doesn't seem to be a form element named "submit", so I wouldn't expect that value to exist in the $_POST collection.

POST values are key/value pairs where the key is the name of the form element. Try assigning a name:

<input name="submit" type="submit" value="Button" />
Sign up to request clarification or add additional context in comments.

3 Comments

Of course. I mistook <input type="submit" value="Button" /> as being named. I need a 2nd cup of coffee. Plus, a dash of dyslexia doesn't help me neither.
You guys are awesome, i started with two forms and two php, because i had another form in between, tried everything with javascript and ajax that i could find, now when i was down to one php file and one action i was destroyed when i could not get it to work. THANKS A MILLION! I feel less the brilliant right now.
$Fid = mysql_query("SELECT ID AS MAX(ID) FROM hemsida;");
0

$_POST take the name of input

You have to add a name attribute like this:

name = "submit"

Comments

0

You need to add name="submit" and you need to use mysql_real_escape_string function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.