0

I have problem with this code:

code

<?php
include('config.php');
?>

<?php
if(isset($_POST['add']))
{

$conn = mysqli_connect($servername, $username, $password);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}

if(! get_magic_quotes_gpc() )
{
$name_of_activity = addslashes ($_POST['name_of_activity']);
$descriotion = addslashes ($_POST['descriotion']);
}
else
{
$course_No = $_POST['name_of_activity'];
$descriotion = $_POST['descriotion'];
}
$date = $_POST['date'];

$sql = "INSERT INTO Activity". "(name_of_activity, descriotion, date)       ". "VALUES('$name_of_activity','$descriotion','$date')";
mysql_select_db('ecom');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">name_of_activity</td>
<td><input name="name_of_activity" type="text" id="name_of_activity" />              </td>
</tr>
<tr>
<td width="100"> descriotion </td>
<td><input name="descriotion" type="text" id="descriotion" /></td>
</tr>
<tr>
<td width="100">date </td>
<td><input name="date" type="text" id="date" /></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="add" type="submit" id="add" value="Add Activity" />
</td>
</tr>
</table>
</form>
<?php
}
?>

If I run it show this error message:

Warning: mysql_query() expects parameter 2 to be resource, object given in /Applications/XAMPP/xamppfiles/htdocs/add/add-course.php on line 29 Could not enter data: Access denied for user ''@'localhost' to database 'ecom'

Aisha
  • 11
  • 2

1 Answers1

0

Change mysql to mysqli, you can't use mysql and mysqli altogether.

$retval= mysqli_query($conn, $sql);
Agung Santoso
  • 83
  • 1
  • 8