Jump to content

Process form submission with multiple actions in one PHP script


dcostyk

Recommended Posts

Hi. So what i would like to do is have a form filled out and submitted to a php script which will then do multiple actions on it (for example fopen/fwrite, mysql queries).

 

I have both scripts allready created and both of the work, however, when i put them in one php script it selects for the fopen/fwrite function over the mysql query independent of its position in the script(ive tried placing both in various positions.

 

I will post the script below, hopefully you can help me with it.

 

Thanks in advance!

 

<?php

$name = $_POST['name'];

$name2 = $_POST['name2'];

$title = $_POST['title'];

$title2 = $_POST['title2'];

$year = $_POST['year'];

$rating = $_POST['rating'];

$textarea = $_POST['textarea'];

$trailer = $_POST['trailer'];

$movie = $_POST['movie'];

$game = $_POST['game'];

$tvshow = $_POST['tvshow'];

$link = "<li><a href='$name2/$title2.html' target='_parent'>";

$title3 = "$title</a> </li>";

$sPattern = '/\s*/m';

$sReplace = '';

$review= stripslashes($textarea);

 

 

$con = mysql_connect("mysql9.000webhost.com","a5118716_thereel","saxophone88");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("a5118716_thereel", $con);

 

$sql = "INSERT INTO recent (id, title, link) VALUES ('', '$title3', '$link')";

$sql = @mysql_query($sql);

 

 

 

mysql_close($con);

 

$ourFileName = "/home/a5118716/public_html/$name2/$title2.html";

$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");

$stringData = <<<EOD

<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>

<html xmlns='http://www.w3.org/1999/xhtml'>

<head>

<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />

<title>TheReelEvaluation - $title ($year)</title>

<style type='text/css' media='all'>

<!--

@import url('../styles.css');

.style1 {color: #FFFFFF}

-->

</style>

<!--[if IE 5]>

 

<style type='text/css'>

#outerWrapper #subcontentWrapper #rightColumn {

  width: 220px;

}

</style>

<![endif]-->

<!--[if IE]>

<style type='text/css'>

#outerWrapper #subcontentWrapper #content {

  zoom: 1;

}

 

</style>

<![endif]-->

<script type="text/javascript" src="/konami.js"></script>

<script type="text/javascript">

konami = new Konami()

konami.load("http://www.thereelevaluation.host56.com/members/");

</script>

</head>

<body>

<div id='wrapperbackground'>

  <div id='outerWrapper'>

    <div id='header'>

      <div id='logo'><a href='#'><img src='../images/logo.png' alt='Logo' width='350' height='41' /></a></div>

      <div id='links'><a href='../aboutus.html'>About Us</a> | <a href='contactus.html'>Contact Us</a> | <a href='../problems.html'>Problems?</a></a></div>

      <div class='clearFloat'></div>

    </div>

    <div id='nav'>

      <ul>

        <li><a href='../index.html'><span>Home</span></a></li>

        <li><a href='../news.html'><span>News</span></a></li>

        <li><a href='../newrelease.html'><span>New Releases</span></a></li>

      </ul>

      <ul>

        <li><a href='../movie.html'><span>Movies</span></a></li>

      </ul>

      <ul>

        <li><a href='../tv.html'><span>TV Shows</span></a></li>

      </ul>

      <ul>

        <li><a href='../game.html'><span>Games</span></a></li>

      </ul>

      <ul>

        <li><a href='../net.html'><span>The Net</span></a></li>

      </ul>

      <ul>

        <li><a href='../reel10.html'><span>Reel 10</span></a></li>

      </ul>

      <ul>

        <li><a href='../reelteam.html'><span>The Reel Team</span></a></li>

      </ul>

      <ul>

        <li><a href='../request.html'><span>Request</span></a></li>

      </ul>

    </div>

    <div id='feature' style='display:none;'></div>

    <div id='subcontentWrapper'>

      <div id='content'> <!-- TemplateBeginEditable name='content' -->

        <h1> $title ($year)<img src='$rating' width='125' height='25' hspace='25' /></h1>

        <p>Reviewed By $name</p>

        <p>$review</p>

        <h2><a href='$trailer'>Trailer</a></h2>

        <div class='featureboxes'>

        </div>

       

        <br style='clear: left;' />

      <!-- TemplateEndEditable --></div>

      <div id='rightColumn'>

        <div id='rightColumnContent'>

          <h3 align='center'>Recently Reviewed</h3>

          <iframe

name='iframe2'

src='../recentreview.html'

width='210'

height='195'

frameborder='1'

vspace='0'

hspace='0'

marginwidth='0'

marginheight='0'

scrolling='no'

noresize></iframe>

        <!-- TemplateEndEditable --></div>

      </div>

      <br class='clearFloat' />

    </div>

  </div>

</div>

<div id='footer'><img src='' width='1' height='1' />Copyright © 2009 The Reel Evaluation| <a href='#'>Site Map</a> | <a href='#'>Privacy Policy</a></div>

<div id='credit'><a href=''>Site Design by Dustin Costyk</a><a href=''></a> 2009</div>

</body>

</html>

EOD;

 

fwrite($ourFileHandle, $stringData);

fclose($ourFileHandle);

 

 

 

$theResults = <<<EOD

<html>

<head>

<title>sent message</title>

<meta http-equiv="refresh" content="5;URL=http://thereelevaluation.host56.com/$name2/$title2.html">

<style type="text/css">

<!--

body {

background-color: #0B2653;

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 20px;

font-style: normal;

line-height: normal;

font-weight: normal;

color: #fec001;

text-decoration: none;

padding-top: 200px;

margin-left: 150px;

width: 800px;

}

 

-->

</style>

</head>

<div align="center">Your review has been submitted!<br />

It will be displayed in just a few seconds. <br />

Please verify your post. Press back to fix, and resubmit.<br />

Thanks!</div>

</div>

</body>

</html>

EOD;

echo "$theResults";

 

?>

 

[attachment deleted by admin]

A script will run in order and in full (ie all the way to the end) unless you somehow change that. Generally speaking if you are self submitting (ie submitting a form to the same page you are filling the form in on) you will need to wrap any logic that relies on $_POST data inside a block of logic so that it is not processed the first time the page is loaded.

 

if( isset( $_POST['submit'] ) ) {
   // process the information
} 

my form is in a different html file, that submits to this php file.

how would i get this script to run both of the actions in it, currently it only runs the fopen, fwrite function and ignores the mysql query. I will also have many other sql queries that i want to add to the file eventually.

 

If you could tell me what i need to change for it to run multiple functions, in one script. or be able to send variables to multiple php scripts when clicking on the html submit button.

 

Thanks, Dustin

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.