Jump to content

Recommended Posts

Hello,
I'm very new at PHP and SQL with enough knowledge to first build a table and try to fill it with the code below. The problem is even though it says your information was posted to the server, nothing is there. I don't know if I need to query it but it's suppose to post into the table which is in the script. I appreciate any help and thanks in advance.

<?php
$textbox1name = $_POST['textbox1name'];
$textbox2date = $_POST['textbox2date'];
$check1male = $_POST['check1male'];
$check2female = $_POST['check2female'];
$text3phone = $_POST['text3phone'];
$textbox4county = $_POST['textbox4county'];
$check3personwithimpairment = $_POST['check3personwithimpairment'];
$check4family_member_significant_other = $_POST['check4family_member_significant_other'];
$textbox5other_specify = $_POST['textbox5other_specify'];
$textbox6business_agency = $_POST['textbox6business_agency'];
$chech5advocacy_legal_services = $_POST['chech5advocacy_legal_services'];
$check9_architectual_barrier_services = $_POST['check9_architectual_barrier_services'];
$check7_assistive_devices_equipment_services = $_POST['check7_assistive_devices_equipment_services'];
$check8_benefits_advisment = $_POST['check8_benefits_advisment'];
$check10_business_industry_agency_services = $_POST['check10_business_industry_agency_services'];
$check11_childrens_services = $_POST['check11_childrens_services'];
$check12_communication_services = $_POST['check12_communication_services'];
$check13_family_services = $_POST['check13_family_services'];
$check14_housing_home_modification_other_shelter_services = $_POST['check14_housing_home_modification_other_shelter_services'];
$chech15_il_skills_traing_life_skills_training = $_POST['chech15_il_skills_traing_life_skills_training'];
$check16_inforamtion_referral = $_POST['check16_inforamtion_referral'];
$check17_mobility_training = $_POST['check17_mobility_training'];
$check18_peer_counseling_services= $_POST['check18_peer_counseling_services'];
$check19_preventative_services = $_POST['check19_preventative_services'];
$check20_prostheses_orthics_other_appliances = $_POST['check20_prostheses_orthics_other_appliances'];
$check21_recreational_services = $_POST['check21_recreational_services'];
$check22_rehabilitation_technology_services = $_POST['check22_rehabilitation_technology_services'];
$check24_transportation_services = $_POST['check24_transportation_services'];
$check25_youth_services = $_POST['check25_youth_services'];
$check26_vocational_services = $_POST['check26_vocational_services'];
$check27_voter_reistration = $_POST['check27_voter_reistration'];
$textbox7_staff_person_date1 = $_POST['textbox7_staff_person_date1'];
$textbox8_staff_person_date2 = $_POST['textbox8_staff_person_date2'];
mysql_connect("localhost.org.com", "61606", "password") or die(mysql_error());
mysql_select_db("61606") or die(mysql_error());
mysql_query("INSERT INTO `servicerecord` VALUES ('$textbox1name', '$textbox2date', '$check1male', '$check2female', '$text3phone', '$textbox4county', '$check3personwithimpairment', '$check4family_member_significant_other', '$textbox5other_specify', '$textbox6business_agency', '$chech5advocacy_legal_services', '$check9_architectual_barrier_services', '$check10_business_industry_agency_services', '$check11_childrens_services', '$check12_communication_services', '$check13_family_services', '$check14_housing_home_modification_other_shelter_services', '$chech15_il_skills_traing_life_skills_training', '$check16_inforamtion_referral', '$check17_mobility_training', '$check18_peer_counseling_services', '$check19_preventative_services', '$check20_prostheses_orthics_other_appliances', '$check21_recreational_services', '$check22_rehabilitation_technology_services', '$check24_transportation_services', '$check25_youth_services', '$check26_vocational_services', '$check27_voter_reistration', '$textbox7_staff_person_date1', '$textbox8_staff_person_date2')");
Print "Your information has been successfully added to the database.";
?>
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/
Share on other sites

your query needs to be like this:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']INSERT[/span] [color=green]INTO[/color] [color=orange]tablename[/color] (column1, column2, column3) VALUES ([color=red]'$value1'[/color],[color=red]'$value2'[/color],[color=red]'$value3'[/color])
[!--sql2--][/div][!--sql3--]
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-43938
Share on other sites

This script is a bit harsh. Too much code
I would advise using the following method:

$sql = "";
foreach ($_POST as $field => $value)
{
if ($value != "")
{
$append = ($sql == "") ? "" : ", ";
$sql .= "$append'$value'";
}
}
$query = "INSERT INTO `db` VALUES ($sql)";

