Update not working with php mysql -
i trying update username column on database. table has 2 columns: username , phoneno. code have done is:
<html> <body> <?php if(isset($_post['update'])) { $dbname = 'test'; $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); if(! $conn ) { die('could not connect: ' . mysql_error()); } $new = $_post['testing']; $sql = "update test set username = $new phoneno = 2000,196,200" ; mysql_select_db('test'); $retval = mysqli_query( $sql, $conn ); if(! $retval ) { die('could not update data: ' . mysql_error()); } echo "updated info successfully\n"; mysql_close($conn); } else { ?> <form method="post"> <input type="text" name="testing"> </form> </body> </html> but when run code gives me error:
warning: mysqli_query() expects parameter 1 mysqli
i know it's due error in query still didn't understand error means.
you using mysqli_* functions , selecting database via mysql_select_db. wrong. connection string like.
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); missing quotes in query condition.
$sql = "update test set username = '$new' phoneno = '2000,196,200'"; mysqli_query needs connection string first parameter , query sec one.
$retval = mysqli_query($conn, $sql); php mysql sql
No comments:
Post a Comment