Forum Moderators: open
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?
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.
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.
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.
<?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.
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'");
So, I replaced this with
$query = mysql_query("SELECT * FROM tablename WHERE email = '$email'");
$name = $query->name;
$passwd = $query->passwd;
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