|
Thank you dude for your response ...... I am gonna try it ....but
Marc Firth wrote:
@ this line I already have another class ..... so how can I have both classes @ the same time? ...thank you AGIAN
|
|
|
|
|
I presume so. Not really sure what you mean TBH. You could post code so I can see what you mean.
|
|
|
|
|
Don't forget you need to download jquery to try my example.
|
|
|
|
|
why ? ...and what is jquery? ... doesnt it work just by placing it before the body?
|
|
|
|
|
http://jquery.com/[^]
You need to include jquery:
jquery is a javascript library that makes writing javascript easier. download it and include it.
|
|
|
|
|
Ok. got it... if i 've any trouble i will ask you.
Thank you
|
|
|
|
|
I post this 2 questions on web development forum.............I thought if it might be the wrong place ..... so I just put it here ..... here are the questions
Can any body tell me how to send an email to some fixed email address(i.e to the owner of the site) just by collecting message and email address of the sender?
and the other question is
I am developing web page for some music production. What I wanted to ask is, there are a lot of links for a lot of lyrics. If I put the lyrics with their file name and when the user presses the link it reads the file and displays on a new page. But this is really bad(too slow). So I decided to do like CODEPROJECT's site did. i.e when we click one question(or answer) on a thread it display the message @ that page with in a fraction of mili second. So can any body help me how to do that so that I can display the lyrics next to the song as CodeProject's thread did?
I hope I will get some help soon. Thank you
|
|
|
|
|
Hey,
Sending an Email in PHP is rather simple. If you want a user to send an email, design and create a form with the appropriate fields (reply email address, email address subject, email address message/content). Then, when the form is submitted (I use post) you can apply validation and process the email (Regular expressions are useful for the email address, make sure you filter empty fields as well).
An email can then be sent like this:
$To = "webmaster@example-site.com";
$Headers = 'From:' . "<" . $frmEmail . ">" . "\r\n";
$Subject = 'Subject: '.$frmSubject;
$Message = 'Message: '.$frmMessage;
if(mail($To, $Subject, $Message, $Headers))
{
echo "Message Sent!";
}
else
{
echo "Error sending message!";
}
I suggest you use reCaptcha to guard your form (this system can be exploited easily). Also, you might want to pad the input using "\n" ...
I am not quite sure what you are requesting in regards to the music production system but a database driven website seems to be in order.
Regards,
- Calvin
http://www.calvinhartwell.com
|
|
|
|
|
Thankk you ma friend I will try it that ..... but how do i know it reaches to the person before posting the site? ... is there any mechanism to know that?
Thank you agian.
|
|
|
|
|
Hello everybody
I'm searching for a way to get information(name,author,...) out of a documeny(like docx,exc,zip,...)
Does anybody has an idea how i can accomplish this?
Greetz
|
|
|
|
|
|
How can i insert the current system date into MSSQL database using formview in asp.net
|
|
|
|
|
Artakazezs wrote: into MSSQL database using formview in asp.net
with PHP?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
If you managed to find the PHP forum how the hell did you miss the ASP.NET forum? That makes absolutely no sense.
|
|
|
|
|
hi everybody,
Im new with php, started recently, Im making a registration form for my website and here is the problem. I try to check if email address entered isn't already in use. here is the code Im using:
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$name = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$nickname = $_POST['nickname'];
$password = md5($_POST['password']);
$checkuser = mysql_query("SELECT email FROM users WHERE email='$email'");
$username_exist = mysql_num_rows($checkuser);
if($username_exist > 0){
die('{status:0,txt:"This email address is already registered"}');
unset($email);
include 'register.html';
exit();
$query = "INSERT INTO users (name, lname, email, nickname, password)
VALUES('$name', '$lname', '$email', '$nickname', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();
echo "You have successfully Registered";
It does the job, doesnt send data to database if email is registered, but it allways displays error message
{status:0,txt:"This email address is already registered"}, and don't output message that you have been registered. If email address is unique it creates a record in a database, but displays error and doesnt redirect. Its probably something simple, but I cant figure out by my self. Anyone any ideas?
By the way my form includes jQuery and few functions if it makes any difference.
thanx in advance
|
|
|
|
|
wartotojas wrote: die('{status: 0,txt:"This email address is already registered"}');
The die function stops the process from running, so every thing after die is not executed.
wartotojas wrote:
if($username_exist > 0){
die('{status:0,txt:"This email address is already registered"}');
unset($email);
include 'register.html';
exit();
$query = "INSERT INTO users (name, lname, email, nickname, password)
VALUES('$name', '$lname', '$email', '$nickname', '$password')";
mysql_query($query) or die(mysql_error());
mysql_close();
echo "You have successfully Registered";
Why are you using die and exit? Where is the if tag closed? I can see the curly bracket open, but not close.
This should work. Notice that I dont use die or exit (apart from if the query fails):
if ( $username_exist > 0 )
{
mysql_close();
echo 'Email already registered';
include( 'register.html' );
}
else
{
$query = "INSERT INTO users (name, lname, email, nickname, password)
VALUES('$name', '$lname', '$email', '$nickname', '$password')";
mysql_query( $query ) or die( mysql_error() );
mysql_close();
echo "You have successfully Registered";
}
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I used die function few times, and it doesnt kill all process.
here is full php code Im using :
<?php
if(empty($_POST['fname']) || empty($_POST['lname']) || empty($_POST['email']) || empty($_POST['nickname']) || empty($_POST['pass']))
{
die('{status:0,txt:"All the fields are required"}');
}
if(!(preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $_POST['email'])))
{
die('{status:0,txt:"You haven\'t provided a valid email"}');
}
$dbhost = "localhost";
$dbname = "register";
$dbuser = "*******";
$dbpass = "******";
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$name = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$nickname = $_POST['nickname'];
$password = md5($_POST['password']);
$checkuser = mysql_query("SELECT email FROM users WHERE email='$email'");
$username_exist = mysql_num_rows($checkuser);
if ( $username_exist > 0 ){
mysql_close();
echo 'Email already registered';
include( 'members.php' );
}
else{
$query = "INSERT INTO users (name, lname, email, nickname, password)
VALUES('$name', '$lname', '$email', '$nickname', '$password')";
mysql_query( $query) or die( mysql_error() );
mysql_close();
echo "You have successfully Registered";
}
?>
It is still doesnt work. I used die('{status:0,txt:"You haven\'t provided a valid email"}'); to display error message in error box, before you are redirected, I tought it will work instead of echo statment and it is working with first few fields. Like I said before records are created in database in the way they are supposed to, the only thing is that error message I want to make for email validation. Any suggestion about that, and this might sound realy dumb, but how do I make that after registration and clicking submit button users would be redirected to other page, lets say "members.php"?
thanks for answers and any help
|
|
|
|
|
wartotojas wrote: I tought it will work instead of echo statment
No, read some documentation: php.net[^] W3Schools[^].
wartotojas wrote: It is still doesnt work
Ok. Here is a basic example of how you should do it.
<?php
if ( isset( $_POST[ 'submit' ] )
{
if ( isset( $_POST[ 'name' ] ) && isset( $_POST[ 'age' ] ) )
{
if ( strlen( $_POST[ 'name' ] ) > 0 && strlen( $_POST[ 'age' ] ) > 0 )
{
if ( *something* )
{
header( 'Location: redirect.php' );
exit();
}
else
$result = 'Something went wrong!';
}
else
$result = 'You must fill in name AND age.';
}
else
$result = 'Name and age are not set';
}
?>
<html>
<head>
...
</head>
<body>
...
<!-- Output the result, if one is set. -->
<?php echo $result; ?>
<form action="" method="post">
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" name="submit" />
</form
...
</body>
</html>
Notice that the form is processed before anything is output, therefore you can redirect.
To redirect to another page use header( 'Location: members.php' ); . This can only be used before you have output anything to the browser.
Example:
This will work
header( 'Location: members.php' );
echo 'This won\'t be output as it the page will have been redirected.';
This won't work
echo 'This has been output, therefore headers cannot be set.';
header( 'Location: members.php' );
The exit() function is normally used after a redirect.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I always include the form processing at the top to the same page and allow the logic to either load a successful registration page on success or reload the same page with errors marked in the form.
The general form is
<?php
$name_good = true;
if(isset($_POST['reg'])
{
if(isset($_POST['name']))
{
$name = htmlspecialchars($_POST['name'],ENT_QUOTES);
}
else
{
$name = "";
}
if(strlen($name)>0)
{
if( )
{
header("location: http://www.sitename.com/welcome.php');
}
else
{
$name_good = false;
}
}
}
$pg = "<html>\n";
$pg.= "<head>\n";
$pg.= " <title>Register</title>\n";
$pg.= "</head>\n";
$pg.= "<body>\n";
$pg.= "<form action='' method='post'>\n";
$pg.= "Name: <input type='text' name='name'";
if($name_good)
{
$pg.= " class='field_good' title='enter your name' ";
}
else
{
$pg.= " class='field_bad' title='name is in use' ";
}
$pg.= ">\n";
$pg.= "<input type='submit' name='reg' value='Join Now!'>\n";
$pg.= "</form>\n";
$pg.= "</body>\n";
$pg.= "</html>\n";
print $pg;
?>
I often leave the action empty as it will default to the same page.
Hope this helps
|
|
|
|
|
Why do I need to know this?
cjoki wrote: $pg = "\n";
$pg.= "\n";
$pg.= " <title>Register\n";
$pg.= "\n";
$pg.= "\n";
$pg.= "\n";
$pg.= "Name:
Why are you assigning it to a variable? It's quicker just to output it directly onto the screen.
<head>
<title>Register</title>
</head>
<body>
<form action="" method="post">
Name: <input type="text" name="name"
<?
echo ($name_good) ? ' class="field_good" title="enter your name" ' : ' class="field_bad" title="name is in use" ';
?>
>
<input type="submit" name="reg" value="Join Now!">
</form>
</body>
</html>
Also use ' to encapsulate strings as they are quicker than ", as " marks compile the string to check for variables, hence why they are slower.
I suggest you look into using a template engine, such as Smarty[^], to format your pages.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I have used this style for some time and it works fine and gives me better control over the output. With echo once something is echoed its gone to the browser.
Any performance hits from the quote style has never been an issue. Also its just habit, I generally write much bigger forms that have variables worked into the HTML output...and why are you asking me to look into a template system when your concern is performance?
As for smarty...or any other template engine...why bother? PHP IS my template engine. This style of code allows me to separate PHP and HTML from css and js. That allows me to write large scripts and maintain complete control over the source and keep it clean and easy to read, and thus maintain.
Template engines just add another layer that IMHO is not needed and does little more than complicate a design and add to the learning.
modified on Monday, October 12, 2009 2:08 PM
|
|
|
|
|
cjoki wrote: This style of code allows me to separate PHP and HTML from css and js.
How is $pg = "<html>\n"; separating the two? You include the HTML IN your PHP.
CSS and JS can be separated from HTML into several separate files (using the link tags and the script src attribute, respectively), rather than being scripted in, so to say. I prefer having separate files. When separating JS and CSS there are always certain bits which have to overlap such ass the class attributes. Smarty does the same for PHP and HTML.
This is a very basic example of using Smarty.
index.php
<?
include('Smarty.class.php');
$Smarty = new Smarty();
$Smarty->assign( 'message' , 'Smarty Rocks!!!' );
$Smarty->display( 'index.tpl' );
?>
index.tpl
<html>
<head>
<title>Smarty Example</title>
</head>
<body>
{$message}
</body>
</html>
cjoki wrote: Template engines just add another layer that IMHO is not needed and does little more than complicate a design and add to the learning.
After looking at the above code, you can't say that it's not insanely simple.
cjoki wrote: and why are you asking me to look into a template system when your concern is performance?
Quite simply, I don't actually do the website design (I'm colour blind), I just worry about the functionality. The designer I hire designs the site and then writes the HTML and CSS and leaves me to do all the JS and server side, without having to get in my way. So if he wants to redesign the site then he just changes the templates, rather than having to troll through my PHP code, the same could be said if I want to redo the back-end of the site.
Have a read of this[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I could have stated this better, but I meant php and html, then js, and then css are seperated and controlled by code logic.
I do entire projects, including layout and design, programing and db design. I have no need to separate the page further, than is needed by css and js, or even to keep the code more manageable.
Also if you know php you can easily maintain my code. There is no need to learn additional language rules required by a template engine.
My file structure is also way more simplistic than a template engine. I do not have to hunt a templates code to find where they buried a code fragment.
...and I counter your simple smarty code with an even simpler php code that only requires 1 file and will run..much...much faster!
<?php
$msg = "Smarty What...?";
echo "<html>";
echo "<head>";
echo " <title>PHP Example</title>";
echo "</head>";
echo "<body>";
echo "<h1>".$msg."</h1>";
echo "</body>";
echo "</html>";
?>
I sure we can go tit for tat, but this has gone way of topic from the original post. My reply was not meant to start a flame war, but to offer another option to the author.
|
|
|
|
|
I'm sorry, but I only echoed the variable, NOT the rest.
<?
$msg = 'Smarty is cool';
?>
<html>
<head>
<title>PHP Example</title>
</head>
<body>
<h1><? echo $msg; ?></h1>
<!-- OR -->
<h1><?=$msg?></h1>
<!-- If you have quick echoing enabled -->
</body>
</html>
No unnecessary processing wasted by unnecessary echoing, holding all the output in memory or wasted time compiling strings using " instead of '. Which is what I said in the first place.
Template engines generate it all for you, quite efficiently. They are only sluggish when compiling a template for the first time. I have to admit that it did take me a very long time (almost 5 years) to convert.
cjoki wrote: My file structure is also way more simplistic than a template engine. I do not have to hunt a templates code to find where they buried a code fragment.
Using the template engine doesn't make my file system any more complicated:
/
classes/
logs/
smarty/
templates/
templates_c/
htdocs/
css/
js/
img/
Enough of the flame war. I call a truce, apologies.
cjoki wrote: With echo once something is echoed its gone to the browser.
Have a look at Output Buffering[^]. It's quicker than both of our methods. I was going to talk about it when talking about the header redirection, but it's too advanced for what he is doing.
I'm thinking about writing a couple of articles (when I have time) about OOP in PHP. It'll be more appropriate to continue the discussion then.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I never write broken HTML, large projects to easily become a mess to read. And honestly I have never had an issue with performance. But I would be interested in your article when it is ready...
I am familiar with Output Buffering, but have not used it all that much, although maybe I should.
Currently I am updating my js knowledge to the current standards of code separation...(i.e.: removing things like ...to and js adding the event logic at the end page load.).
I am also contemplating an issue of external (multiple) css file loads vs style tags with css loaded based on page need using php code logic. I suspect in projects with a large number css rules can be refined to reduce the file size (sent to the browser) by send only the needed rules without the need for a larger number of file reads (split css files). But this flies in the face of separation of style from html...and I need to test, well I first need to figure out how I could test.
All the best
cjoki
modified on Monday, October 12, 2009 5:12 PM
|
|
|
|
|