PDA

View Full Version : Incorporating PHP



Medyman
07-12-2007, 06:18 AM
Hi all...

I'm kind of in a bind. This is like PHP 101 but I can't seem to figure it out.

I have this existing page (with some php on it already)

<?
$fail = false;
if(isset($_GET[s]))
include("search.php");
else
include("recent.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/dropdown.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<link type="text/css" rel="stylesheet" href="css/Style.css" />
<link rel="shortcut icon" href="favicon.ico" />
<title>THEPAPERBAGWRITER // CHANGING THE WAY INFORMATION FLOWS</title>
</head>
<body bgcolor="#ffffff">

<div id="watermarklogo" style="position:absolute;height:30px;overflow:hidden;"></div>
<script src="js/logo.js"></script>

<div id="container">
<div id="mainframe" >
<form id="myform">
<input type="text" class="textinput" /> <input class="submit" type="image" src="images/form.png" />
</form>

<div id="musicholder">
<div id="flashmusic">To view the header, please upgrade your Flash plugin.</div>
<script type="text/javascript">
var so = new SWFObject("musicPlayer.swf", "music", "340", "20", "8", "#CCCCCC");
so.addParam("quality", "high");
so.addParam("wmode", "opaque");
so.addParam("salign", "t");
so.addParam("scale", "noscale");
so.write("flashmusic");
</script>

</div>
<div id="musiccredit" style='float:right;'><a href="http://www.caribou.fm/site/">MUSIC BY CARIBOU</a></div>
<div id="menuline">&nbsp;</div>

<div id="flashcontent">To view the header, please upgrade your Flash plugin.</div>
<script type="text/javascript">
var so = new SWFObject("header.swf", "index", "700", "250", "8", "#ffffff");
so.addParam("quality", "high");
so.addParam("wmode", "opaque");
so.addParam("salign", "t");
so.addParam("scale", "noscale");
so.write("flashcontent");
</script>

<div id="leftframe">
<div id ="news">
<div id="framehead"><img src="images/news.jpg"></div>
<div id="newsart">
<span id="date">07.01.07</span>
<br />Submissions for Brown Paper 1 will be closing soon, so send us your contributions of poetry, prose, commentary and art before it's too late. Send all submissions to <a id="email" href="mailto:printsubmissions@thepaperbagwriter.org">printsubmissions@thepaperbagwriter.org</a>. For more information, see our submission page.
</br>
</br><br /><span id="date">06.30.07</span>
<br />It is with great sadness that we announce, Kim Maria or Revelation Studios has been diagnosed with Cancer. Kim's work has redefined the context of collage and greatly expanded the vernacular of assemblage art. Her innovations have been spectacular and her contributions even greater. Over the course of the last few months, the artistic community has stepped forward in a tremendous way to supplement Kim's extensive medical costs. Benefit auctions have taken place all throughout the country featuring a breadth of artistic talent from Mark Ryden, to Gary Baseman, to Mark Todd and Esther Pearl Watson. To do our share, we have decided to publish a retrospective of Kim and her husband Craig La Rotunda's work, in a folio book that will help to supplement her outstanding medical bills. We are working with Kim and Craig, as to the specifics but expect to hit the shelves soon. 100 % of the profits will go to Kim; the books will be available for pre-order soon. We'll keep you posted.
</br>
</br><br /><span id="date">06.27.07</span>
</br>New Site! Yay, it's been a few months but it's finally here. We know it's been a long construction, but we'd like to get back in the swing of things as quickly as possible so send your submissions or poetry, prose, comment and criticism to websubmissions @thepaperbagwriter.org , so we can get the new site in motion. We've also added a new block section, we're you can post story ideas or fragments. Let us know what you think of the new site, enjoy.
</div>
</div>
</br>
<div id="video">
<div id="framehead" style='background-image:URL("images/videos.jpg");'><a href="http://www.adbusters.org"><img src="images/kalle.gif" style='float:right;margin-top:2px;'></a></div>
<div id="youtube"><embed src="http://www.youtube.com/v/-GhXKILWcG8" type="application/x-shockwave-flash" width="100%" height="210"></embed></div>
</div>
</br>
<div id="personals">
<div id="framehead"><img src="images/personals.jpg"></div>
<span id="opening">LOOKING FOR A CARTOONIST</span>
<span id="desc">We're looking for a cartoonist, somewhere between 4'8 and 8'9, preferably male or female (although I don't discriminate) , must be an outgoing, fun-loving romantic who shares my adoration and enthusiasm for Fellini and Mozart and candlelit dinst have at least six fingers and some experience in the visual arts. </br></br>*If you meet at least 32% of these requirements and are interested in joining our team, drop us a line at 516.474.3947 or email us at team@thepaperbagwriter.org</span>
</div>


