I am very new to wordpress. I am trying to do the following:
a. I have a very simple html and php based website. I have a signup page which accepts user id and password and then on click of submit button it calls a php file which verifies the userid/password and saves it in the database. THIS WORKS PERFECTLY FINE
b. Now, I trying to move those two pages to wordpress platform. I have installed a php plugin also. Now the problem in wordpress platform is whenever I hit the submit button, in the database 3 duplicate records are getting appended. I have been trying a lot but could not fix this
c. I tried different php plugins but does not work
d. After reading few help documents on the web, I have tried creating my own template page, even that does not work
Any help in this regard will be much appreciated.
EDIT
Form:
<form action="http://xxxxxx.xxx/xxxxxx" method="post">
Enter User ID:
<input name="userid" type="text" value="" />Password:
<input name="password" type="text" value="" />
Confirm Password:
<input name="confrimpassword" type="text" value="" />
<input type="submit" value="SIGN UP" />
</form>
Below is the php file:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<body>
<?php
// Echo session variables that were set on previous page
//echo "Favorite color is ".$_SESSION["favcolor"].".<br>";
//echo "Favorite animal is ".$_SESSION["favanimal"].".";
?>
<?php
mysql_connect("localhost","***********","**************");
mysql_select_db("******");
$sql1=mysql_query("select * from login_details where customer_id='$_POST[userid]'");
$row=mysql_fetch_assoc($sql1);
if (!$sql1) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
//exit;
}
else {
echo " inside last else";
$sql2=mysql_query("INSERT INTO login_details VALUES ('$_POST[userid]','$_POST[password]')");
echo "Account successfully Created...";
}
mysql_close();
?>
</body>
</HTML>
Related
In a wordpress page I have a form where, after the pressure of submit botton, the same page is reloaded and it sends an email with the information in the form. The problem is that, as soon as I try to save the page, if in the php code there is a $_GET[],$_POST[] or $_REQUEST[] array, wordpress does not let me to save the changes, and the last code I wrote (those with $_variables) disappears. If I make an external php script and I call it in the wordpress page, I get "Internal Server Error" when I connect to the page.
I tried with two different php wp plugins, and I have the same problem in both.
Does anyone know why?
EDIT:
Here is an example of code I tried, it is the simpest example I found and it is still not working:
<?php
function test() {
echo $_POST["user"];
}
if (isset($_POST[])){ //If it is the first time, it does nothing
test();
}
?>
Here is the form:
<form action="" method="post">
<input type="text" name="user" placeholder="enter a text" />
<input type="submit" value="submit" onclick="test()" />
</form>
Anyway it is as if the wordpress parser recognizes the variables and refuses to save, if I wrote, for instance, only the following code `
<?php
$_GET[];
?>
it give me the same problem, but writing
<?php
$_HELLO[];
?>
though it returns error when I call the page in the browser (obviously considering that $_HELL does not exist), it let me save.
EDIT 2: Very strange, if I print all the post array with
`<?php
var_dump($_POST);
?>`
it works, and it prints "array(1) { ["user"]=> string(3) "123" }",
BUT IF I TRY TO ACCESS TO THE ELEMENT WITH THE KEY "USER" USING [] IT GIVES ME ERROR!
$_POST and $_GET are also work in wordpress too..
Remove the square bracket[ ] on $_POST, it will work.
<form action="" method="post">
<input type="text" name="user" placeholder="enter a text" />
<input type="submit" value="submit" onclick="test()" />
</form>
<?php
function test() {
echo $_POST["user"];
}
if (isset($_POST)){ //If it is the first time, it does nothing
test();
}
?>
Hope this will help you!!
so I've got the latest version of Xampp installed and in the htdocs directory I have an htm page containing a very simple form with just a single text field and a submit button which, when clicked, links to a php page that prints a message saying "What you typed is:" followed by what was typed. If nothing was actually typed in the field, after clicking on the submit button, the php page will display an error message saying "Error: you didn't type anything".
Here is the code for the htm page:
<html>
<head>
</head>
<body>
<center>
<form action="p1.php" method="post">
Type something:
<input type="text" name="nom">
<input type="submit" value="SEND">
</form>
</center>
</body>
</html>
And here is the initial code for the php page:
<html>
<head>
</head>
<body>
<?PHP
if (!$_POST) {echo "Error: you didn't type anything";}
else {echo "What you typed is: " . $_POST["nom"];}
?>
</body>
</html>
So with this php code, if I type anything in the field and click the submit button, the php page will display "What you typed is:" followed by what was typed but if I don't actually type anything in the field and click the submit button, the php page will display "What you typed is:" followed by nothing instead of displaying "Error: you didn't type anything".
However, I discovered that if I changed the "if (!$_POST)" to "if (!$_POST["nom"])", then if I didn't type anything in the field, the php page would display "Error: you didn't type anything"...problem solved.
But this surprised me, as I have seen in my course material an example (it is referred as a self-calling form or something along those lines) where "if (!$_POST)" is used.Here it is:
<html>
<head>
<title>Me llamo a mi mismo...</title>
</head>
<body>
<?
if (!$_POST){
?>
<form action="auto-llamada.php" method="post">
Nombre: <input type="text" name="nombre" size="30">
<br>
Empresa: <input type="text" name="empresa" size="30">
<br>
Telefono: <input type="text" name="telefono" size=14 value="+34 " >
<br>
<input type="submit" value="Enviar">
</form>
<?
}else{
echo "<br>Su nombre: " . $_POST["nombre"];
echo "<br>Su empresa: " . $_POST["empresa"];
echo "<br>Su Teléfono: " . $_POST["telefono"];
}
?>
</body>
</html>
So why isn't "if (!$_POST)" not working in my case? (using Mozilla as the browser)
when posting like this and having empty fields, it still gets saved as value.
var_dumping this
<form method="post" action="fgc.php">
<input type="text" name="horse">
<input type="submit">
</form>
will return:
array(1) { ["horse"]=> string(0) "" }
In PHP, the $_POST superglobal is always defined, regardless of whether or not the method was actually POST, or if any data was posted. However, if it isn't a POST, or if there is no data, that array will be empty.
If you convert an array to a boolean, the value will be false if there are no elements in the array.
<?php
var_dump(isset($_POST)); // Always TRUE
var_dump(!!$_POST); // TRUE if data was posted (even if empty fields), FALSE otherwise
The reason your documentation says to use !$_POST is that often times the page will be loaded with the GET method, in which case, $_POST will be an empty array.
try this code
if($_SERVER['REQUEST_METHOD'] == 'POST'){ // if the form was submitted
if(isset($_POST['name']) && !empty($_POST['name'])){ // basic validation
// # Don't forget XSS sanitizing !
$name = htmlspecialchars($_POST['name']);
// Add data to DB or something
}else{
echo 'Error: Required field "name"';
}
}
I feel i am missing a crucial link in my design and i was hoping some fine programmer could fill me in (this is not really my field of experience)
What I have
page - form.html
<div style="text-align:left">
<form action="addtoserver.php" method="post">
Server Name: <input type="text" name="servername"><br>
<br>
Server Address: <input type="text" name="serveraddress"><br>
<br>
Port Number: <input type="text" name="portnumber"><br>
<br>
Server Description :<TEXTAREA NAME="description" ROWS=3 COLS=30 ></TEXTAREA>
<br>
<input name="Submit" type="submit" value="Add Server" />
</form>
<div style="text-align:left">
page - addtoserver.php
<html>
<body>
Server Name :<?php echo $_POST["servername"]; ?><br>
<br>
Server Address : <?php echo $_POST["serveraddress"]; ?><br>
<br>
Port Number : <?php echo $_POST["portnumber"]; ?><br>
<br>
Server Description : <?php echo $_POST["description"]; ?><br>
<?php
$ip = $_POST['serveraddress'];
$port = $_POST['portnumber'];
if (!$socket = #fsockopen($ip, $port, $errno, $errstr, 30))
{
echo "<centre><font color='red'><strong>Server Is Offline!</strong></font></center>";
}
else
{
echo "<centre><font color='green'><strong>Server Is Online!</strong></font></centre>";
fclose($socket);
}
?>
</body>
</html>
Everything is all gravy
Purpose
I designed this for the purpose of my website a user will click a link "Add server" and will be directed to the form page, they will fill out the form page and once submitted be directed to the addserver.php page.
On this page i wont the post to pertinently stay there and the next user to to come in and add his server and for that post to be listed underneath.
My Dilemma
I am not sure what the next step is to take, would i have to add the users input to Mysql and then export it from Mysql to the page or is there another way. would i have to rite a PHP script in order to get the posts to come in one after the other if imported from the data base.
I am not sure what the next step is to take, would i have to add the users input to Mysql and then export it from Mysql to the page?
If you require persistent data then you'll sure need some static storage such as a database or a XML file. In both way, yes you want to store the user input into it (make sure you fully understand the security need behind such an action) and then retrieve it from there.
This is just a project for my own learning purposes. For my project, users will be able to create polls and answer them. Each survey will have its own unique ID and can be accessed by its unique URL.
My problem is this. I know I can get around doing it this way, but this is a learning experience. When the user submits this form:
<form name="createPoll" action="polls.php" method="post">
Poll Title: <input name="pollTitle" type="text" /><br />
Option 1: <input name="pollOption" type="text" /><br />
Option 2: <input name="pollOption" type="text" /><br />
<input type="submit" value ="Submit Poll" /><br />
</form>
I want to run a script that will add this to my MySQL database and use the pollID that this script will generate for the URL like this:
http://www.mydomainname.com/polls.php?pollID=12345
where "12345" is the unique ID of the poll. My question is this:
What is the best way to bring the user to http://www.mydomainname.com/polls.php?pollID=12345 (assuming that the generated pollID will be '12345') on the submission of my form? Do I have to set the header in php in order to redirect them once the script has created the unique pollID?
Thanks
By the way: There is two inputs named "pollOption", be carefull :)
Your INSERT codes may be like that
$id=rand(100000,9999999999999999);
$checkid=mysql_query("SELECT ID FROM ID WHERE ID='$id'");
$checkidx=mysql_fetch_array($checkid);
if($_POST and $checkidx==null){
$title=$_POST['pollTitle'];
$opt1=$_POST['pollOption1'];
$opt2=$_POST['pollOption2'];
$insert=mysql_query("INSERT INTO ID,title,option1,option2 VALUES ('$id','$title','$opt1','$opt2')");
echo "Added! You re redirecting";
?>
<meta http-equiv="refresh" content="2;URL=http://www.mydomainname.com/polls.php?pollID=<?echo $id; ?>">
<?
}
And your polls.php may be like that;
$id=$_GET['id'];
if($id!=null){
$idget=mysql_query("SELECT * FROM blabla WHERE ID='$id'");
$idgetx=mysql_fetch_array($idget);
echo $idgetx[0] . $idgetx[1];
}
Generate the url, then use header() to redirect the page.
e.g.:
$id = 12345;
$url = 'http://www.mydomainname.com/polls.php?pollID=' . $id;
header('Location: ' . $url);
hey guys i want to creat my own form in joomla and use the post method .
so i download extension to make my own code in articles in joomla like this
<form action="http://localhost/ocr/includes/Create_Subject.php" method="post">
username <input type="text" name="menu_name" value=""/><br/>
password <input type="text" name="id" value=""/><br/>
<input type="submit" name="save" value="Submit" />
</form>
and then i go to my website data base and create a table called show to add into it my values which i get it from my form and also
make a php file called (Create_Subject.php) and i put it in includes file in my website and called it by action like u see in my code in my html and the code of that php here
<?php
$coonect=mysql_connect("localhost","root","");
if(!$coonect){
echo "Data_base error";
die(mysql_error());
}
?>
<?php
$username=$_POST['menu_name'];
$id=$_POST['id'];
$db_select=mysql_select_db("ocr");
if(!$db_select){
die(mysql_error());
echo" error";
}
$query= "INSERT INTO show (
name , id )
VALUES( '{$username}' ,{$id} ) " ;
if(mysql_query($query)){
header("www.google.com");
exit;
}else{
echo"<p> error </p>";
}
?>
`
and when iam run the site show to my an error what am doing wrong any heleeeep plez ....:))
Here you can find plenty of information about SQLQuering with Joomla!
http://docs.joomla.org/Accessing_the_database_using_JDatabase
You can ask anything you want if you have any trouble...