Jump to content

[solved]insert update problam cheers


redarrow

Recommended Posts

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','$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");
}
}
?>
[/code]
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.