</div>

<div id="rightframe">
<div id ="about">
&nbsp;
</div>
</div>
</div>

<div id="sideframe">
<a href="brownpaper.php"><img src="images/firstissue.jpg"></a>
<div id="framehead"><img src="images/bptitle.jpg"></div>
</br>

<a href="paperandplastic.php"><img src="images/pp.jpg"></a>
</br>

<a href="donations.php"><img src="images/donate2.jpg" ></a>
</br>

<a href="subscribe.php"><img src="images/subscribe2.jpg" ></a>
</br>

<a href="shop.php"><img src="images/shop2.jpg" ></a>
</br>

<a href="http://www.myspace.com/mybrownpaperbag"><img src="images/myspace2.jpg" ></a>

</div>
</div>

<div id="dropinboxv2cover">
<div id="dropinboxv2">
<div id="framehead" style='width:98%'><img src="images/mlist.jpg"></div>
<div id="bodycontent">
Join our mailing list for news updates, readings and exclusive invitations to PBW events, gatherings and exorcisms. Once you join there is no turning back! (only kidding there is an unsubscribe option – but that’s complicated and involves phone books and taxidermied animals and besides which you’ll never want to leave anyway).
</br>
<form id="submit">
<img src="images/name.jpg"><input style='position:relative;top:-4px;left:5px;' type="text" class="textinput" style='width:328px' name="name" id="name"/>
</br>
<img src="images/email.jpg"><input style='position:relative;top:-4px;left:5px;' type="text" class="textinput" style='width:328px' name="email" id="email"/>
<input class="submit" type="submit" value="submit" style='float:right;margin-right:18px;' id="add" />
</form>
</div>
</div>
</div>
<p align="right"><a href="#" onClick="dismissboxv2();return false">&nbsp;</a></p>

</body>
</html>


I'm trying to add some php to post the values of the name & email to a mySQL db.

I did it in testing with this page:


