Jump to content


PHP help


4 replies to this topic

#1 iPsyko

    Young Padawan

  • Members
  • Pip
  • 53 posts

Posted 25 September 2005 - 08:48 AM

Hey people,

I am in a bit of a dilemma. On my site, i have a Shoutbox (which is done through MySQL, and works fine). But, i also have a contact form that i include on the same page as the shoutbox. For some reason, my contact form isn't sending, and now the shoutbox doesnt work. Please help me, here is the code i am using for the Contact form.

<?php
   if($submit) 
   {
   mail("psykogfx@psyko-gfx.com","$subject","$message","From: $name <$email>"); 
   }
?>
<form method="post" action="<?php echo("$php_self"); ?>">
   <p><strong>Name:</strong>       <input type="text" name="name">
      <br>
       <strong>Email:</strong>       <input type="text" name="email">
      <br>
       <strong>Subject:</strong>       <input type="text" name="subject">
       <strong><br>
  Message:</strong></p>
   <p>
       <textarea name="message" rows="10" cols="30"></textarea> 
      <br>
      <input type="submit" name="submit" value="Send">
      </p>
</form>


Please help me!

iPsyko

Edited by iPsyko, 25 September 2005 - 08:50 AM.


#2 dEcade

    P2L Staff

  • P2L Staff
  • PipPipPipPip
  • 1,850 posts
  • Gender:Male
  • Location:Saskatoon, Saskatchewan
  • Interests:Guitar, Programming, Storm Chasing, Games (Designing and playing), Hockey, Photography

Posted 25 September 2005 - 10:24 AM

Are you sure it should be

if($submit)
{

Maybe try

if($_POST)
{

Also for this

<?php echo("$php_self"); ?>

Try this

<?php echo '$PHP_SELF'; ?>

dEcade

Edited by dEcade, 25 September 2005 - 10:26 AM.


#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 25 September 2005 - 02:48 PM

Regarding decades post, it's a little bit safer/function to do
if($_POST['submit'])
Rather then just $_POST...

And from what i read on php.net, PHP_SELF, is not exactly the best thing to use (it depends on the circumstances), but most use REQUEST_URI (yes, I, not L). Also, the use of superglobals, is prefered over the method you're using, i.e.
<form method="post" action="<?=$_SERVER['PHP_SELF']; ?>">
And no, there's no echo... the way it is now should work, if not, you can add the echo yourself.
-----------------------------
Now, to get down to business... From what i can make out about your post, neither the conact form or the shoutbox is sending any data anywhere. What we need, is a little more info...
1. When you hit the send button, does anything happen.
2. Is the script ever making it to where it needs to go (i.e. is the contact form making it to the mail function.

To find an answer to number 2, simply go to the following part of your code, and add what i added
if($submit) 
  {
  die('Contact submitted, mail() not working'); // Added die()
  mail("psykogfx@psyko-gfx.com","$subject","$message","From: $name <$email>");
And do something similar to the shoutbox section of the code (make sure the message is different or you'll never get anything done).

#4 iPsyko

    Young Padawan

  • Members
  • Pip
  • 53 posts

Posted 25 September 2005 - 04:19 PM

Hey guys, thanks for your help thus far.

Here is my code as of now for the contact.php page. As you can see, i have changed the variables so that they don't conflict with the shoutboxes variables.

<?php
 if($submit)
 {
 die('Contact submitted, mail() not working'); // Added die()
 mail("psykogfx@psyko-gfx.com","$sub","$mess1","From: $name1 <$email1>");
?>
<form method="post" action="<?=$_SERVER['PHP_SELF']; ?>">
  <p><strong>Name:</strong>       <input type="text" name="name1">
     <br>
      <strong>Email:</strong>       <input type="text" name="email1">
     <br>
      <strong>Subject:</strong>       <input type="text" name="sub">
      <strong><br>
 Message:</strong></p>
  <p>
      <textarea name="mess1" rows="10" cols="30"></textarea>
     <br>
     <input type="submit" name="submit" value="Send">
     </p>
</form>

My contact form is still not working, instead of getting to the page, i am getting an error.

Parse error: parse error, unexpected $ in /home/psyko-gf/public_html/beta/contact.php on line 30

Why am i getting this error?

rc69, to answer your question, you are right, neither the shoutbox, or the contact form are giving off any information. After i hit submit on the contact page, the form clears, and nothing happens. Same with the shoutbox. Here is the Shoutbox code.

<?php
mysql_connect("localhost","---------","---------"); //change username and password with your mySQL username and password. you can leave the "localhost" part alone, as it is just a standard thing.
mysql_select_db("---------"); //change the given database name with the name of the sql database where the shoutbox will be (i.e. root_shoutbox)

if($_POST['submit'])
{
$time=date("M j, Y"); //will display date in format Jul 25, 2005. If you want to change it, check out php.net for more info.
$result=MYSQL_QUERY("INSERT INTO shoutbox (`id`,`name`,`email`,`time`,`message`)".
      "VALUES ('','$name','$email','$time','$message')");
}
$result = mysql_query("select * FROM shoutbox ORDER BY id desc limit 5");
while($r=mysql_fetch_array($result))
{  
$id=$r["id"];
$name=$r["name"];
$email=$r["email"];
$time=$r["time"];
$message=$r["message"];

echo ("
 <strong><a href=\"mailto:$email\">$name:</a></strong>
 <br />
 $time
 <hr />
 $message
 <br /><br />
");
}
?>
<form action="<?php echo("$php_self"); ?>" method="post">
Name:<br />
<input type="text" name="name" /><br />
Email:<br />
<input type="text" name="email" /><br />
Message:<br />
<input type="text" name="message" /><br />
<input name="submit" type="image" class="submit" src="images/login_button_go.gif" alt="Post shout!" width="24" height="14" />
</form>


Please help.
Thanks!

Edited by iPsyko, 25 September 2005 - 04:23 PM.


#5 iPsyko

    Young Padawan

  • Members
  • Pip
  • 53 posts

Posted 25 September 2005 - 05:14 PM

Nevermind guys, i got both to work, thanks alot. I had to change some things, but it all turned out nice. Thanks for all your help!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users