Forum Moderators: open

Message Too Old, No Replies

Simple User Signup

Also, linking it to the HTML Page

         

anand84

9:56 am on Jan 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am designing a new site for which I need to get the email ids of my visitors. I know the commands to create a new database, insert a new entry and so on. I would like to know how and where I should insert this commands so that when the user enters the data and presses SUBMIT, his name and email id is entered into my table. In short, how should I merge the MySql commands to my HTML page.

coopster

12:50 am on Jan 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You use a server-side language to *build* your statements based on the data provided. Part of that building process includes editing and verifying the data is what you expect, such as a valid email address.

anand84

3:46 pm on Jan 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My doubt is I use form statement's Method = Post in the signup form and then Method = Get in the form that I need to display after the user clicks on the submit. As of now, I do not intend to perform checks and validation because that will trouble my already 'weak in programming' brain.

So the next step naturally is inserting the
" Insert into table..." MySql command to insert the text field so obtained. However I fail to understand how I can suddenly include a MySql statement. If this page requires to be written in Php instead(since you say we require a server-side script), how do I insert the MySql statement here?

coopster

5:49 pm on Jan 9, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How are you processing your form data today? Or perhaps you aren't processing form data yet ...

Using a server-side language you would accept the posted form values and build a query statement string, just as if you were going to key the statement into a command line. Next, you use the server-side processing program to connect to your database server and execute the query.

anand84

3:31 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was just going through some websites teaching php+mysql programming.

I have one doubt. Now after I POST to send my 'email' variable and then in the destination HTML Page, I use GET. Will this work


$email1 = $_Request['email']
$query = "Insert into Tablename ('Emailfield') Values('$email1')";
mysql_query($query);

Please assume that I have inserted the necessary commands for connecting to the database,etc. My main doubt in the above statement is the _Requestcommand.

anand84

3:33 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have missed a ';' after the _Request line. Sorry for that.

anand84

3:56 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am having some difficulties in getting the value from the form.

To make things simple, I have made two simpler files to know what is the mistake I'm making. In the testsource.php, I have the following code


<html>
<body>
<form action="/testdes.php" method="post">
<input type="text" name="email" value="Your Email Address" onfocus="value=''">
<input type="submit" value="Subscribe!">
</form>
</body>
</html>

And in the destination testdes.php, I have


<html>
<body>

<?php
$email = $_Request['email'];

?>
Email is <?php
echo($email);
?>
</body>
</html>

Can you let me know, what mistake I'm doing, since I only get "Email is" in the destination file.

Also, another problem I sometime get when I was trying out is that I cannot use POST method for this. Can you please clarify on this also?

PS:Mod, Sorry that my topic has wavered from Databases to the PHP side.

stu_uk

8:15 pm on Jan 11, 2006 (gmt 0)

10+ Year Member



instead of using $request['email']

try using

$email=$_POST['email'];

anand84

2:24 pm on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That was awesome Stuart..Thanks for the info..This current sample program is now working fine. Let me now try the database part of it and come back.

By the way, for just my info.when should I have used the _Request command then?

stu_uk

7:24 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



$_REQUEST has superseeded $_POST and $_GET but some older versions of php don't support $_REQUEST

anand84

8:25 am on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Now, I have been facing some problem in the actual site code. The code is as follows.


<?php
$email = $_POST['email'];
$host = "localhost";
$username = "a";
$password = "b";
$database = "c";
$server = mysql_connect( $host, $username, $password )
or die( "1.Error! Could not connect to database: " . mysql_error() );

mysql_select_db( $database, $server )
or die( "2.Error! Could not select the database: " . mysql_error() );
mysql_query("INSERT INTO MEMBERS
('email') VALUES(<?php $email?>)" )
or die("3." . mysql_error());
?>
Thanks <?php $email;?>,
You have been added to our Preferred Members list.

I think the 1. and 2. part of the mysql commands have worked because I get the "3." error. I actually got an error that the program was encountering an unexpected?. So, I removed the double quotes that I initially enclosed around the VALUES part of my INSERT command.

ie, VALUES("<?php $email?>") has now become VALUES(<?php $email?>).

But still I get an error that


3.You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''email') VALUES()' at line 2

I cannot understand what my mistake is. Can you please help me out.

percentages

8:30 am on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



> In short, how should I merge the MySql commands to my HTML page.

In short you need need to learn PHP. The post above this one helped you most ;)

anand84

1:42 pm on Jan 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have rectified my mistake..Thanks everyone..Shall get back to this thread incase I face problems on similar issues..

anand84

5:19 pm on Jan 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want to use a mail function, but have some problem with embedding the mysql commands.

First, I had my commands as


$name = mysql_query("SELECT name FROM tablename WHERE email = '$email'");
$passwd = mysql_query("SELECT passwd FROM tablename WHERE email = '$email'");

For this, the mail was indeed sent but instead of the expected 'Hi Robert',I got something like 'Hi Resource id##5', and a similar Resource id for the passwd.

So, I replaced this with


$query = mysql_query("SELECT * FROM tablename WHERE email = '$email'");
$name = $query->name;
$passwd = $query->passwd;

This time, both the places got substituted with null values. So I simply got 'Hi ,'.

Can somebody help me out.
PS: I dont think there is any error with the syntaxes as I had already corrected some instances of parse errors. Thanks

anand84

2:32 pm on Jan 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm waiting..Please any inputs.