php - 1046: No database selected? -


i having problem. below code, select database, still gives me error stating didn't. can let me know doing wrong?

<?php  $nc = mysqli_connect("localhost", "264191", "adhiambo95"); if (mysqli_connect_errno()) {     echo "sorry couldn't connect mysql: " . mysqli_connect_error(); }  mysqli_select_db($sc, "264191");  $sis = "insert nogata_keywords ('keyword')     value ('.$_get[keyword]')";  if (!mysqli_query($nc,$sis)) {     die('error: ' . mysqli_error($nc)); }  else {     echo "this keyword has been added database."; }  ?> 

you've misspelled connection resource variable here:

mysqli_select_db($sc, "264191"); 

should be

mysqli_select_db($nc, "264191"); 

mysqli_connect allows specify database 4th parameter, making above line redundant:

$nc = mysqli_connect("localhost", "264191", "adhiambo95", "264191"); 

try out.


one more thing, pointed out first yogesh suthar, sql query wrong, have period shouldn't:

$sis = "insert nogata_keywords ('keyword') value ('.$_get[keyword]')"; 

should be

$sis = "insert nogata_keywords (`keyword`) value ('".$nc->real_escape_string($_get['keyword'])."')"; 

because have quoted field name in single quotes , not escaped value inserted database. ie if keyword o'neil invalidate sql.

consider switching using prepare() , bind() avoid issue.

you should use 'keyword' in index $_get array not keyword constant. http://php.net/manual/en/language.types.array.php


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -