开发者

I am getting a , after my result after mysql insert

开发者 https://www.devze.com 2023-03-08 19:42 出处:网络
Hello everyone I am getting a, after my result in the databases here is my code <input type=\"text\" size=\"49\" maxlength=\"40\" name=\"image2\">

Hello everyone I am getting a, after my result in the databases here is my code

<input type="text" size="49" maxlength="40" name="image2">

$_SESSION['image'] = $image ;

mysql_query("INSERT INTO adds  (username, url, coins, image) VALUES('".$_SESSION['username']."','".$_SESSION['url']."', '".$_SESSION['perclick'].",', 开发者_StackOverflow'".$_SESSION['image'].",'  )  ") or

die(mysql_error());

So if there is nick in side $_SESSION['image'] it would show has nick, in the db the column is varchar if I change it to int and enter a number it adds the number with out the , at the end


The quotes in the query are what are confusing. Let me use PHP's inline variables to help make this more clear.

"VALUES('{$_SESSION['username']}','{$_SESSION['url']}', '{$_SESSION['perclick']},', '{$_SESSION['image']},' ) ") or die(mysql_error());

As is hopefully now evident, what is being inserted as image is actually {$_SESSION['image']},. Also be aware that the same thing is occurring for coins.


VALUES (
  '".$_SESSION['username']."',
  '".$_SESSION['url']."',
  '".$_SESSION['perclick'].",', // here is one
  '".$_SESSION['image'].",'     // and here's another
)

should be like this

VALUES (
  '".$_SESSION['username']."',
  '".$_SESSION['url']."',
  '".$_SESSION['perclick']."',
  '".$_SESSION['image']."'
)


VALUES('".$_SESSION['username']."','".$_SESSION['url']."', '".$_SESSION['perclick']."', '".$_SESSION['image']."' )

0

精彩评论

暂无评论...
验证码 换一张
取 消