Jump to content

MYsql insert problem.


lional

Recommended Posts

Hi All

I am having a very frustrating morning. I am trying to either insert insert data into a mysql table based on a condition. there are no records in the table currently, so the insert should be used. I have tested all the variables and they are pulling the correct values. What is frustrating is that my application has three legs to it which are identical in structure but the tables and variables changes.

The insert works perfectly on those scripts.

Is there a way to insert an error script into php to see if the data does actually get written to the table, and if not what is the reason.

 

I have included the code segment:

$query_deg_cc_member = "SELECT * from cc_degrees WHERE member_no = '$cc_ass_mem_number_out'";

$result_deg_cc_member = mysql_query($query_deg_cc_member);

$num_deg_cc_member = @mysql_num_rows($result_deg_cc_member);

if ($num_deg_cc_member == 0) {

 

$query_deg_member1 = "INSERT INTO cc_degrees (member_no, royal, royal_day, royal_month, royal_year, select, select_day, select_month, select_year, sem, sem_day, sem_month, sem_year, master_lodge) VALUES ('$cc_ass_mem_number_out', '$com_royal_out', '$royal_day_out', '$royal_month_out', '$royal_year_out', '$com_select_out', '$select_day_out', '$select_month_out', '$select_year_out', '$com_sem_out', '$sem_day_out', '$sem_month_out', '$sem_year_out', '$master_lodge_out')";

$result_deg_member1 = @mysql_query ($query_deg_member1);

}

if ($num_deg_member != 0) {

print "Not Equal";

$query_deg_in = "UPDATE cc_degrees SET royal = '$com_royal_out', royal_day = '$royal_day_out', royal_month = '$royal_month_out', royal_year = '$royal_year_out', select = '$com_select_out', select_day = '$select_day_out', select_month = '$select_month_out', select_year = '$select_year_out', sem = '$com_sem_out', sem_day = '$sem_day_out', sem_month = '$sem_month_out', sem_year = '$sem_year_out', master_lodge = '$master_lodge_out' WHERE member_no = '$cc_ass_mem_number_out'";

$result_deg_in = @mysql_query ($query_deg_in);

 

Thanks

 

Lional

Link to comment
https://forums.phpfreaks.com/topic/58188-mysql-insert-problem/
Share on other sites

Try this code....

 

 

<?php

$query_deg_cc_member = "SELECT * from cc_degrees WHERE member_no = '$cc_ass_mem_number_out'";

$result_deg_cc_member = mysql_query($query_deg_cc_member);

$num_deg_cc_member = @mysql_num_rows($result_deg_cc_member);

if ($num_deg_cc_member == 0)

{

$query_deg_member1 = "INSERT INTO cc_degrees (member_no, royal, royal_day, royal_month, royal_year, select, select_day, select_month, select_year, sem, sem_day, sem_month, sem_year, master_lodge) VALUES ('$cc_ass_mem_number_out', '$com_royal_out', '$royal_day_out', '$royal_month_out', '$royal_year_out', '$com_select_out', '$select_day_out', '$select_month_out', '$select_year_out', '$com_sem_out', '$sem_day_out', '$sem_month_out', '$sem_year_out', '$master_lodge_out')";

$result_deg_member1 = @mysql_query ($query_deg_member1);

}

if ($num_deg_cc_member != 0)

{

print "Not Equal";

$query_deg_in = "UPDATE cc_degrees SET royal = '$com_royal_out', royal_day = '$royal_day_out', royal_month = '$royal_month_out', royal_year = '$royal_year_out', select = '$com_select_out', select_day = '$select_day_out', select_month = '$select_month_out', select_year = '$select_year_out', sem = '$com_sem_out', sem_day = '$sem_day_out', sem_month = '$sem_month_out', sem_year = '$sem_year_out', master_lodge = '$master_lodge_out' WHERE member_no = '$cc_ass_mem_number_out'";

$result_deg_in = @mysql_query ($query_deg_in);

}

 

?>

;)

Link to comment
https://forums.phpfreaks.com/topic/58188-mysql-insert-problem/#findComment-288597
Share on other sites

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.