and if that does work out add another $sql for the field names according to the form input names, and match them with the db field names.
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44040
Share on other sites

[!--quoteo(post=382261:date=Jun 10 2006, 12:43 PM:name=joquius)--][div class=\'quotetop\']QUOTE(joquius @ Jun 10 2006, 12:43 PM) [snapback]382261[/snapback][/div][div class=\'quotemain\'][!--quotec--]
This script is a bit harsh. Too much code
I would advise using the following method:

$sql = "";
foreach ($_POST as $field => $value)
{
if ($value != "")
{
$append = ($sql == "") ? "" : ", ";
$sql .= "$append'$value'";
}
}
$query = "INSERT INTO `db` VALUES ($sql)";

and if that does work out add another $sql for the field names according to the form input names, and match them with the db field names.
[/quote]


Could you please tell me what I need to insert into this and where? I'm really new at this. The colum didn't work. I appreciate your help. Thanks.
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44115
Share on other sites

[!--quoteo(post=382421:date=Jun 11 2006, 01:56 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 11 2006, 01:56 AM) [snapback]382421[/snapback][/div][div class=\'quotemain\'][!--quotec--]
you pretty much throw away your old code and use that instead. except, use the correct table name in your sql query (servicerecord)
[/quote]
Could some one teel me what to insert into the new code and were. Please be specific, I'm really new at this. Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44396
Share on other sites

bxmachines,

I have been as much a noobie as you, so I will make this simple.

1) All of the variable declarations -- $variable = $_POST['variable']; -- you can either leave all of these in (which is very verbose), or you can delete all of them & insert joquius's snippet of code instead. It really doesn't matter. To first get it working, you might leave this part as-is, then try his more efficient code later.

2) After you declare all your variables, your INSERT statement is incorrect. It is going to be a very, very LONG statement. Following Violet's suggestion:

[code]$query = "INSERT INTO servicerecord (textbox1name, textbox2name, check1male, check1female ...) VALUES ('$textbox1name', '$textbox2name', '$check1male', '$check1female', ...)";[/code]

EVERY table cell you want to insert data into must be listed in the first set of parentheses(), THEN its matching $variable must be listed in the second set of parentheses(), IN THE SAME ORDER. Also, be sure to follow my (or Violet's) lead as to which things have single & double quotes. Obviously, do not leave the "..." in -- this is just to demonstrate that there will be more entries after it.

3) It is not a good idea to simply spit out "This worked" at the end without checking it somehow. At least until you have debugged your script, add a simple IF statement to check it:

[code]if (mysql_affected_rows == 1) {
   echo "Succeeded";
   }else{
   echo "Failed: ".mysql_affected_rows()." affected rows with Query: ".$query."<br />Error:".mysql_error();
   }[/code]

The above will help you figure out what is going on by giving you the returned error messages (if any). It is also a good idea to leave these statements in, but change them to something like "An Error occurred: please contact the webmaster" so that the poor non-profit people aren't thinking things always worked if they DIDN'T.

Wendy

Can I make a suggestion?

Instead of having checkboxes for Male & Female, instead make these radio buttons. Give them the same name but values of M or F, so that no one can check BOTH of them!

<input type="radio" name="gender" value="M"> Male
<input type="radio" name="gender" value="F"> Female

Then you can simplify to ONE table in your database called "Gender" and assign in the value of $_POST['gender'].

Just an idea --

Wendy

--Always assume the user will screw it up somehow.
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44440
Share on other sites

Try this ok.
[code]
<?php

$textbox1name = $_POST['textbox1name'];
$textbox2date = $_POST['textbox2date'];
$check1male = $_POST['check1male'];
$check2female = $_POST['check2female'];
$text3phone = $_POST['text3phone'];
$textbox4county = $_POST['textbox4county'];
$check3personwithimpairment = $_POST['check3personwithimpairment'];
$check4family_member_significant_other = $_POST['check4family_member_significant_other'];
$textbox5other_specify = $_POST['textbox5other_specify'];
$textbox6business_agency = $_POST['textbox6business_agency'];
$chech5advocacy_legal_services = $_POST['chech5advocacy_legal_services'];
$check9_architectual_barrier_services = $_POST['check9_architectual_barrier_services'];
$check7_assistive_devices_equipment_services = $_POST['check7_assistive_devices_equipment_services'];
$check8_benefits_advisment = $_POST['check8_benefits_advisment'];
$check10_business_industry_agency_services = $_POST['check10_business_industry_agency_services'];
$check11_childrens_services = $_POST['check11_childrens_services'];
$check12_communication_services = $_POST['check12_communication_services'];
$check13_family_services = $_POST['check13_family_services'];
$check14_housing_home_modification_other_shelter_services = $_POST['check14_housing_home_modification_other_shelter_services'];
$chech15_il_skills_traing_life_skills_training = $_POST['chech15_il_skills_traing_life_skills_training'];
$check16_inforamtion_referral = $_POST['check16_inforamtion_referral'];
$check17_mobility_training = $_POST['check17_mobility_training'];
$check18_peer_counseling_services= $_POST['check18_peer_counseling_services'];
$check19_preventative_services = $_POST['check19_preventative_services'];
$check20_prostheses_orthics_other_appliances = $_POST['check20_prostheses_orthics_other_appliances'];
$check21_recreational_services = $_POST['check21_recreational_services'];
$check22_rehabilitation_technology_services = $_POST['check22_rehabilitation_technology_services'];
$check24_transportation_services = $_POST['check24_transportation_services'];
$check25_youth_services = $_POST['check25_youth_services'];
$check26_vocational_services = $_POST['check26_vocational_services'];
$check27_voter_reistration = $_POST['check27_voter_reistration'];
$textbox7_staff_person_date1 = $_POST['textbox7_staff_person_date1'];
$textbox8_staff_person_date2 = $_POST['textbox8_staff_person_date2'];

mysql_connect("localhost.org.com", "61606", "password") or die(mysql_error());
mysql_select_db("61606") or die(mysql_error());

$query="INSERT INTO servicerecord VALUES
('$textbox1name', '$textbox2date', '$check1male', '$check2female', '$text3phone', '$textbox4county', '$check3personwithimpairment', '$check4family_member_significant_other', '$textbox5other_specify', '$textbox6business_agency', '$chech5advocacy_legal_services', '$check9_architectual_barrier_services', '$check10_business_industry_agency_services', '$check11_childrens_services', '$check12_communication_services', '$check13_family_services', '$check14_housing_home_modification_other_shelter_services', '$chech15_il_skills_traing_life_skills_training', '$check16_inforamtion_referral', '$check17_mobility_training', '$check18_peer_counseling_services', '$check19_preventative_services', '$check20_prostheses_orthics_other_appliances', '$check21_recreational_services', '$check22_rehabilitation_technology_services', '$check24_transportation_services', '$check25_youth_services', '$check26_vocational_services', '$check27_voter_reistration', '$textbox7_staff_person_date1', '$textbox8_staff_person_date2')";

$check="select * from servicerecord where id='$id' ";

$check_result=mysql_query($check);

while($record=mysql_fetch_assoc($check_result) {

if($record["id"]==1) {

echo " Thank You Data Entered Into Database";
exit;


}else{

echo"Sorry There Was A Problam Please Try Agin";
exit;
}
?>
[/code]


ps. program how you want ok good luck mate.
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44461
Share on other sites

Hello all,
Thanks so much for your kind help. It was at least giving me error messages with the added error code but now I get the white screen of death with my code and the one above. The error code was that the values couldn't have '', so I tried nothing and; [''],[],[];['']; and all gave a sytax error but nothing but a white screen now. I'm doing this for a non profit place so any more ideas would be great. Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44491
Share on other sites

Hello,
I figured out the syntax error and it now posts the check boxes to the server but not any of the text. I appreciate your help if anyone has any ideas. The server side looks like it's setup right and it wants to give an error message after posting but it's blank after the word error. Thanks again,
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44525
Share on other sites

[!--quoteo(post=382762:date=Jun 12 2006, 01:26 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ Jun 12 2006, 01:26 AM) [snapback]382762[/snapback][/div][div class=\'quotemain\'][!--quotec--]
are you sure your columns are the correct data type for what you are trying to insert into them? that is, you cannot insert text into a column that is a number type, like int.
[/quote]


Hello,
Yes, I'm certain that part is right except I didn't know what to use for check marks and have it as bool. I don't know if that's right. It doesn't post any of the info for some reason.
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44757
Share on other sites

For checkmarks, it will submit the value=" " in your <input> area.

If you have <input type="checkbox" value="male" name="gender" /> then it will try to submit "male" if that box is checked. Those should be char or varchar. Look up the definitions of what each type will hold.

Try taking out your "insert" query for a moment & just ask it to echo back to you what was submitted in the form. When you can debug & get it to echo back properly, take out the echo & put your insert command back in.

Wendy
Link to comment
https://forums.phpfreaks.com/topic/11633-wont-post-to-sql/#findComment-44781
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.