Jump to content

PHP Form not working right...


Recommended Posts

I'm not sure what to do but for some reason the file is not going into the folder, although the name is showing up in the db table. The folder has all permissions enabled.

 

<?php

include("settings.php");

include("header.php");

if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form

?>

 

<!-- InstanceBeginEditable name="text_box" -->

                                    <h1 class="Head">Soccer United <br>

                                      <font color="#000000">African Team Member Fact Sheet</font>

                                    </h1>

<form action="" method="post" enctype="multipart/form-data" name="join">

                                      <p>Name*:<br />

                                        <input name="name" type="text" id="name" size="40">

                                      </p>

                                      <p>Age*:

                                        <input name="age" type="text" id="age" size="10" maxlength="2">

                                          <br />

                                      </p>

                                      <p> Location*: <br />

                                        <input name="location" type="text" id="location" size="40">

                                      </p>

<p> Favorite Activity: <br />

                                        <input name="activity" type="text" id="activity" size="40">

<p> Soccer Story: <br />

                                        <textarea name="grsstory" type="text" id="grsstory" cols="40"></textarea>

</p>

<p>Upload Photo: <br />

                                        <input type="file" name="pic">

                                        <br />

                                      </p>

<p>

                                        <input type="submit" name="submit" value="submit">

                                        <a href="thanks.html">After submitting, you'll go to this page</a></p>

                                    </form>

<?php

//imageupload

 

$target = "uploads/";

$target = $target . basename( $_FILES['pic']['name']) ;

$ok=1;

if(move_uploaded_file($_FILES['pic']['tmp_name'], $target))

{

echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";

}

else {

echo "Sorry, there was a problem uploading your file.";

}

//endimageupload

 

} else {

 

// Check to see if the required fields are filled in. If not display errors.

$error = 0;

if ($_POST['name'] == "") {

echo "Sorry, but Name was not entered. <br />";

$error = $error + 1 ;

}

if ($_POST['age'] == "") {

echo "Sorry, but age was not entered.  <br />";

$error = $error + 1;

}

if ($_POST['location'] == "") {

echo "Sorry, but email was not entered. <br />";

$error = $error + 1;

}

echo "<a href=\"javascript:history.go(-1)\">Go back</a>";

// If the required fields are filled in then proceed.

if ($error == 0) {

 

// Set Variable names and get data from form and insert into database.

// also checks to make sure it is good data being inserted and escapes possible injection attacks.

$Fname = mysql_real_escape_string(trim($_REQUEST["name"]));

$Age = mysql_real_escape_string(trim($_REQUEST["age"]));

$Location = mysql_real_escape_string(trim($_REQUEST["location"]));

$Activity = mysql_real_escape_string(trim($_REQUEST["activity"]));

$Grsstory = mysql_real_escape_string(trim($_REQUEST["grsstory"]));

$Image = mysql_real_escape_string(trim($_FILES['pic']['name']));

$MySQLquery = "INSERT INTO team_member_teammate VALUES('','$Fname','$Age','$Location','$Activity','$Grsstory','$Image')";

$results = mysql_query($MySQLquery); //Query the results

// script to redirect to thanks.html page.

print "<script>";

print " self.location='thanks.html';";

print "</script>";

// If there is a problem inserting into database show error.

if(!$results){

echo(mysql_error());

}

}

}

// bottom of the template do not remove.

include("footer.php");

?>

Link to comment
https://forums.phpfreaks.com/topic/102174-php-form-not-working-right/
Share on other sites

change

$ok=1 ;

 

to

 

$ok = "1" ;

 

 

 

 

 

<?php
include("settings.php");
include("header.php");
   if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>

<!-- InstanceBeginEditable name="text_box" -->
                                    <h1 class="Head">Soccer United

                                      <font color="#000000">African Team Member Fact Sheet</font>
                                    </h1>
<form action="" method="post" enctype="multipart/form-data" name="join">
                                      <p>Name*:

                                        <input name="name" type="text" id="name" size="40">
                                      </p>
                                      <p>Age*:
                                        <input name="age" type="text" id="age" size="10" maxlength="2">
                                          

                                      </p>
                                      <p> Location*:

                                        <input name="location" type="text" id="location" size="40">
                                      </p>
<p> Favorite Activity:

                                        <input name="activity" type="text" id="activity" size="40">
<p> Soccer Story:

                                        <textarea name="grsstory" type="text" id="grsstory" cols="40"></textarea>
</p>
<p>Upload Photo:

                                        <input type="file" name="pic">
                                       

                                      </p>
<p>
                                        <input type="submit" name="submit" value="submit">
                                        <a href="thanks.html">After submitting, you'll go to this page[/url]</p>
                                    </form>
<?php
   //imageupload

