2

I have a feeling that my syntax is incorrect but I can't narrow down what's going on. I have no issues running the statement in a phpMyAdmin SQL query, so hopefully I can get pointed in the right direction. My code is as follows:

else if ($resultdetails === 1) {
    $query3 = "update customer_det set `10k`='$_10k', 
      `14k`='$_14k', `18k`='$_18k', `21k`='$_21k', `22k`='$_22k', 
      `24k`='$_24k', `925k`='$_925k', `coins`='$coins', `bars`='$bars' 
      where `id` = '".$uid."'";
    $result3 = mysql_query($query3);
}

$resultdetails is a variable set with a EXISTS function. In the SQL query, it returns 1 for me, because the row I'm looking for does exist. So there should be no issues with that.

I tried the double ==, as well as the triple, and there doesn't seem to be any difference in results. I believe the triple === means that it's identical, i.e. the datatype is the same and the value is the same.

I think the issue here is the WHERE statement. Any ideas or suggestions would be greatly appreciated. I forgot to mention that customer_det is the table to be updated and id is the primary key, autoincremented. I pull the $uid variable from the database as well.

air4x
  • 5,618
  • 1
  • 23
  • 36
smada
  • 227
  • 1
  • 7
  • 17
  • have you tried running the query in phpmyadmin directly against your database (or atleast a test one!) it will give you a greater idea of any syntax errors etc. –  Nov 01 '12 at 12:47
  • The query runs fine in the phpMyAdmin SQL query box. That's why I'm unsure as to why it doesn't work. – smada Nov 01 '12 at 12:47
  • 1
    what is the datatype for $uid ?? if its int remove the '' from your query. – swapnesh Nov 01 '12 at 12:48
  • 1
    so if you output $query3 so youi can see what's gone in it. Does it make sense. Can't see syntax error, $uid not being waht you think it is, more likely – Tony Hopkinson Nov 01 '12 at 12:48
  • Hm, I believe that it is an integer. I can see the issue would be "" is trying to datatype as a string. – smada Nov 01 '12 at 12:48

2 Answers2

1

Your sql query is right ! But your else if is the problem ! see you add ===, change it with == and i'm also doubt with your variable declare, your code will look like this:

else if ($resultdetails == 1) {
$query3 = "update customer_det set `10k`='".$_10k."',
`14k`='".$_14k."', `18k`='".$_18k."',
`21k`='".$_21k."', `22k`='".$_22k."', `24k`='".$_24k."', `925k`='".$_925k."', `coins`='".$coins."', `bars`='".$bars."' where `id` = '".$uid."'";
$result3 = mysql_query($query3);
}

EDIT:

 if (CONDITION :: IF FOUND ON DATABASE) {
  $query3 = "update customer_det set `10k`='".$_10k."',
 `14k`='".$_14k."', `18k`='".$_18k."',
 `21k`='".$_21k."', `22k`='".$_22k."', `24k`='".$_24k."', `925k`='".$_925k."',        `coins`='".$coins."', `bars`='".$bars."' where `id` = '".$uid."'";
 $result3 = mysql_query($query3);
 } else {
 // Insert query if not found
 }
Michael Antonius
  • 942
  • 2
  • 11
  • 20
  • 1
    You're right, now I'm getting a blank insert because I changed the first IF to double ==. The first IF statement says if record doesn't exist then insert, the else if is the statement provided, if exists, update. – smada Nov 01 '12 at 12:57
  • Ok i will be help you ... I will edit my question ... The important you must know and get learn more ! Wait me ... – Michael Antonius Nov 01 '12 at 13:00
  • I has edit my answer, please learn my way ! I want you to know how to PHP and MySQL showng the power ! – Michael Antonius Nov 01 '12 at 13:05
  • I echo'd the $resultdetails and it's saying Resource ID #11. So that means I need to return a value and not an object correct? – smada Nov 01 '12 at 13:07
  • can you create one more question with full of your code ? I will first to answer it, because i did'nt get catch if you only say ! Please sir !, Spirit ! – Michael Antonius Nov 01 '12 at 13:12
0

Check for the data type for $uid and $_blahblah

Try this query --

else if ($resultdetails == 1) {
    $query3 = "update customer_det set `10k`='$_10k', 
      `14k`='$_14k', `18k`='$_18k', `21k`='$_21k', `22k`='$_22k', 
      `24k`='$_24k', `925k`='$_925k', `coins`='$coins', `bars`='$bars' 
      where `id` = $uid";
    $result3 = mysql_query($query3);
}
swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • I removed the ' as well as the " and tried it each time, still failing to get an update. I echo UID before the request and UID returns 273. So basically it's trying to update the record where id = 273. – smada Nov 01 '12 at 12:51
  • echo $query3; and then run the query in mysql and check if its running or not? – swapnesh Nov 01 '12 at 12:52
  • Ya $query3 won't even echo, so it looks like it's not being executed. – smada Nov 01 '12 at 12:57
  • @user1718270 check it with a die; that is it really going inside it or not and then tell me – swapnesh Nov 01 '12 at 12:58
  • @user1718270 try this -> else if ($resultdetails == 1) { echo "Hello"; die; and check if its showing hello or not?? – swapnesh Nov 01 '12 at 13:02
  • I echo'd two different statements, it looks like neither is executing on the IF / ELSE IF – smada Nov 01 '12 at 13:04