funstein Posted August 12, 2011 Share Posted August 12, 2011 Hello everyone, I am working on the registration script of an academic conference. In the form, there are 3 registration types, which are to Regular, Student, Reduced. If the person has checked student, the script checks if his paper is listed as a student, and if they choose Reduced, the scripts check if their country is in the array of reduced countries. Then, the type is inserted into mysql alongside other information. So here is the problem : I see blanks in phpMyAdmin. All other fields are OK while this one is not. Here is the code : (All variables are defined correctly, only parts related to the problem are here. MySQL connection is OK.) //check if fee conditions are met if($formtype == "student") { if($check['student'] == "T") { $warning['studentwarning'] = false ; $type = "Student" ; } else{ $warning['studentwarning'] = true ; $type = "Regular" ; } } elseif($formtype == "reduced") { if(in_array($country, $reducedcountries)) { $warning['reducedwarning'] = false ; $type = "Reduced" ; } else{ $warning['reducedwarning'] = true ; $type = "Regular" ; } } else { $type == "Regular" ; } $type = mysql_real_escape_string($type); mysql_query("INSERT INTO registration (type) VALUES('$type') ") or die(mysql_error()); Hope someone can help me. Thanks, Funstein Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/ Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 You probably want to start doing test cases and echoing/var_dumping the $formtype and $type variables before running the query. Also could echo out the query how does it look like when you do the tests. And see based on this what happens and when, then try to figure out why. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256405 Share on other sites More sharing options...
funstein Posted August 12, 2011 Author Share Posted August 12, 2011 I have tried lots of different ways and I havent been able to come across this problem myself. Do you think you can help if I send you the whole code? Because this is overwhelming and I am going to be stuck with lots of untagged information if this goes on. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256408 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 Yes I think I can help, but I am at work at the moment and I do not have too much extra time to work on big files (if yours is big). Better option would be probably to paste the relevant codes in here on the forum inside the code tags so other people also can read them and maybe find you an answer for your problem. Some questions: 1. What debugging you have done to find out the source of the problem? 2. Do you have error reporting turned on? Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256413 Share on other sites More sharing options...
funstein Posted August 12, 2011 Author Share Posted August 12, 2011 Some questions: 1. What debugging you have done to find out the source of the problem? 2. Do you have error reporting turned on? I havent done any of these, because I cant simulate the error, I dont know why. None of my queries end up empty in the database. I'd start echoing variables but it wont help a lot since my queries are OK. I'm sending you the source code now, with MySQL information blanked. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256420 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 Well if you have not done any of these how can you know your variables and queries are OK? Add ini_set('display_errors', 1); error_reporting(-1); in the beginning of your scripts to see if there is any errors. And do some variable / query debugging like I said few posts ago to see if your query / variables have the data that you expect them to have. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256424 Share on other sites More sharing options...
funstein Posted August 12, 2011 Author Share Posted August 12, 2011 How I know that is, I have submitted the form with different information 1000s of times and never ended up with a blank. I have no idea how these people manage to do that. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256428 Share on other sites More sharing options...
TeNDoLLA Posted August 12, 2011 Share Posted August 12, 2011 Have you tried submitting the form leaving some fields empty or something similar? Think what the users could do. Do you validate the form data good enough? Checking for empty values etc? Is there any other wai users could insert data to these tables than this form? Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256432 Share on other sites More sharing options...
funstein Posted August 12, 2011 Author Share Posted August 12, 2011 There is no other way of insertion to the table. I have sent the code to you by PM, you can see that there is a validation, it kicks back if the field is null, and as the field is checkboxes, people have to select either regular,reduced or student. Or it kicks them back to the form and tells them to pick one. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256434 Share on other sites More sharing options...
shlumph Posted August 12, 2011 Share Posted August 12, 2011 Keeping track of more information, such as the date the record was added, and the user id if someone is logged in, may help troubleshoot the issue. The code to me looks like it should always insert a $type, but just in case you could try restructuring your code to something like this: //Set default values $warning['reducedwarning'] = true ; $type = "Regular" ; //check if fee conditions are met if($formtype == "student") { if($check['student'] == "T") { $warning['studentwarning'] = false ; $type = "Student" ; } } elseif($formtype == "reduced") { if(in_array($country, $reducedcountries)) { $warning['reducedwarning'] = false ; $type = "Reduced" ; } } $type = mysql_real_escape_string($type); mysql_query("INSERT INTO registration (type) VALUES('$type') ") or die(mysql_error()); It may be that those records were added when you had coded this differently, or something along those lines. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256436 Share on other sites More sharing options...
MasterACE14 Posted August 12, 2011 Share Posted August 12, 2011 So here is the problem : I see blanks in phpMyAdmin. All other fields are OK while this one is not. what do you mean by 'blanks' ? Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256437 Share on other sites More sharing options...
funstein Posted August 12, 2011 Author Share Posted August 12, 2011 Check the photo, you can see that on some rows, the TYPE value is not defined. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256438 Share on other sites More sharing options...
funstein Posted August 12, 2011 Author Share Posted August 12, 2011 I can send you the whole code, if you want. Quote Link to comment https://forums.phpfreaks.com/topic/244619-empty-value-in-mysql-database/#findComment-1256444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.