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); } } ?>