Jump to content


Photo

[solved]insert update problam cheers


  • Please log in to reply
4 replies to this topic

#1 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 September 2006 - 11:35 AM

Advance thank you.

Can you kindly see why this wont work please.

What i want to do is use the below code to cheek if the id exist and if not insert the id and jan-dec to a 0 then update any id that does exist via 1.

There is no errors and all the querys are correct please help cheers.

<?php
$name=$_GET['name'];

$query="select * from members where name='$name'";
$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){

if($_GET['cmd']=="hit"){

$colname=($_POST['colname']);

$colname=date('M');

$query1="select * from hits where id='".$record['id']."'";
$result1=mysql_query($query1);

if(mysql_num_rows($result1)<0){

$id=$record['id'];
$jan=="0";
$feb=="0";
$mar=="0";
$apr=="0";
$may=="0";
$jun=="0";
$jul=="0";
$aug=="0";
$sep=="0";
$oct=="0";
$nov=="0";
$dec=="0";

$insert="insert into hits (id,jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec)values('$id','$jan','$feb','$mar','$apr','$may','$jun','$jul','$aug','$se
p','$oct','$nov','$dec')";
$in=mysql_query($insert)or die("insert problam");

}elseif(mysql_num_rows($result1)>0){

$update="update hits set $colname=$colname+1 where id='".$record['id']."'";

$resultu=mysql_query($update)or die("update problam");
}
 } 
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 16 September 2006 - 11:40 AM

What about this one?
if(mysql_num_rows($result1)<0){

When do you expect the number of rows to be less then 0?

Ronald   8)
RTFM is an almost extinct art form, it should be subsidized.

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 September 2006 - 11:44 AM

the rows are not there yet so they are 0 unless you got another idear cheers.
like how to add empty there.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 September 2006 - 11:53 AM

solved

<?php
$name=$_GET['name'];

$query="select * from members where name='$name'";
$result=mysql_query($query);

while($record=mysql_fetch_assoc($result)){

if($_GET['cmd']=="hit"){

$colname=($_POST['colname']);

$colname=date('M');

$query1="select * from hits where id='".$record['id']."'";
$result1=mysql_query($query1)or die("query problam");

if(!mysql_num_rows($result1)){

$id=$record['id'];
$jan="1";
$feb="1";
$mar="1";
$apr="1";
$may="1";
$jun="1";
$jul="1";
$aug="1";
$sep="1";
$oct="1";
$nov="1";
$dec="1";

$insert="insert into hits (`id`, `jan`, `feb`, `mar`, `apr`, `may`, `jun`, `jul`, `aug`, `sep`, `oct`, `nov`, 

`dec`)values('$id','$jan','$feb','$mar','$apr','$may','$jun','$jul','$aug','$sep','$oct','$nov','$dec')";
$in=mysql_query($insert)or die("insert problam");

}elseif(mysql_num_rows($result1)>0){

$update="update hits set $colname=$colname+1 where id='".$record['id']."'";
echo $update;

$resultu=mysql_query($update)or die("update problam");
}
 } 
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 16 September 2006 - 11:56 AM

I wanted to say: change that statement to
if(mysql_num_rows($result1)<1){

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users