mysql - want to remove hostname,username and pasword from php code

970

i am having php code like below

<?php
/*  $host='127.0.0.1';
$uname='root';
$pwd='password';
$db="android";
*/  
require_once('dbConnect.php');

/*  $con = mysql_connect($host,$uname,$pwd) or die("connection failed");
mysql_select_db($db,$con) or die("db selection failed");
*/   
$id=$_REQUEST['id'];
$approval=$_REQUEST['approval'];

$flag['code']=0;

$sql = "UPDATE ap_events SET event_approval = '$approval' WHERE id ='$id'";

if($r=mysqli_query($sql,$con))
{
    $flag['code']=1;
}

print(json_encode($flag));
// mysql_close($con);
mysqli_close($con);
?>

but i want to remove the hostname username and password details from the above code, for the same i have another dbConnect.php code below:

<?php
define('HOST','localhost');
define('USER','root');
define('PASS','password');
define('DB','android');

$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

producing results always code = 0 means unsuccessful. and when i remove the comments it is successful!!

472

Answer

Solution:

removed

$approval=$_REQUEST['approval'];

and

if($r=mysqli_query($sql,$con))

i changed to

if($r=mysqli_query($con,$sql))

People are also looking for solutions to the problem: will not excute mysql statement from view in php

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.