# What is wrong with this update query?

**URL:** <https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386>\
**Category:** programming\
**Created:** [March 26, 2006, 3:59pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386 "2006-03-26T15:59:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [March 26, 2006, 3:59pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/1 "2006-03-26T15:59:01Z")

</div>

I get the echo “error” else statement, meaning the query didn’t run. What’s up? I’ve checked spelling for the fields in the database. I’ve made sure all variables are set correctly.🅰

```php
 if($_GET['page'] == 'contact'){
 
   $id = $_GET['id'];
   $pe = escape_data($_GET['pubemail']);
   $co = escape_data($_GET['company']);
   $ut = escape_data($_GET['usertitle']);
   $a1 = escape_data($_GET['address1']);
   $a2 = escape_data($_GET['address2']);
   $ci = escape_data($_GET['city']);
   $st = escape_data($_GET['state']);
   $zi = escape_data($_GET['zipcode']);
   
   echo $id." ".$pe." ".$co." ".$ut." ".$a1." ".$a2." ".$ci." ".$st." ".$zi." ";
   
   $queryc = "UPDATE members SET pubemail='$pe', company='$co', usertitle='$ut', address1='$a1', address2='$a2', city='$ci', state='$st', zip='$zi' WHERE id=$id";
   $resultc = @mysql_query($queryc);
   if($resultc){echo "Contact Information Updated";}else{echo"error";}

}

```

---

<div class="post-metadata">

**Author:** ![melvijin](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@melvijin](https://forum.kirupa.com/u/melvijin)\
**Post date:** [March 26, 2006, 4:30pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/2 "2006-03-26T16:30:21Z")

</div>

dud check this out!!!

```php
 
$queryc = "UPDATE members SET pubemail='$pe', 
company='$co', usertitle='$ut', address1='$a1', 
address2='$a2', city='$ci', state='$st', zip='$zi' 
WHERE id=$id"; 

```

the code [COLOR=red]WHERE id=$id[/COLOR]

[COLOR=black]make that [/COLOR][COLOR=blue]WHERE id=’$id’[/COLOR]

[COLOR=#0000ff]

```php
 
$queryc = "UPDATE members SET pubemail='$pe', 
company='$co', usertitle='$ut', address1='$a1', 
address2='$a2', city='$ci', state='$st', zip='$zi' 
WHERE id='$id'"; 

```

[COLOR=black]rok on!!![/COLOR] 🙂  
[/COLOR]

---

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [March 26, 2006, 6:20pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/3 "2006-03-26T18:20:40Z")

</div>

Yeah I’ve done that and it still doesn’t work.

---

<div class="post-metadata">

**Author:** ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)\
**Post date:** [March 26, 2006, 6:26pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/4 "2006-03-26T18:26:44Z")

</div>

> [@melvijin](#):
>
> the code [COLOR=red]WHERE id=$id[/COLOR]
> 
> [COLOR=black]make that [/COLOR][COLOR=blue]WHERE id=‘$id’[/COLOR]

Actually if “id” is an integer (or numerical value), like I’m guessing it is, then it shouldn’t have the quotes around it.

I’ve had issues like this before where I’ve checked everything and still get an error. The solution’s been different most times – mainly because I messed something up. 😛

It’s hard to know what your DB set looks like. By just looking at the code, I need to ask. For the zip code (zip in the DB), is that an integer or are you allowing for non-numeric characters? If the zip is set up as an integer (or numerical value) then you wouldn’t need the quotes around the $zi.

If that doesn’t work, it would be helpful to see how you have your database set up.

---

<div class="post-metadata">

**Author:** ![Seb\_Hughes](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@Seb\_Hughes](https://forum.kirupa.com/u/Seb_Hughes)\
**Post date:** [March 26, 2006, 6:31pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/5 "2006-03-26T18:31:43Z")

</div>

Are you connecting to the database?  
Maybe:

echo $id." “.$pe.” “.$co.” “.$ut.” “.$a1.” “.$a2.” “.$ci.” “.$st.” “.$zi.” ";

Should be  
echo “”.$id." “.$pe.” “.$co.” “.$ut.” “.$a1.” “.$a2.” “.$ci.” “.$st.” “.$zi.” ";

else it beats the \*\*\*\* out of me.

---

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [March 26, 2006, 6:56pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/6 "2006-03-26T18:56:04Z")

</div>

That echo is just to check if the variable are set okay.  
Here are my fields, all are varchar accept id=int, status=char(3), subscription=char(3)

id   
firstname   
lastname   
email   
username   
password   
access   
pubemail   
company   
address1   
address2   
city   
state   
zip   
service   
zone   
status   
subscription   
title

---

<div class="post-metadata">

**Author:** ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)\
**Post date:** [March 26, 2006, 11:29pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/7 "2006-03-26T23:29:58Z")

</div>

> [@SlowRoasted](#):
>
> That echo is just to check if the variable are set okay.  
> Here are my fields, all are varchar accept id=int, status=char(3), subscription=char(3)
> 
> id  
> firstname  
> lastname  
> email  
> username  
> password  
> access  
> pubemail  
> company  
> address1  
> address2  
> city  
> state  
> zip  
> service  
> zone  
> status  
> subscription  
> title

> [@SlowRoasted](#):
>
> [COLOR=#000000][COLOR=#0000bb]$queryc [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]“UPDATE members SET pubemail=‘$pe’, company=‘$co’, usertitle=‘$ut’, address1=‘$a1’, address2=‘$a2’, city=‘$ci’, state=‘$st’, zip=‘$zi’ WHERE id=$id”[/COLOR][COLOR=#007700];[/COLOR][/COLOR]

usertitle=‘$ut’ … I don’t see a “usertitle” in your database. There’s the problem: **usertitle** should be **username**

I setup a database and ran a test, orginally it failed to make the updates. I then changed **usertitle=‘$ut’** to be **username=‘$ut’** for your query and then it worked fine.

---

<div class="post-metadata">

**Author:** ![melvijin](https://avatars.discourse-cdn.com/v4/letter/m/e9a140/32.png) [@melvijin](https://forum.kirupa.com/u/melvijin)\
**Post date:** [March 26, 2006, 11:55pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/8 "2006-03-26T23:55:21Z")

</div>

> **usertitle** should be **username**

yeah!!!

---

<div class="post-metadata">

**Author:** ![SlowRoasted](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@SlowRoasted](https://forum.kirupa.com/u/SlowRoasted)\
**Post date:** [March 27, 2006, 1:53pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/9 "2006-03-27T13:53:11Z")

</div>

Thanks Ankou that worked. Thanks for going through all the trouble to figure out my stupid mistake:P

---

<div class="post-metadata">

**Author:** ![Ankou](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ankou/32/1351_2.png) [@Ankou](https://forum.kirupa.com/u/Ankou)\
**Post date:** [March 27, 2006, 8:03pm UTC](https://forum.kirupa.com/t/what-is-wrong-with-this-update-query/183386/10 "2006-03-27T20:03:43Z")

</div>

> [@SlowRoasted](#):
>
> Thanks Ankou that worked. Thanks for going through all the trouble to figure out my stupid mistake:P

No prob SlowRoasted, glad I could help. And hey, I’ve made that same mistake a few times in the past myself so I know how it goes!
