php - MySQLi insert not working - Die error -
I am working on the domain shortening service called "SHTPP". This uses a MySQL database to store short URLs. I can not include them.
This is my code:
function db () {$ link = mysqli_connect ('sqlserver', 'user', 'pass', 'db') or die (Mysqli_error ()); $ Link returned; } $ Url = mysqli_real_escape_string (db (), $ _POST ['url']); $ Ip = $ _SERVER ['REMOTE_ADDR']; Function checkexists ($ name) {// check if shttp is present $ q = mysqli_num_rows (mysqli_query (db (), "select name shttp with WHERE name = '$ name'")); If ($ q & gt; 0) {back true; } Other {return false; }} Generate function ($ length) {// string generated for placeholder name $ character = '0123456789abcdefghijklmnopqrstuvwxyz ABCDFGHIJJLMNOPQRSTUVX'; $ RandomString = ''; ($ I = 0; $ i & lt; $ length; $ i ++) {$ randomString. = $ Letters [rand (0, strollon ($ letters) - 1)]; } $ Random string; } If (Check Exist ($ name)) {Dead ('SHTPP name already exists!'); } If ($ _ POST ['url'] == '') {Dead ('no URL is entered!'); } If (! $ _ POST ['name']) {$ name = generRandStr (5); } And {$ name = mysqli_real_escape_string (db (), $ _POST ['name']); } // This is my main problem, even enter $ query = "shttp (name, url, ip) values ($ name, $ url, $ ip)"; // YU no work $ exe = mysqli_query (db ()), "shttp (name, url, ip) value ($ name, $ url, $ ip) in INSERT;); If (! $ Exe) {// I'm die of death ('error: can not be processed'); } Else {echo 'sHTTP created! & Lt; Br> URL: & lt; A href = http: //shttp.tk/ '. $ Name '& Gt; Http: //shttp.tk/'.$name.'< / A & gt; '; }
I'm setting up "error: could not be processed".
In addition, my DB table is: name varchar (255) url varchar (255) ip varchar (255)
I believe how I set it in my code too I can do
If someone can help, I would appreciate it. Thanks for your time.
You must use a bid for string values
$ Enter the query = "shttp (name, url, ip) values ('$ name', '$ url', '$ ip')";
Comments
Post a Comment