0

I want to write a script
if database no this record. It will insert
If database have tis reord. It will update

for ($a=0; $a<count($arr_event_id); $a++)
{    

    $query1 = "SELECT evnt_id FROM sales_roadshow  WHERE evnt_id = '".$arr_event_id[$a]."' ";
	$result1 = mysql_query($query1) or die(mysql_error());
	$row_s1 = mysql_fetch_row($result1);
	$P_numrows1 = mysql_num_rows($result1);
	
	if ($P_numrows1 == 0)
    {
      $res=mysql_query("insert into sales_roadshow1
      (evnt_id , evnt_start , evnt_end , evnt_status , evnt_type , evnt_title)
                            values	(\"$arr_event_id[$a]\",\"$arr_start_date[$a]\",\"$arr_end_date[$a]\",\"$arr_status[$a]\",\"$arr_event_kind[$a]\",\"$arr_event_title_chi[$a]\")") or die(mysql_error());
	 }
	 else
	 {
	   
	    mysql_query("UPDATE `sales_roadshow1` SET `evnt_title`  = '".$this_event_title."' WHERE `evnt_id` = '".$this_event_id."'");
	 }
}  // for

But I don't know why have a problem
Object of class __PHP_Incomplete_Class could not be converted to string
The problem is
mysql_query("UPDATE `sales_roadshow1` SET `evnt_title` = '".$this_event_title."' WHERE `evnt_id` = '".$this_event_id."'");

How can I fix it?

4
Contributors
10
Replies
11
Views
5 Years
Discussion Span
Last Post by urtrivedi
1

I think you can do it with

mysql_query("UPDATE sales_roadshow1 SET evnt_title = '$this_event_title' WHERE evnt_id = '$this_event_id'");
1

1) Here in insert query \" double quote is not allowed you must use single quote
2) no need to check record exist or not, just use on duplicate key.
(Note: on duplicate key works only in MYSQL, and you must define primary key or unique for the table)

$res=mysql_query("insert into sales_roadshow1      (evnt_id , evnt_start , evnt_end , evnt_status , evnt_type , evnt_title)                            values	('{$arr_event_id[$a]}','{$arr_start_date[$a]}','{$arr_end_date[$a]}','{$arr_status[$a]}','{$arr_event_kind[$a]}','{$arr_event_title_chi[$a]}') on duplicate key update `evnt_title`  = '".$this_event_title."'") ;
0

I try this coding. I already set up evnt_id as primary key.
But occur a error
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '` = ''' at line 3"

What is the eroor mean?

My coding here

for ($a=0; $a<count($arr_event_id); $a++)
{    

    $query1 = "SELECT evnt_id FROM sales_roadshow  WHERE evnt_id = '".$arr_event_id[$a]."' ";
	$result1 = mysql_query($query1) or die(mysql_error());
	$row_s1 = mysql_fetch_row($result1);
	$P_numrows1 = mysql_num_rows($result1);
	
	
      $res=mysql_query("insert into sales_roadshow1
      (evnt_id , evnt_start , evnt_end , evnt_status , evnt_type , evnt_title , evnt_title_eng , evnt_district , evnt_venue , evnt_organizer , evnt_booth , evnt_time , evnt_promo_pkg , evnt_food , promoter_count , evnt_promoter1 , evnt_promoter2 , evnt_promoter3 , evnt_promoter4 , evnt_promoter5 , remark , updated , updated_by , promote_type , stage_performance)
                            values	(\"$arr_event_id[$a]\",\"$arr_start_date[$a]\",\"$arr_end_date[$a]\",\"$arr_status[$a]\",\"$arr_event_kind[$a]\",\"$arr_event_title_chi[$a]\",\"$arr_event_title_eng[$a]\",\"$arr_district[$a]\",\"$arr_venue[$a]\",\"$arr_organizer[$a]\",\"$arr_evnt_booth[$a]\",\"$arr_event_time[$a]\",\"\",\"$arr_event_food[$a]\",\"$arr_promoter_count[$a]\",\"$arr_evnt_promoter1[$a]\",\"$arr_evnt_promoter2[$a]\",\"$arr_evnt_promoter3[$a]\",\"$arr_evnt_promoter4[$a]\",\"$arr_evnt_promoter5[$a]\",\"$arr_remark[$a]\",\"$date_time\",\"$user_id\",\"$arr_promote_kind[$a]\",\"$arr_stage_performance[$a]\") on duplicate key update evnt_title`= '".$this_event_title[$a]."'") or die(mysql_error());
	 
}  // for

1) Here in insert query \" double quote is not allowed you must use single quote
2) no need to check record exist or not, just use on duplicate key.
(Note: on duplicate key works only in MYSQL, and you must define primary key or unique for the table)

