Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm trying to insert a value to mysql database with mysqli but it's not inserting and no error
my code
PHP
if ($hwid->num_rows) { 
		if(!mysqli_query($con,"UPDATE $username SET logs = CONCAT(logs,'$logs') WHERE hwid = '$id'")){
    			die(mysqli_error($con));
				exit;}
  } 
   else{
	   if(!mysqli_query($con,"INSERT INTO $username (hwid, date, logs) VALUES ('$hwid', '$date', '$logs')")){
    			die(mysqli_error($con));
				exit;}
   }


I gives no error and not inserts data. I'm sure first $hwid query executing properly
What is the problem
Posted

if ($hwid->num_rows) {
if(!mysqli_query($con,"UPDATE $username SET logs = CONCAT(logs,'$logs')
WHERE hwid = '{$id}'")){
die(mysqli_error($con));
exit;}
}
else{
if(!mysqli_query($con,"INSERT INTO $username (hwid, date, logs) VALUES ('{$hwid}', '{$date}', '{$logs}')")){
die(mysqli_error($con));
exit;}
}

you forgot the {} for your INSERT
is better to do multiline in your update
 
Share this answer
 
v4
Comments
suleymankenar 16-Jul-14 10:42am    
When i run the this query INSERT INTO myusername (hwid, date, logs) VALUES ('myhwid', 'mydate', 'mylog') via phpmyadmin it's working but in php it's not working with/without {}'s
I can't beleive it. I added ";" end of the query and it's working know.
 
Share this answer
 
try checking your table settings. have you created unique index or some restriction on the table?
 
Share this answer
 
Comments
suleymankenar 16-Jul-14 10:25am    
Everything in normal in my table settings. The weird thing when i execute query in phpmyadmin it's working but not works in php

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900