Jump to content

Hi, i cant see the problem..forms..:P[solved]


AbydosGater

Recommended Posts

Hi ive been working on a script for my website..
Its just a basic for that updates the database but ive gone wrong somewhere naming the fields and ive read over and over the code and cant see where ive gone wrong..

<?php
} elseif ($_POST['Update'] && $_POST['newcharactername'] && $_POST['newage'] && $_POST['newrace'] && $_POST['newdob'] && $_POST['newpob'] && $_POST['newlanguages'] && $_POST['newinterests'] && $_POST['neweducation'] && $_POST['newservicenum'] && $_POST['newcurrentposition'] && $_POST['newservicerecord'] && $_POST['newdecorations'] && $_POST['newpersonalprofile'] && $_POST['newphysicalprofile'] && $_POST['newspecialnotes'] && $_POST['newfamilyrecord'] && $_POST['newrank']){

?>

Thats the code for the if statement that checks if ALL the form fields have been submitted...
and here is the code for the form.

[code]   <font color='#FFFFFF'>To edit your character bio please fill in the
          form below.Please note none of the form fields may be left blank.</font></p>
        <form name='editbio' method='post' action='editbio.php'>
          <font color='#FFFFFF'>Character Name:
          <input name='newcharactername' type='text' id='newcharactername' value='$charactername' maxlength='30' class='field1'>
          <br>
          Age:
          <input name='newage' type='text' id='newage' value='$age' size='4' maxlength='4' class='field1'>
          <br>
          Race:
          <input name='newrace' type='text' id='newrace' value='$race' maxlength='20' class='field1'>
          <br>
          Date Of Birth:
          <input name='newdob' type='text' id='newdob' value='$dob' maxlength='15' class='field1'>
          <br>
          Place Of Birth:
          <input name='newpob' type='text' id='newpob' value='$pob' maxlength='35' class='field1'>
          <br>
          Known Languages:
          <input name='newlanguages' type='text' id='newlanguages' value='$languages' maxlength='100' class='field1'>
          <br>
          Current Rank:
          <input name='newrank' type='text' id='newrank' value='$rank' maxlength='20' class='field1'>
          <br>
          Current Position:
          <input name='newcurrentposition' type='text' id='newcurrentposition' value='$currentposition' maxlength='50' class='field1'>
          <br>
          Service Number:
          <input name='newservicenum' type='text' value='$servicenum' maxlength='20' class='field1'>
          <br>
          <br>
          Interests:<br>
          <textarea name='newinterests' cols='50' id='newinterests' class='field1'>$interests</textarea>
          <br>
          Education:<br>
          <textarea name='neweducation' cols='50' id='neweducation' class='field1'>$education</textarea>
          <br>
          Decorations:<br>
          <textarea name='newdecorations' cols='50' rows='3' id='newdecorations' class='field1'>$decorations</textarea>
          <br>
          Service Record:<br>
          <textarea name='newservicerecord' cols='50' id='$newservicerecord' class='field1'>$servicerecord</textarea>
          <br>
          Family Record:<br>
          <textarea name='newfamilyrecord' cols='50' rows='3' id='newfamilyrecord' class='field1'>$familyrecord</textarea>
          <br>
          Personal Profile:<br>
          <textarea name='newpersonalprofile' cols='50' id='newpersonalprofile' class='field1'>$personalprofile</textarea>
          <br>
          Physical Profile:<br>
          <textarea name='newphysicalrecord' cols='50' id='newphysicalrecord' class='field1'>$physicalrecord</textarea>
          <br>
          Special Notes:<br>
          <textarea name='newspecialnotes' cols='50' id='newspecialnotes' class='field1'>$specialnotes</textarea>
          <br>
          <br>
          <input name='Update' type='submit' id='Update' value='Update' class='button1'>
          </font>
        </form>
[/code]
I really cant see where ive gone wrong.. can anyone?
I added a foreach $_POST to the script and all of the fields have been submitted, did i misspell somewhere?
Link to comment
https://forums.phpfreaks.com/topic/29121-hi-i-cant-see-the-problemformspsolved/
Share on other sites

It would be much easier to do this check is a foreach loop:
[code]<?php
$errs = false;
foreach($_POST as $key => $val)
    if ($key != 'Update')
      if (strlen(trim($val)) == 0) $errs = true;
if (!$errs) { // all fields submitted
?>[/code]

Ken
No i prefair to be doing it the way it is..
Ive been through it all i even added the following code...

foreach ($_POST as $field => $value){
echo "$field : $value <br>";
}

and it gave me...

newcharactername : value
newage : valu
newrace : value
newdob : value
newpob : value
newlanguages : value
newrank : value
newcurrentposition : value
newservicenum : value
newinterests : value
neweducation : value
newdecorations : value
newservicerecord : value
newfamilyrecord : value
newpersonalprofile : value
newphysicalrecord : value
newspecialnotes : value
Update : Update


So i know all of the fields are being sent..
So why is the IF that checks the $_POST failing?

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.