$res=mysql_query("insert into sales_roadshow1      (evnt_id , evnt_start , evnt_end , evnt_status , evnt_type , evnt_title)                            values	('{$arr_event_id[$a]}','{$arr_start_date[$a]}','{$arr_end_date[$a]}','{$arr_status[$a]}','{$arr_event_kind[$a]}','{$arr_event_title_chi[$a]}') on duplicate key update `evnt_title`  = '".$this_event_title."'") ;
0

on duplicate key update evnt_title`= '".$this_event_title[$a]."'") the error is on that character before evnt_title, what's this character "`"? delete it and put ' this one cuz it seems like you copied that code so that's y it doesn't read that character.

0

Thanks.......
But I back to my original problem again

"Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in /home/germanpo/public_html/roadshow/upload_excel_import.php on line 78"

for ($a=0; $a<count($arr_event_id); $a++)
{    

	
      $res=mysql_query("insert into sales_roadshow1
      (evnt_id , evnt_start , evnt_end , evnt_status , evnt_type , evnt_title , evnt_title_eng , evnt_district , evnt_venue , evnt_organizer , evnt_booth , evnt_time , evnt_promo_pkg , evnt_food , promoter_count , evnt_promoter1 , evnt_promoter2 , evnt_promoter3 , evnt_promoter4 , evnt_promoter5 , remark , updated , updated_by , promote_type , stage_performance)
                            values	(\"$arr_event_id[$a]\",\"$arr_start_date[$a]\",\"$arr_end_date[$a]\",\"$arr_status[$a]\",\"$arr_event_kind[$a]\",\"$arr_event_title_chi[$a]\",\"$arr_event_title_eng[$a]\",\"$arr_district[$a]\",\"$arr_venue[$a]\",\"$arr_organizer[$a]\",\"$arr_evnt_booth[$a]\",\"$arr_event_time[$a]\",\"\",\"$arr_event_food[$a]\",\"$arr_promoter_count[$a]\",\"$arr_evnt_promoter1[$a]\",\"$arr_evnt_promoter2[$a]\",\"$arr_evnt_promoter3[$a]\",\"$arr_evnt_promoter4[$a]\",\"$arr_evnt_promoter5[$a]\",\"$arr_remark[$a]\",\"$date_time\",\"$user_id\",\"$arr_promote_kind[$a]\",\"$arr_stage_performance[$a]\") on duplicate key update evnt_title = '".$arr_event_title_chi[$a]."'") or die(mysql_error());
	 
}
0

Is that error in one of your classes? if you have this page "/home/germanpo/public_html/roadshow/upload_excel_import.php" plz show us the code on line 78 so we can sort it out

0

I sent all coding to your message box.
Please help me~

Is that error in one of your classes? if you have this page "/home/germanpo/public_html/roadshow/upload_excel_import.php" plz show us the code on line 78 so we can sort it out

0

Okay, m working on it. I'll let you know once m finished

THANKS~~~~~~~~~

0

You have not read my last post properly,
You must use single quote instead of double quote. Also you need to use braces {}
like '{$arr_promoter_count[$a]}'
do you use \" only use '


Post your table structure in sql format here, I will try to debug your query here.

Edited by urtrivedi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.