Hello I am a newbie to PHP, I am using xampp as a local host and html forms to collect data.
my form asks for pacific data, I am trying to get it to put that data into MySQL database client
I am getting error Warning: mysql_query() expects parameter 2 to be resource, object given in C:\xampp\htdocs\service_record.php on line 14 Error:
form code
<center>
<form method="post" action="service_record.php">
<table border="1" cellspacing="50">
<center><h1>Record Service Record</h1></center>
<tr>
<td>Date joined <input name="join_date"size="34" maxlength="30"> </td>
<td>Discharge date <input name="leave_date"size="34" maxlength="30"><br /></td>
</tr>
<tr>
<td>Rank <input name="rank"size="20" maxlength="20"> </td>
<td>time served <input name="time_served"size="20" maxlength="10"></td>
</tr>
<tr>
<td>Service <input name="service"size="34" maxlength="30"></td>
<td>Regt/Corps <input name="regt_corps"size="34" maxlength="30"><br /></td>
</tr>
</table>
<input type="reset" value="Reset Form"/> <input type="submit" value="Send" />
</center>
</form>
php code
<?php
$con=mysqli_connect("localhost","client","");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="INSERT INTO service_record (join_date,leave_date,rank,time_served,service,regt_corps)
VALUES
('$_POST[join_date]','$_POST[leave_date]','$_POST[rank]','$_POST[time_served]','$_POST[service]','$_POST[regt_corps]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "The Staff Details have been added to database";
mysql_close($con);
?>
I have read books after books changed it 100 times still no result. I have read this site and many others, I just can get it.
Please help if you can.
Rob