Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 02-10-2008, 07:33 PM   #1 (permalink)
Human Spambot
 
toofan's Avatar
 
Join Date: May 2008
Location: Haldwani(Nainital)
Posts: 2,124
Default Check this PHP code for error.


Quote:
<?php
if($_POST['submit'] == 'submit')
{
if(!$_POST['email'] || $_POST['email'] == "" || strlen ($_POST['email']) >30)
{
$message = "<p> Problem. Did you enter an email address?</p>";
}
else
{
//open connection to database
mysql_connect("localhost", "root", "abc123") or die ("Failur to communication to database");

mysql_select_db("test") or die ("problem connecting to db. " .mysql_error());
//Insert email address
$as_email = addslashes($_POST['email']);
$tr_email = trim($as_email);
$query = "insert into mailinglist (ID, Email, Source)
values (null, '$tr_email', 'www.example.com/newletter_signup.html')";
$result = mysql_query($query);
if(mysql_affected_rows() == 1)
{
echo "<p> Your information has been recorded.</p>";
$noform_var = 1;
}
else
{
error_log(mysql_error());
$message = "<p>Something went wrong with your signup attempt.</p>";
}
}


//show the form in every case except successful submission
if (!$noform_var) {
$thisfile = $_SERVER['PHP_SELF'];
$message .= <<< EOMSG
<P>Enter your email address and we will send you our weekly newsletter.</P>
<FORM METHOD="post" ACTION="$thisfile">
<INPUT TYPE="text" SIZE=25 NAME="email">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="submit">
</FORM>
EOMSG;
}

}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>email newsletter</title>
<style type="text/css">
<!--
body, p {
color:#000099;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12pt
}
H1 {
color:#990000;
font-family:Arial, Helvetica, sans-serif;
font-size:14pt
}
-->
</style>
</head>
<body>

<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="17%" bgcolor="#f0f8ff">&nbsp;</td>
<td width="83%" align="center" valign="top" bgcolor="#fffff0"><h1>News Letter SignUp Form</h1>
<?php echo $message; ?>
</td>
</tr>
</table>


</body>
</html>
Friends Help me to debug this code. I don't know whats wrong with this code. Acc to me their is some problem with the code marked with blue.

Thanks friends.
toofan is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 02-10-2008, 07:58 PM   #2 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Check this PHP code for error.

I'm not sure about interpolation in heredoc Means ...
Code:
 <FORM METHOD="post" ACTION="$thisfile">
Not sure that the value will be put here...
Check that !!
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 02-10-2008, 08:06 PM   #3 (permalink)
MMO Addict
 
amitava82's Avatar
 
Join Date: Jul 2004
Location: Bangalore
Posts: 1,474
Default Re: Check this PHP code for error.