<?php
if(isset($_POST['add']))
{
include 'config.php';
include 'opendb.php';

$name = $_POST['name'];
$email = $_POST['email'];

$query = "INSERT INTO mlist VALUES ('','${name}','${email}')";
mysql_query($query) or die('Error, insaert query failed');

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');

include 'closedb.php';
echo "New MySQL user added";
}
else
{
?>
<form method="post">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Name</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td width="100">Email</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="100">&nbsp;</td>
<td><input name="add" type="submit" id="add" value="Add New User"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>


But when I try to incorporate it into the actual page, it doesn't work. The page just refershes and the values I entered in fields show up in the address bar (http://www.url.com/page.php?name=Name&email=Email)

jc_gmk
07-12-2007, 07:53 AM
I might be wrong as i'm pretty new to PHP but I noticed that your form has no 'action'

e.g.

<form method="post" action="successful.php">

or

<?php $current_page = $_SERVER['PHP_SELF']; ?>

<form method="post" action="<?php print $current_page; ?>">

Hope this helps!

Medyman
07-12-2007, 01:56 PM
ahh, good observation!

That might be the culprit. I knew I was being dumb in some way.

Medyman
07-12-2007, 03:00 PM
That still doesn't seem to fix it.

Any other ideas people?

jc_gmk
07-12-2007, 03:20 PM
i might be wrong but looking at it, this also appears to be incorrect:



$query = "INSERT INTO mlist VALUES ('','${name}','${email}')";


Should it be:



$query = "INSERT INTO mlist VALUES ('$name', '$email')";

Medyman
07-12-2007, 03:23 PM
Well the PHP works...I've tested it with just a form on the page.

The problem I have is when I try adding the form to another page. I'm not sure what to do in this situation.

jc_gmk
07-12-2007, 03:27 PM
try changing the code for error reporting, it might give you a better understanding of whats going wrong!

from:



mysql_query($query) or die('Error, insaert query failed');


to:



mysql_query($query) or die(mysql_error());

Medyman
07-12-2007, 03:34 PM
Thanks for the help but still no change :(

I don't see what goes wrong between the test page (which works) and the actual page (which doesn't work).

This is how I have it, am I doing something wrong?


<?php
if(isset($_POST['add']))
{
include 'php/config.php';
include 'php/opendb.php';

$name = $_POST['name'];
$email = $_POST['email'];

$query = "INSERT INTO mlist VALUES ('','${name}','${email}')";
mysql_query($query) or die(mysql_error());

$query = "FLUSH PRIVILEGES";
mysql_query($query) or die(mysql_error());

include 'php/closedb.php';
echo "New MySQL user added";
}
else
{
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/dropdown.js"></script>
<script type="text/javascript" src="js/menu.js"></script>
<link type="text/css" rel="stylesheet" href="css/Style.css" />
<link rel="shortcut icon" href="favicon.ico" />
<title>THEPAPERBAGWRITER // CHANGING THE WAY INFORMATION FLOWS</title>
</head>
<body bgcolor="#ffffff">

<div id="watermarklogo" style="position:absolute;height:30px;overflow:hidden;"></div>
<script src="js/logo.js"></script>

<div id="container">
<div id="mainframe" >
<form id="myform">
<input type="text" class="textinput" /> <input class="submit" type="image" src="images/form.png" />
</form>

<div id="musicholder">
<div id="flashmusic">To view the header, please upgrade your Flash plugin.</div>
<script type="text/javascript">
var so = new SWFObject("musicPlayer.swf", "music", "340", "20", "8", "#CCCCCC");
so.addParam("quality", "high");
so.addParam("wmode", "opaque");
so.addParam("salign", "t");
so.addParam("scale", "noscale");
so.write("flashmusic");
</script>

</div>
<div id="musiccredit" style='float:right;'><a href="http://www.caribou.fm/site/">MUSIC BY CARIBOU</a></div>
<div id="menuline">&nbsp;</div>

<div id="flashcontent">To view the header, please upgrade your Flash plugin.</div>
<script type="text/javascript">
var so = new SWFObject("http://www.thepaperbagwriter.com/header.swf", "index", "700", "250", "8", "#ffffff");
so.addParam("quality", "high");
so.addParam("wmode", "opaque");
so.addParam("salign", "t");
so.addParam("scale", "noscale");
so.write("flashcontent");
</script>

<div id="leftframe">
<div id ="news">
<div id="framehead"><img src="images/news.jpg"></div>
<div id="newsart">
<span id="date">07.01.07</span>
<br />Submissions for Brown Paper 1 will be closing soon, so send us your contributions of poetry, prose, commentary and art before it's too late. Send all submissions to <a id="email" href="mailto:printsubmissions@thepaperbagwriter.org">printsubmissions@thepaperbagwriter.org</a>. For more information, see our submission page.
</br>
</br><br /><span id="date">06.30.07</span>
<br />It is with great sadness that we announce, Kim Maria or Revelation Studios has been diagnosed with Cancer. Kim's work has redefined the context of collage and greatly expanded the vernacular of assemblage art. Her innovations have been spectacular and her contributions even greater. Over the course of the last few months, the artistic community has stepped forward in a tremendous way to supplement Kim's extensive medical costs. Benefit auctions have taken place all throughout the country featuring a breadth of artistic talent from Mark Ryden, to Gary Baseman, to Mark Todd and Esther Pearl Watson. To do our share, we have decided to publish a retrospective of Kim and her husband Craig La Rotunda's work, in a folio book that will help to supplement her outstanding medical bills. We are working with Kim and Craig, as to the specifics but expect to hit the shelves soon. 100 &#37; of the profits will go to Kim; the books will be available for pre-order soon. We'll keep you posted.
</br>
</br><br /><span id="date">06.27.07</span>
</br>New Site! Yay, it's been a few months but it's finally here. We know it's been a long construction, but we'd like to get back in the swing of things as quickly as possible so send your submissions or poetry, prose, comment and criticism to websubmissions @thepaperbagwriter.org , so we can get the new site in motion. We've also added a new block section, we're you can post story ideas or fragments. Let us know what you think of the new site, enjoy.
</div>
</div>
</br>
<div id="video">
<div id="framehead" style='background-image:URL("images/videos.jpg");'><a href="http://www.adbusters.org"><img src="images/kalle.gif" style='float:right;margin-top:2px;'></a></div>
<div id="youtube"><embed src="http://www.youtube.com/v/-GhXKILWcG8" type="application/x-shockwave-flash" width="100%" height="210"></embed></div>
</div>
</br>
<div id="personals">
<div id="framehead"><img src="images/personals.jpg"></div>
<span id="opening">LOOKING FOR A CARTOONIST</span>
<span id="desc">We're looking for a cartoonist, somewhere between 4'8 and 8'9, preferably male or female (although I don't discriminate) , must be an outgoing, fun-loving romantic who shares my adoration and enthusiasm for Fellini and Mozart and candlelit dinst have at least six fingers and some experience in the visual arts. </br></br>*If you meet at least 32% of these requirements and are interested in joining our team, drop us a line at 516.474.3947 or email us at team@thepaperbagwriter.org</span>
</div>


</div>

<div id="rightframe">
<div id ="about">
&nbsp;
</div>
</div>
</div>

<div id="sideframe">
<a href="brownpaper.php"><img src="images/firstissue.jpg"></a>
<div id="framehead"><img src="images/bptitle.jpg"></div>
</br>

<a href="paperandplastic.php"><img src="images/pp.jpg"></a>
</br>

<a href="donations.php"><img src="images/donate2.jpg" ></a>
</br>

<a href="subscribe.php"><img src="images/subscribe2.jpg" ></a>
</br>

<a href="shop.php"><img src="images/shop2.jpg" ></a>
</br>

<a href="http://www.myspace.com/mybrownpaperbag"><img src="images/myspace2.jpg" ></a>

</div>
</div>

<div id="dropinboxv2cover">
<div id="dropinboxv2">
<div id="framehead" style='width:98%'><img src="images/mlist.jpg"></div>
<div id="bodycontent">
Join our mailing list for news updates, readings and exclusive invitations to PBW events, gatherings and exorcisms. Once you join there is no turning back! (only kidding there is an unsubscribe option – but that’s complicated and involves phone books and taxidermied animals and besides which you’ll never want to leave anyway).
</br>

<form method="post">
<img src="images/name.jpg"><input style='position:relative;top:-4px;left:5px;' type="text" class="textinput" style='width:328px' name="name" id="name"/>
</br>
<img src="images/email.jpg"><input style='position:relative;top:-4px;left:5px;' type="text" class="textinput" style='width:328px' name="email" id="email"/>
<input class="submit" type="submit" value="submit" style='float:right;margin-right:18px;' id="add" />
</form>
</div>
</div>
</div>
<p align="right"><a href="#" onClick="dismissboxv2();return false">&nbsp;</a></p>
<?php
}
?>
</body>
</html>

jc_gmk
07-12-2007, 03:44 PM
I noticed you've got no action on your form again.

also the page you copied it into; has it got a .php file extension?

Other than that, that's me all out of ideas!
Have to leave it to the rest of you!

Medyman
07-12-2007, 03:48 PM
What should I make the action, then?

Because on my test page, I have no action and it still works.

And yes, it does have a .php extension.

jc_gmk
07-12-2007, 03:52 PM
Set it to the page that is going to collect the data from the form.

In this case it looks like its the same place that the form is on.

e.g


<form method="post" action="currentpagename.php">

JShor
07-12-2007, 04:04 PM
When you are posting those values, as opposed to being posted to MySQL, and therefore is posting it as queries. Its simply fixed by putting the form action, the <form> tag should look like this:


<form action="<? $_SERVER['PHP_SELF'] ?>" method="post">