redarrow Posted September 16, 2006 Share Posted September 16, 2006 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.[code]<?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','$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']."'";$resultu=mysql_query($update)or die("update problam");} } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/20965-solvedinsert-update-problam-cheers/ Share on other sites More sharing options...
ronverdonk Posted September 16, 2006 Share Posted September 16, 2006 What about this one?[code]if(mysql_num_rows($result1)<0){[/code]When do you expect the number of rows to be less then 0?Ronald 8) Link to comment https://forums.phpfreaks.com/topic/20965-solvedinsert-update-problam-cheers/#findComment-92953 Share on other sites More sharing options...
redarrow Posted September 16, 2006 Author Share Posted September 16, 2006 the rows are not there yet so they are 0 unless you got another idear cheers.like how to add empty there. Link to comment https://forums.phpfreaks.com/topic/20965-solvedinsert-update-problam-cheers/#findComment-92955 Share on other sites More sharing options...
redarrow Posted September 16, 2006 Author Share Posted September 16, 2006 solved[code]<?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");} } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/20965-solvedinsert-update-problam-cheers/#findComment-92957 Share on other sites More sharing options...
ronverdonk Posted September 16, 2006 Share Posted September 16, 2006 I wanted to say: change that statement to [code]if(mysql_num_rows($result1)<1){[/code]Ronald 8) Link to comment https://forums.phpfreaks.com/topic/20965-solvedinsert-update-problam-cheers/#findComment-92961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.