PHP Code:
<?php
if($_POST['submit'])
{
if(!
$_POST['email'] || $_POST['email'] == "" || strlen ($_POST['email']) >30)
{
$message "<p> Problem. Did you enter an email address?</p>"
}
else 
{
//open connection to database
mysql_connect("localhost""root""abc123") or die ("Failur to communication to database");

mysql_select_db("test") or die ("problem connecting to db. " .mysql_error());
//Insert email address
$as_email addslashes($_POST['email']);
$tr_email trim($as_email);
$query "insert into mailinglist (ID, Email, Source)
values (null, '
$tr_email', 'www.example.com/newletter_signup.html')";
$result mysql_query($query);
if(
mysql_affected_rows() == 1)
{
echo 
"<p> Your information has been recorded.</p>";
$noform_var 1;
}
else 
{
error_log(mysql_error());
$message "<p>Something went wrong with your signup attempt.</p>";
}
}
}

//show the form in every case except successful submission
//if (!$noform_var) {
$thisfile $_SERVER['PHP_SELF'];
$message .= <<< EOMSG
<P>Enter your email address and we will send you our weekly newsletter.</P>
<FORM METHOD="post" ACTION="
$thisfile">
<INPUT TYPE="text" SIZE=25 NAME="email">
<BR><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="submit">
</FORM>
EOMSG;
//}

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>email newsletter</title>
<style type="text/css">
<!--
body, p {
color:#000099; 
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12pt
}
H1 {
color:#990000;
font-family:Arial, Helvetica, sans-serif;
font-size:14pt
}
-->
</style>
</head>
<body>

<table width="100%" border="0" cellspacing="0" cellpadding="10">
<tr>
<td width="17%" bgcolor="#f0f8ff">&nbsp;</td>
<td width="83%" align="center" valign="top" bgcolor="#fffff0"><h1>News Letter SignUp Form</h1>
<?php echo $message?>
</td>
</tr>
</table>


</body>
</html>
I think this is the correct code. Wrong placement of "}". Didn't check other stuffs though. Im in office now
__________________
Steam Profile || Personal Page
Warp drive active. Approaching stargate.
amitava82 is offline  
Old 02-10-2008, 08:45 PM   #4 (permalink)
Human Spambot
 
toofan's Avatar
 
Join Date: May 2008
Location: Haldwani(Nainital)
Posts: 2,124
Default Re: Check this PHP code for error.

@amitava82
Boss you are genius. Solved my problem in minutes. that's why i like this forum for having such an intelligent and helping peoples.
Now after the correction there is no need to change the following lines.

if ($_POST['submit'] == 'Submit') to
if($_POST['submit'])

no need to hide this line
if (!$noform_var) {

its working well after that editing "}" sign and adding one at the last if statement.

thanks dear. Now can you tell me one thing
what is the effect of these lines.
$as_email = addslashes($_POST['email']);
$tr_email = trim($as_email);
why we used addslashes and trime.
toofan is offline  
Old 02-10-2008, 08:52 PM   #5 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
Default Re: Check this PHP code for error.

lol... thats good...
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_
Garbage is offline  
Old 02-10-2008, 09:23 PM   #6 (permalink)
MMO Addict
 
amitava82's Avatar
 
Join Date: Jul 2004
Location: Bangalore
Posts: 1,474
Default Re: Check this PHP code for error.

Quote:
string addslashes ( string $str )

Returns a string with backslashes before characters that need to be quoted in database queries etc. These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte).

An example use of addslashes() is when you're entering data into a database. For example, to insert the name O'reilly into a database, you will need to escape it. Most databases do this with a \ which would mean O\'reilly. This would only be to get the data into the database, the extra \ will not be inserted. Having the PHP directive magic_quotes_sybase set to on will mean ' is instead escaped with another '.

The PHP directive magic_quotes_gpc is on by default, and it essentially runs addslashes() on all GET, POST, and COOKIE data. Do not use addslashes() on strings that have already been escaped with magic_quotes_gpc as you'll then do double escaping. The function get_magic_quotes_gpc() may come in handy for checking this.
So if you have get_magic_quotes_gpc() on then you don't need to do addslashes(). Check the database entry if you have slash in email ID. If yes then remove addslashes(). Too lazy to type..
__________________
Steam Profile || Personal Page
Warp drive active. Approaching stargate.
amitava82 is offline  
Old 02-10-2008, 10:36 PM   #7 (permalink)
हॉर्न ओके प्लीज़
 
victor_rambo's Avatar
 
Join Date: Sep 2007
Posts: 1,493
Default Re: Check this PHP code for error.

@Toofani,

Instead of posting the whole code, post the error. It hints us the likely location of error and we don't have to waste time reading the whole piece of code.

You will get error that look like:
Code:
Parse error: Unexpected T_VAR in /home/nai/scripts/contact.php on line 38
That helps us to hit the target more easily!
__________________
विक्टर रॅंबो - चाणकया प्रभावित व्यक्ति

गीक होना माँगता
victor_rambo is offline  
Old 02-10-2008, 11:01 PM   #8 (permalink)
MMO Addict
 
amitava82's Avatar
 
Join Date: Jul 2004
Location: Bangalore
Posts: 1,474
Default Re: Check this PHP code for error.

Unfortunately there are no errors in his code. Its just an issue with his if condition. Try running his code, you won't get any error.
__________________
Steam Profile || Personal Page
Warp drive active. Approaching stargate.
amitava82 is offline  
Old 03-10-2008, 06:53 AM   #9 (permalink)
Human Spambot
 
toofan's Avatar
 
Join Date: May 2008
Location: Haldwani(Nainital)
Posts: 2,124
Default Re: Check this PHP code for error.

@rohan_shenoy
If there will be any error next time and I can't solve it ,I will surely be posting it with code to check.

@amitava82
Thanks for your help dear.
Can you suggest me a good advance programming book in PHP.
And after PHP what should I learn to make myself something.
I already know HTML, JAVASCRIPT,MACROMEDIA FLASH,MACROMEDIA FIREWORKS, CSS,MySql, a bit of AJAX . tried learning XML but found it of no use and its very very confusing.
Can you guide me.
toofan is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find out the meaning of an Error Message or Error Code. anandk Software Q&A 7 27-06-2010 05:30 PM
.Bat file code error Ricks Programming 3 23-09-2008 05:26 PM
Code 10 error ! prashantmaxsteel Hardware Q&A 2 04-05-2008 12:13 AM
Splinter Cell:Double Agent Visual C++ runtime error and ***MUST CHECK*** error zerohourkill Gamerz 17 04-08-2007 02:47 PM
error code:0x80090006 sujeet2555 Software Q&A 3 12-01-2006 11:36 PM

 
Latest Threads
- by clinton
- by soumya
- by Sujeet
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 11:13 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2