0

My page is all blank because of this piece of code:

$coins = '2';                       
$vote_site = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';      
$account = $_POST['name']; 
$account = mysql_real_escape_string($account); 

$conn = mysql_connect($dbhost, $dbuser, $dbpassword) or die ('mySQL Connecting Error'); 
mysql_select_db($database); 
$ip = $_SERVER['REMOTE_ADDR']; 

if(isset($_POST['submit']) && strlen($account)>=4){
$search = mysql_query("SELECT * FROM account.account WHERE login = '$account' LIMIT 1");
    if (mysql_fetch_array($search) !== false){
    $insert = mysql_query("INSERT INTO account.account SET coins = "'.$coins.'" WHERE login = "'.$account.'"") or die(mysql_error);
    header("Location: http://' .$vote_site. '");
    }else{
        echo "Conta nao existe!";
        }
    }elseif (isset($_POST['submit']) && strlen($account)<4){
        echo "<font color='red'>Conta inválida!</font>";
    }

I have a html form, its supose to insert some values in a table and redirect to a website, but all I get is a white page.

I already tried all the ways to report errors, but it won't display anything!

Gumbo
  • 643,351
  • 109
  • 780
  • 844
Joao Paulo
  • 101
  • 7

1 Answers1

1

Remove double quotes around and concatenation dots here SET coins = "'.$coins.'" WHERE and here login = "'.$account.'"") :

$insert = mysql_query("INSERT INTO account.account SET coins = '$coins' WHERE login = '$account'") or die(mysql_error);

or switch their position:

$insert = mysql_query("INSERT INTO account.account SET coins = '".$coins."' WHERE login = '".$account."'") or die(mysql_error);

OOOPS Since this query is INSERT it has no sense to use WHERE so probably you've meant:

$insert = mysql_query("INSERT INTO account.account (coins, login) VALUES ('$coins', '$account')") or die(mysql_error);

UPDATE 1 It seems you don't understand difference between INSERT and UPDATE statement for mysql. Read about insert and update please . And try:

$insert = mysql_query("UPDATE account.account SET coins = '$coins' WHERE login = '$account'") or die(mysql_error);

Probably that is what you are looking for.

Alex
  • 16,739
  • 1
  • 28
  • 51
  • Parse error: syntax error, unexpected ''.$account.'' (T_CONSTANT_ENCAPSED_STRING) – Joao Paulo May 23 '15 at 16:52
  • switching solved the above , but now: (...)for the right syntax to use near 'WHERE login = 'xxxxxx'' at line 1 – Joao Paulo May 23 '15 at 16:53
  • but I want to insert the variable coins where the account is the same as the person wrote – Joao Paulo May 23 '15 at 17:03
  • do you hear yourself? and understand the word `INSERT`? the logic way is to think and to decide before you start insertion :-) and you have to decide what exactly you plan to insert :-) you cant `INSERT ... WHERE` :-) – Alex May 23 '15 at 17:05
  • yes, but Im inserting a value that already exists : Duplicate entry 'account name' for key 'login' – Joao Paulo May 23 '15 at 17:06
  • so the question is WHAT is your goal? oh, I see, probably you need not `INSERT` but `UPDATE` ? – Alex May 23 '15 at 17:07
  • I want to insert "2" (in this case) on the row "coins" where the login is equal to what I typed – Joao Paulo May 23 '15 at 17:10