Jump to content

Form not submitting


csteff24

Recommended Posts

I have a database with information for a bunch of different clubs that I want the club presidents to be able to edit. I've gotten it set up and it all works correctly, but I realized that it would be nice for the information that's already in the database to come up as the default on the form. So far I have this - http://www.csteffen.com/staples/selectedit.php

It comes up correctly, but the form won't submit.

(If you're going to try it out, please use the club "Club to edit". I don't want any of the others being changed)

 

Here's the code for selectedit

 

<?php
include("include.php");
doDB();

if (!$_POST) {
$get_list_sql = "SELECT id, name FROM clubs ORDER BY name";
$get_list_res = mysqli_query($mysqli, $get_list_sql)
     or die(mysqli_error($mysqli));


$display_block .= "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Select a Club to Edit:</strong><br/>
<select name=\"sel_id\">
<option value=\"\">-- Select One --</option>";

while($recs = mysqli_fetch_array($get_list_res)) {
     $id = $recs['id'];
     $name = $recs['name'];
     $display_block .= "<option value=\"".$id."\">".
     $name ."</option>";
}
$display_block .= "
</select>
<p><input type=\"submit\" name=\"submit\"
value=\"Edit Selected Entry\"></p>
</form>";

mysqli_free_result($get_list_res);

} else if ($_POST) {

header ("Location: edititem.php?id=".$_POST["sel_id"]."");
exit;
}

?>
<html>
<head>
<title>Delete Entries</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>

 

And here's the code for edititem.php (which depends on which club you select in selectedit.php)

 

<?php
include("include.php");
doDB();

if (!$_POST) {

$get_club_sql = "SELECT * FROM clubs WHERE id = '".$_GET["id"]."'";
$get_club_res = mysqli_query($mysqli, $get_club_sql)
       or die(mysqli_error($mysqli));

     while ($club_info = mysqli_fetch_array($get_club_res)) {
          $name = strtoupper($club_info['name']);
          $adv = $club_info['adv'];
          $meet = stripslashes($club_info['meet']);
          $descrip = stripslashes ($club_info['descrip']);
          $pres = $club_info['pres'];
          $email = $club_info['email']; }

     $display_block .= "
     <h1>".$name."</h1>

     <p><strong>Faculty Advisor:</strong><br/>
     <input type=\"text\" name=\"adv\" size=\"30\" maxlength=\"50\" value=\"".$adv."\"></p>

     <p><strong>Meeting time/place:</strong><br/>
     <input type=\"text\" name=\"meet\" size=\"30\" maxlength=\"200\" value=\"".$meet."\">

     <p><strong>Student President - (if multiple, use &):</strong><br/>
     <input type=\"text\" name=\"pres\" size=\"30\" maxlength=\"50\" value=\"".$pres."\">

     <p><strong>President contact info:</strong><br/>
     <input type=\"text\" name=\"email\" size=\"30\" maxlength=\"50\" value=\"".$email."\">

     <p><strong>Club Description:</strong><br/>
     <textarea name=\"descrip\" cols=\"50\" rows=\"5\"
     wrap=\"virtual\">".$descrip."</textarea></p>

     <p><input type=\"submit\" name=\"submit\" value=\"Edit Club\"></p>
     </form>";

} else if ($_POST) {
     if ($_POST["adv"]) {

$update_adv_sql = "UPDATE clubs SET adv = '".$_POST["adv"]."' WHERE id = '".$_GET["id"]."'"; 
    $update_adv_res = mysqli_query($mysqli, $update_adv_sql)
         or die (mysqli_error($mysqli));
}
if ($_POST["meet"]) {

$update_meet_sql = "UPDATE clubs SET meet = '".$_POST["meet"]."' WHERE id = '".$_GET["id"]."'";

    $update_meet_res = mysqli_query($mysqli, $update_meet_sql)
         or die (mysqli_error($mysqli));
}
if ($_POST["pres"]) {

$update_pres_sql = "UPDATE clubs SET pres = '".$_POST["pres"]."' WHERE id = '".$_GET["id"]."'"; 

    $update_pres_res = mysqli_query($mysqli, $update_pres_sql)
         or die (mysqli_error($mysqli));
}
if ($_POST["email"]) {

$update_email_sql = "UPDATE clubs SET email = '".$_POST["email"]."' id = '".$_GET["id"]."'"; 

    $update_email_res = mysqli_query($mysqli, $update_email_sql)
         or die (mysqli_error($mysqli));
}

if ($_POST["descrip"]) {

$update_descrip_sql = "UPDATE clubs SET descrip = '".$_POST["descrip"]."' id = '".$_GET["id"]."'";  

    $update_descrip_res = mysqli_query($mysqli, $update_descrip_sql)
         or die (mysqli_error($mysqli));
}

mysqli_free_result($get_list_res);

mysqli_close($mysqli);
$display_block = "<p>Your entry has been edited. <br/>View your edited entry <a href=\"showitem.php?id=".$id."\">here</a>";

}
?>

<html>
<head>
<title>Edit Club</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>

 

Can you tell what I'm doing wrong? Thank you!!

Link to comment
https://forums.phpfreaks.com/topic/181656-form-not-submitting/
Share on other sites

Prepare to smack yourself in the head.

 

