Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting and updating records

Status
Not open for further replies.

martinb7

Programmer
Joined
Jan 5, 2003
Messages
235
Location
GB
Hi, can someone tell me what im doing wrong here?

<?php
$con = mysql_connect(&quot;host&quot;,&quot;user&quot;,&quot;pass&quot;);
mysql_select_db(&quot;db&quot;,$con);

$pagename = &quot;fred&quot;; //change this to the page the code is on - e.g. games .php > games

$query = mysql_query(&quot;SELECT dacount FROM count1 WHERE page = '$pagename'&quot;);

list ($daviews) = mysql_fetch_row($query);

if (!$daviews) {
mysql_query(&quot;INSERT INTO count1 (NULL, '$pagename', '1' INTO count1)&quot;);
} else {
$views += 1;
$query = mysql_query(&quot;UPDATE count1 SET dacount VALUES('$views') WHERE page = '$pagename'&quot;);
}
?>

Thanx

Martin


thats the page for the thing im tryin to get to work
 
o.k,
this is what struck me first:

mysql_query(&quot;UPDATE count1 SET dacount ='$views' WHERE page = '$pagename'&quot;);
if u can give us the error line number it will be better.

and there is a technique to debug it urself, try this:
mysql_query(&quot;UPDATE count1 SET dacount ='$views' WHERE page = '$pagename'&quot;) or die(mysql_error());

this will give u the error for this sql statement...


Known is handfull, Unknown is worldfull
 
it doesn't come up with an error, its just a blank screen?

Could you rewrite the code pls?

Thanx

Martin

 
Unless there is more to your script than what you have posted, you should come up with a blank screen. You haven't output anything.

To flesh out vbkris' question:

What makes you think that there is anything wrong with your code? What is it doing wrong, not doing, or doing that it is not supposed to do?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
its not updating the table in the database, thats wot its doing wrong!

Any ideas??

Thanx

Martin
 
AhHah! An actual description of a problem! I was wondering where this thread was going!

It's because your update query is not well-formed. According to the keyword VALUES should not appear in an update query.

Your code does not perform enough error trapping. At the absolute minimum, your &quot;mysql_query()&quot; invocations should all be followed by the phrase &quot;or die(mysql_error())&quot;.

I have a FAQ on debugging PHP. The FAQ has a section on database connectivity debugging. FAQ434-2999.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top