I have this script but mysql insert section I have a problem the script didn't insert the first column "DNS" in sql table but did insert the second and the third one. what is my mistake the reason the first column escaped.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$all = implode(",",$_POST);
$all = explode(",",$all);
$insert = "INSERT INTO Cname VALUES (";
for ($x=0;$x<3;$x++)
{
$all[$x] = clean($all[$x]);
if ($all[$x] == "" || strlen($all[$x]) > 300)
die("<p>Incorect Data Entry, Please check again! Column - " . $x);
$insert .= "'" . $all[$x] . "',";
}
$insert .= "'')";
$res = mysql_query($insert) or die(mysql_error());
if($res)
die("<p>Succesfully Added! <a href='index.php'>Back To View Page</a></p>");
} else {
?>
<title>Add CNAME.</title>
</head>
<body>
<?php include("nav.php");?>
<div class="red"><p><h5>All fields are required.</h5></p></div>
<table id="box-table-a">
<tbody>
<form action="" method="POST">
<tr>
<td>DNS</td>
<!-- allow only the word CNAME -->
<td><input type="text" name="DNS" placeholder="enter a word 'CNAME" required pattern="CNAME" title="enter a word 'CNAME' on this field"></td>
</tr>
<tr>
<td>name</td>
<td><input type="text" name="name" placeholder="host with Full Domain Name" required pattern="^[a-zA-Z0-9\-]*$" title="host with full Domain Name"></td>
</tr>
<tr>
<td>alias</td>
<td><input type="text" name="alias" placeholder="only 3-15 digit are allowed" required pattern="^[a-zA-Z0-9-_\-]{3,15}*$" title="only 3-15 digit are allowed"></td>
</tr>
<tr>
<td><input type="submit" value="Add Cname"></td>
<td><input type="reset"></td>
</tr>
</tbody>
</table>
<?php
}
?>
echo $query
) and see what you produced. don't assume your query generating code is working properly. always check outputs. beyond that, what's the point of your implode/explode at the start of the script? why not just$all = $_POST
? You're trying to explode an array, not a string.,
in your values list.