Looking at the source code from the generated page, it shows

 

<html>
<head>
<title>Edit Club</title>
</head>
<body>

     <h1>CLUB TO EDIT</h1>

     <p><strong>Faculty Advisor:</strong><br/>
     <input type="text" name="adv" size="30" maxlength="50" value="MeDe"></p>

     <p><strong>Meeting time/place:</strong><br/>
     <input type="text" name="meet" size="30" maxlength="200" value="Tuesdays">

     <p><strong>Student President - (if multiple, use &):</strong><br/>
     <input type="text" name="pres" size="30" maxlength="50" value="Pres">

     <p><strong>President contact info:</strong><br/>

     <input type="text" name="email" size="30" maxlength="50" value="[email protected]">

     <p><strong>Club Description:</strong><br/>
     <textarea name="descrip" cols="50" rows="5"
     wrap="virtual">Description</textarea></p>

     <p><input type="submit" name="submit" value="Edit Club"></p>
     </form></body>
</html>

 

Your <form> tag is not there

 

 

Link to comment
https://forums.phpfreaks.com/topic/181656-form-not-submitting/#findComment-958147
Share on other sites

<?php
include("include.php");
doDB();

if (!$_POST) {

$get_club_sql = "SELECT * FROM clubs WHERE id = '".$_GET["id"]."'";
$get_club_res = mysqli_query($mysqli, $get_club_sql)
       or die(mysqli_error($mysqli));

     while ($club_info = mysqli_fetch_array($get_club_res)) {
          $name = strtoupper($club_info['name']);
          $adv = $club_info['adv'];
          $meet = stripslashes($club_info['meet']);
          $descrip = stripslashes ($club_info['descrip']);
          $pres = $club_info['pres'];
          $email = $club_info['email']; }

     $display_block .= "
     <h1>".$name."</h1>

     <form action="" method="post">     

     <p><strong>Faculty Advisor:</strong><br/>
     <input type=\"text\" name=\"adv\" size=\"30\" maxlength=\"50\" value=\"".$adv."\"></p>

     <p><strong>Meeting time/place:</strong><br/>
     <input type=\"text\" name=\"meet\" size=\"30\" maxlength=\"200\" value=\"".$meet."\">

     <p><strong>Student President - (if multiple, use &):</strong><br/>
     <input type=\"text\" name=\"pres\" size=\"30\" maxlength=\"50\" value=\"".$pres."\">

     <p><strong>President contact info:</strong><br/>
     <input type=\"text\" name=\"email\" size=\"30\" maxlength=\"50\" value=\"".$email."\">

     <p><strong>Club Description:</strong><br/>
     <textarea name=\"descrip\" cols=\"50\" rows=\"5\"
     wrap=\"virtual\">".$descrip."</textarea></p>

     <p><input type=\"submit\" name=\"submit\" value=\"Edit Club\"></p>
     </form>";

} else if ($_POST) {
     if ($_POST["adv"]) {

$update_adv_sql = "UPDATE clubs SET adv = '".$_POST["adv"]."' WHERE id = '".$_GET["id"]."'"; 
    $update_adv_res = mysqli_query($mysqli, $update_adv_sql)
         or die (mysqli_error($mysqli));
}
if ($_POST["meet"]) {

$update_meet_sql = "UPDATE clubs SET meet = '".$_POST["meet"]."' WHERE id = '".$_GET["id"]."'";

    $update_meet_res = mysqli_query($mysqli, $update_meet_sql)
         or die (mysqli_error($mysqli));
}
if ($_POST["pres"]) {

$update_pres_sql = "UPDATE clubs SET pres = '".$_POST["pres"]."' WHERE id = '".$_GET["id"]."'"; 

    $update_pres_res = mysqli_query($mysqli, $update_pres_sql)
         or die (mysqli_error($mysqli));
}
if ($_POST["email"]) {

$update_email_sql = "UPDATE clubs SET email = '".$_POST["email"]."' id = '".$_GET["id"]."'"; 

    $update_email_res = mysqli_query($mysqli, $update_email_sql)
         or die (mysqli_error($mysqli));
}

if ($_POST["descrip"]) {

$update_descrip_sql = "UPDATE clubs SET descrip = '".$_POST["descrip"]."' id = '".$_GET["id"]."'";  

    $update_descrip_res = mysqli_query($mysqli, $update_descrip_sql)
         or die (mysqli_error($mysqli));
}

mysqli_free_result($get_list_res);

mysqli_close($mysqli);
$display_block = "<p>Your entry has been edited. <br/>View your edited entry <a href=\"showitem.php?id=".$id."\">here</a>";

}
?>

<html>
<head>
<title>Edit Club</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>

 

Also, be sure to protect your input.

 

Also what you can select http://www.csteffen.com/staples/edititem.php?id=-1

Link to comment
https://forums.phpfreaks.com/topic/181656-form-not-submitting/#findComment-958151
Share on other sites

Thank you!!

It's working now except for one small thing...

When I hit submit, this error comes up "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 'id = '160'' at line 1"

The data is still edited and everything's working correctly, but the display block doesn't show up after I submit it

 

What did you mean by

Sorry, I'm very new at PHP haha

Link to comment
https://forums.phpfreaks.com/topic/181656-form-not-submitting/#findComment-958165
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.