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
https://forums.phpfreaks.com/topic/20965-solvedinsert-update-problam-cheers/
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.