1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

help with mysqli insert

Discussion in 'PHP' started by pshaw, Mar 15, 2023.

  1. #1
    Hi, I hopd someone will advise me as to where I'm going astray here. I'm trying to insert using PHP
    mysqli, using a form locally (<a href="waitinsert-form.html">. Following is
    the code for the form (is the form flawed?) followed by the code for the insert.
    I have tried following several online examples with no success.
    -------------------------------------------------
    the code for the form:
    <HTML><HEAD>
    <STYLE type=text/css>.highlight {
    BACKGROUND: #ff6699
    }
    .text {
    COLOR: #ffffff
    }
    .both {
    BACKGROUND: black; COLOR: white
    }
    </STYLE>

    <STYLE>INPUT.bgyellow {
    BACKGROUND-COLOR: yellow
    }
    </STYLE></head>
    <body bgcolor="ccffff">
    <b>Waiting/transfers List input form<p>
    <form action="waitinsert.php" name=Form method="post">


    <label for="entrytype">Entrytype:</label>
    <input type="text" name="entrytype" id="entrytype">
    <SELECT name=entrytype>
    <OPTION class=highlight value=W>W
    <OPTION class=highlight value=T>T
    </OPTION></SELECT><br>
    <label for="appl">appl:</label>
    <input type="text" name="appl" id="appl"><br>
    <label for="date">date:</label>
    <input type="text" name="date" id="date"><br>
    <label for="time">time:</label>
    <input type="text" name="time" id="time"><br>
    <label for="tenant">tenant:</label>
    <input type="text" name="tenant" id="tenant"><br>
    <label for="racegend">racegend:</label>
    <input type="text" name="racegend" id="racegend">
    <SELECT name=racegend>
    <OPTION class=highlight value=1f selected>White female
    <OPTION class=highlight value=2f>Black female
    <OPTION class=highlight value=3f>Asian female
    <OPTION class=highlight value=4f>Indian female
    <OPTION class=highlight value=5f>Hawaiian female
    <OPTION class=highlight value=1m>White male
    <OPTION class=highlight value=2m>Black male
    <OPTION class=highlight value=3m>Asian male
    <OPTION class=highlight value=4m>Indian male
    <OPTION class=highlight value=5m>Hawaiian male
    </OPTION></SELECT><BR>
    <label for="ethnicity">ethnicity:</label>
    <input type="text" name="ethnicity" id="ethnicity">
    <SELECT name=ethnicity>
    <OPTION class=highlight value=Y>Y
    <OPTION class=highlight value=N selected>N
    </OPTION></SELECT><BR>
    <label for="laborhsg">laborhsg:</label>
    <input type="text" name="laborhsg" id="laborhsg">
    <SELECT name=laborhsg>
    <OPTION class=highlight value=Y>N
    <OPTION class=highlight value=N selected>X
    </OPTION></SELECT><BR>
    <label for="displ">displ:</label>
    <input type="text" name="displ" id="displ">
    <SELECT name=displ>
    <OPTION class=highlight value=Y>X
    <OPTION class=highlight value=N selected>N
    </OPTION></SELECT><BR>
    <label for="incomelevel">incomelevel:</label>
    <input type="text" name="incomelevel" id="incomelevel">
    <SELECT name=incomelevel>
    <OPTION class=highlight value=VL selected>verylow
    <OPTION class=highlight value=L>low
    <OPTION class=highlight value=M>medium
    </OPTION></SELECT> <BR>
    <label for="brneeded">brneeded:</label>
    <input type="text" name="brneeded" id="brneeded">
    <SELECT name=brneeded>
    <OPTION class=highlight value=1 selected>1
    <OPTION class=highlight value=2>2
    <OPTION class=highlight value=3>3
    </OPTION></SELECT><BR>
    <label for="moveindate">moveindate:</label>
    <input type="text" name="moveindate" id="moveindate"><BR>
    <label for="removaldate">removaldate:</label>
    <input type="text" name="removaldate" id="removaldate"><BR>
    <label for="code">code:</label>
    <input type="text" name="code" id="code"><BR>
    <label for="comments">comments:</label>
    <input type="text" name="comments" id="comments"><BR>
    <P>
    <INPUT type=submit value="submit data"><BR></FORM></B></BODY></HTML>
    -----------------------------------------------------------------
    the code for insert:
    <?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "homedb";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);

    // Check connection
    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }

    $entrytype = $_POST['entrytype'];
    $appl = $_POST['appl'];
    $date = $_POST['date'];
    $time = $_POST['time'];
    $tenant = $_POST['tenant'];
    $racegend = $_POST['racegend'];
    $ethnicity = $_POST['ethnicity'];
    $displ = $_POST['displ'];
    $compday = $_POST['compday'];
    $compmoyr = $_POST['compmoyr'];
    $incomelevel = $_POST['incomelevel'];
    $brneeded = $_POST['brneeded'];
    $moveindate = $_POST['moveindate'];
    $removaldate = $_POST['removaldate'];
    $code = $_POST['code'];
    $comments = $_POST['comments'];
    $sql = "INSERT INTO waittbl (entrytype, appl, date, time, tenant, racegend, ethnicity, displ,
    compday, compmoyr, incomelevel, brneeded, moveindate, removaldate, code, comments)
    VALUES ('$entrytype','$appl','$date','$time','$tenant','$racegend','$ethnicity','$displ',
    '$compday','$compmoyr','$incomelevel','$brneeded','$moveindate','$removaldate','$code','$comments')";
    if (mysqli_query($conn, $sql)) {
    echo "New record created successfully".'<br>';
    } else {
    echo "Error: " . $sql. "<br>" . mysqli_error($conn);
    }
    }
    ?>
    --------------------------------------
    the result:
    '; } else { echo "Error: " . $sql. "
    " . mysqli_error($conn); } } ?>
     
    pshaw, Mar 15, 2023 IP
  2. seomanualsubmission

    seomanualsubmission Well-Known Member

    Messages:
    908
    Likes Received:
    130
    Best Answers:
    4
    Trophy Points:
    165
    #2
    What error you are getting exactly. I saw there multiple error.
    Missing " " in form name.
    Missing "" in class and value.
    Missing "" in class and value
    Missing "" in name
    Missing "" in class, value
    There are multiple line where you are missing "" ... Your form is running without any error ?????
     
    seomanualsubmission, Mar 15, 2023 IP
  3. dascos

    dascos Member

    Messages:
    11
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    33
    #3
    You have an extra } at the end of the php script.
    The query isn't well formed.
    Should look like this one:
    
    $sql = "INSERT INTO `waittbl` ('entrytype', 'appl', 'date', 'time', 'tenant', 'racegend', 'ethnicity', 'displ',
    'compday', 'compmoyr', 'incomelevel', 'brneeded', 'moveindate', 'removaldate', 'code', 'comments')
    VALUES ('{$entrytype}','{$appl}','{$date}','{$time}','{$tenant}','{$racegend}','{$ethnicity}','{$displ}',
    '{$compday}','{$compmoyr}','{$incomelevel}','{$brneeded}','{$moveindate}','{$removaldate}','{$code}','{$comments}')";
    
    Code (markup):
    As pointed out by seomanualsubmission you also have multiple errors in the form.
    Correct them first, then try again and post us the complete error you get.
    (sorry for english, not my language)
     
    dascos, Mar 28, 2023 IP