$target = "uploads/";
$target = $target . basename( $_FILES['pic']['name']) ;
$ok = "1" ;
if(move_uploaded_file($_FILES['pic']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
//endimageupload
   
} else {
   
// Check to see if the required fields are filled in. If not display errors.
   $error = 0;
   if ($_POST['name'] == "") {
echo "Sorry, but Name was not entered.
";
$error = $error + 1 ;
}
if ($_POST['age'] == "") {
echo "Sorry, but age was not entered. 
";
$error = $error + 1;
}
if ($_POST['location'] == "") {
echo "Sorry, but email was not entered.
";
$error = $error + 1;
}
echo "<a href=\"javascript:history.go(-1)\">Go back[/url]";
// If the required fields are filled in then proceed.
if ($error == 0) {

   // Set Variable names and get data from form and insert into database.
   // also checks to make sure it is good data being inserted and escapes possible injection attacks.
   $Fname       = mysql_real_escape_string(trim($_REQUEST["name"]));
   $Age       = mysql_real_escape_string(trim($_REQUEST["age"]));
   $Location    = mysql_real_escape_string(trim($_REQUEST["location"]));
   $Activity    = mysql_real_escape_string(trim($_REQUEST["activity"]));
   $Grsstory    = mysql_real_escape_string(trim($_REQUEST["grsstory"]));
   $Image       = mysql_real_escape_string(trim($_FILES['pic']['name']));
   $MySQLquery = "INSERT INTO team_member_teammate VALUES('','$Fname','$Age','$Location','$Activity','$Grsstory','$Image')";
   $results = mysql_query($MySQLquery);    //Query the results
   // script to redirect to thanks.html page.
   print "<script>";
   print " self.location='thanks.html';";
   print "</script>";
   // If there is a problem inserting into database show error.
   if(!$results){
      echo(mysql_error());
      }
   }
}
// bottom of the template do not remove.
include("footer.php");
?>

<?php
include("settings.php");
include("header.php");
   if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>

<!-- InstanceBeginEditable name="text_box" -->
                                    <h1 class="Head">Soccer United

                                      <font color="#000000">African Team Member Fact Sheet</font>
                                    </h1>
<form action="" method="post" enctype="multipart/form-data" name="join">
                                      <p>Name*:

                                        <input name="name" type="text" id="name" size="40">
                                      </p>
                                      <p>Age*:
                                        <input name="age" type="text" id="age" size="10" maxlength="2">
                                          

                                      </p>
                                      <p> Location*:

                                        <input name="location" type="text" id="location" size="40">
                                      </p>
<p> Favorite Activity:

                                        <input name="activity" type="text" id="activity" size="40">
<p> Soccer Story:

                                        <textarea name="grsstory" type="text" id="grsstory" cols="40"></textarea>
</p>
<p>Upload Photo:

                                        <input type="file" name="pic">
                                       

                                      </p>
<p>
                                        <input type="submit" name="submit" value="submit">
                                        <a href="thanks.html">After submitting, you'll go to this page[/url]</p>
                                    </form>
<?php

}
   //imageupload

$target = "uploads/";
$target = $target . basename( $_FILES['pic']['name']) ;
$ok = "1" ;
if(move_uploaded_file($_FILES['pic']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else {
echo "Sorry, there was a problem uploading your file.";
}
//endimageupload
   
} else {
   
// Check to see if the required fields are filled in. If not display errors.
   $error = 0;
   if ($_POST['name'] == "") {
echo "Sorry, but Name was not entered.
";
$error = $error + 1 ;
}
if ($_POST['age'] == "") {
echo "Sorry, but age was not entered. 
";
$error = $error + 1;
}
if ($_POST['location'] == "") {
echo "Sorry, but email was not entered.
";
$error = $error + 1;
}
echo "<a href=\"javascript:history.go(-1)\">Go back[/url]";
// If the required fields are filled in then proceed.
if ($error == 0) {

   // Set Variable names and get data from form and insert into database.
   // also checks to make sure it is good data being inserted and escapes possible injection attacks.
   $Fname       = mysql_real_escape_string(trim($_REQUEST["name"]));
   $Age       = mysql_real_escape_string(trim($_REQUEST["age"]));
   $Location    = mysql_real_escape_string(trim($_REQUEST["location"]));
   $Activity    = mysql_real_escape_string(trim($_REQUEST["activity"]));
   $Grsstory    = mysql_real_escape_string(trim($_REQUEST["grsstory"]));
   $Image       = mysql_real_escape_string(trim($_FILES['pic']['name']));
   $MySQLquery = "INSERT INTO team_member_teammate VALUES('','$Fname','$Age','$Location','$Activity','$Grsstory','$Image')";
   $results = mysql_query($MySQLquery);    //Query the results
   // script to redirect to thanks.html page.
   print "<script>";
   print " self.location='thanks.html';";
   print "</script>";
   // If there is a problem inserting into database show error.
   if(!$results){
      echo(mysql_error());
      }
   }
}
// bottom of the template do not remove.
include("footer.php");
?>

 

Try this, you forgot to close the bracket that you opened on line 4

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.