funbinod Posted April 14, 2014 Share Posted April 14, 2014 the following line-- mysqli_query($connect, $sql) or die('Error: ' . mysql_error()); works for $connect = mysql_connect($db_host, $db_user, $db_pass);if (!$connect) die("Unable to connect to database: " . mysql_error());$sql = ("INSERT INTO customer (cname, cadd, cemail, cphone, cperson, cmob, cob)VALUES ('$_POST[cname]', '$_POST[cadd]', '$_POST[cemail]', '$_POST[cphone]', '$_POST[cperson]', '$_POST[cmob]', '$_POST[cob]')"); but doesnot work for $connect = mysql_connect($db_host, $db_user, $db_pass);if (!$connect) die("Unable to connect to database: " . mysql_error());$sql = ("INSERT INTO vender (vname, vadd, vemail, vphone, vperson, vmob, vob)VALUES ('$_POST[vname]', '$_POST[vadd]', '$_POST[vemail]', '$_POST[vphone]', '$_POST[vperson]', '$_POST[vmob]', '$_POST[vob]'"); & gives error message --- Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in E:xampphtdocsacpandavvregisterpost.php on line 63 i couldnt understand why! Link to comment Share on other sites More sharing options...
thescientist Posted April 14, 2014 Share Posted April 14, 2014 this has been asked numerous times. there is a pinned thread about this question on this subforum (PHP). http://w3schools.invisionzone.com/index.php?showtopic=44106 Link to comment Share on other sites More sharing options...
justsomeguy Posted April 14, 2014 Share Posted April 14, 2014 This issue is slightly different. You're connecting with mysql_connect, and querying with mysqli_query. You are mixing mysql and mysqli. Other than that, your code is completely vulnerable to SQL injection attacks and does not do any validation at all. You should be using prepared statements with mysqli instead of putting things from $_POST or $_GET straight into your queries. Link to comment Share on other sites More sharing options...
thescientist Posted April 15, 2014 Share Posted April 15, 2014 ah, right. good catch. Link to comment Share on other sites More sharing options...
funbinod Posted April 16, 2014 Author Share Posted April 16, 2014 thank u all. i got the point and i edited that and made it work. but at another point got another problem $payment = mysqli_query($connect, "SELECT sum(amt) FROM payment WHERE vid='$row[vid]'") or die(mysqli_errno()); and got this message-- Warning: mysqli_errno() expects exactly 1 parameter, 0 given in E:xampphtdocsacpandavvregister.php on line 109 but the same line on another page doesnt show any warning and works properly.. Link to comment Share on other sites More sharing options...
thescientist Posted April 16, 2014 Share Posted April 16, 2014 now you should read the pinned thread i referenced. Link to comment Share on other sites More sharing options...
funbinod Posted April 16, 2014 Author Share Posted April 16, 2014 thank u all again. and i found the problem now. it was mistake on column name of database. but thank u for helping me understand basics of mysqli. now am trying to write everything on mysqli. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now