Only else statement is executing - php

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'moviefone';
$con = mysql_connect($dbhost, $dbuser, $dbpass) or die ('can not connect to the database');
mysql_select_db($dbname, $con);
if (!empty($_POST['usernamesignup']) && !empty ($_POST['emailsignup']) && !empty($_POST['passwordsignup'])
&& !empty($_POST['passwordsignup']) && !empty($_POST['passwordsignup_confirm']))
{
$email = $_POST['emailsignup'];
$username = $_POST['usernamesignup'];
$password = $_POST['passwordsignup'];
$sql ="INSERT INTO users (email,username, password) VALUES ('$email', $username','$password')";
$result = mysql_query($sql);
if ($result) {
echo "you have registered successfully";
}
else {
echo "there was a problem";
}
}
else {
echo "Please confirm your information";
}
?>
Here's html code
<div id="register" class="animate form">
<form action="signup_ac.php" autocomplete="on" method="POST">
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Your username</label>
<input id="usernamesignup" name="usernamesignup" required type="text" placeholder="mysuperusername690" />
</p>
<p>
<label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
<input id="emailsignup" name="emailsignup" required type="email" placeholder="mysupermail#mail.com"/>
</p>
<p>
<label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
<input id="passwordsignup" name="passwordsignup" required type="password" placeholder="eg. X8df!90EO"/>
</p>
<p>
<label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label>
<input id="passwordsignup_confirm" name="passwordsignup_confirm" required type="password" placeholder="eg. X8df!90EO"/>
</p>
<p class="signin button">
<input type="submit" value="Sign up"/>
</p>
<p class="change_link">
Already a member ?
Go and log in
</p>
</form>
</div>
I have made a simple registration form to test if its working.But when I try to open registration.php it only displays please confirm your information.there are two page for html registration.php and for php signup_ac.php. I do not understand why.If the problem is with my php then it should display the form I think .

You need to learn to debug your code:
if [...snip...] $POST_['passwordsignup_confirm'])){
^^^^^--- dyslexic moment?

Related

Why can't I enter the data into the database even though the codes are correct and no error appear?

There is no change and no response in the form or in the database. I believe
the code is okay as no error appears and I included the connect database pdo. The connection is okay, and I changed the position of code to be above the form and under form but still no response. I connected correctly.
I separated the php page but it did not help.
Where is the problem in this code ?
Summary of the problem:
1-no response or error message
2- data not inserted into database
connection database:
<?php
$dsn ='mysql:host=localhost;dbname=person';
$user ='root';
$pass = "";
$option = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES UTF8",);
try{
$pdo = new PDO($dsn, $user , $pass, $option);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);}
catch(PDOException $e){
die("ERROR: Could not connect. " . $e->getMessage()); }
and form of html:
<div class="container">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method=" POST">
<label for="fname"> الاسم </label><br>
<input type=" text" id="fname" name="username" placeholder=" الاسم"><br>
<label for="email"> البريد الالكتروني </label><br>
<input type="email" id="email" name="email" placeholder="البريد الالكتروني "><br>
<label for="valley"> اسم الحي </label><br>
<input type="text" id="valley" name="valley" placeholder="اسم الحي "><br>
<label for="phone"> رقم الجوال</label><br>
<input type="text" id="phone" name="mobile" placeholder="رقم الجوال "><br>
<label for="subject">الطلب</label><br>
<textarea id="subject" name="subj" placeholder="اكتب الطلب " style="height:200px">
</textarea><br>
<input type="submit" name="submit" value="ارسل">
</form>
</div>
<br>
php and query insertion to database
<?php
include('connect_pdo.php');
if (isset($_post['submit'])) {
$name = $_POST['username'];
$email = $_POST['email'];
$valley = $_POST['valley'];
$phone = $_POST['mobile'];
$subject = $_POST['subj'];
$stmt = $pdo->prepare("INSERT INTO emails (username,email,valley,mobile,subj)
VALUES('$name','$email','$valley','$phone' ,'$subject')");
if ($stmt->execute()) {
echo "تم الارسال بنجاح";}
else {
echo "تم الارسال" } }

Why I cannot insert data into database

<?php
session_start();
$host = "localhost";
$user = "root";
$password = "";
$database = "tuition";
$conn = mysqli_connect($host, $user, $password, $database);
?>
<div role="tabpanel" class="tab-pane fade in" id="sign_up">
<form action="" method="post">
<input type="text" class="form-control" name="register_name" placeholder="Name" required />
<input type="text" class="form-control" name="register_ic" placeholder="IC" required />
<input type="telephone" class="form-control" name="register_phone" placeholder="Telephone" required />
<input type="email" class="form-control" name="register_email" placeholder="Email" required />
<input type="password" class="form-control" name="register_password" placeholder="Password" required />
<input type="submit" class="form-control" name="register_btn" value="Sign up" />
</form>
</div>
<?php
if(isset($_POST['register_btn'])){
$name = $_POST['register_name'];
$ic = $_POST['register_ic'];
$phone = $_POST['register_phone'];
$email = $_POST['register_email'];
$password = md5($_POST['register_password']);
$result = mysqli_query($conn,"select parent.parent_ic from parent where parent_ic ='$ic'");
if(mysqli_num_rows($result)!=1){
mysqli_query($conn,"insert into parent(parent_name,parent_ic,parent_email,parent_contact_num,parent_password) values ('$name','$ic','$email','$phone','$password')");
?>
<script type="text/javascript">
alert("success");
</script>
<?php
}
else{
?>
<script type="text/javascript">
alert("fail");
</script>
<?php
}
}
?>
It coming out with alert success, but it do not insert the data into the database.But when I hard code insert the data into the database it work! Why?
Here is the result after I click submit button:
You should see by printing error after insert data query
echo("Error description: " . mysqli_error($conn));
I think your MySQL error will be there.

How to get a logged in user account data including memberID so user can edit or delete their account?

I have a member page that lands after user signs in. From there I need to populate that page with all their data in a form format (same as the one they filled out initially) so they can edit and update/save.
<form>
<fieldset>
<legend>Edit My Account
</legend>
<div>
<label class="label" for="username">Username</label>
<input class="user" type="text" name="username" id="username" value="<?php if(isset($error)){ echo $_POST['username']; } ?>" tabindex="2" required />
</div>
<div>
<label class="label" for="email">Email</label>
<input class="email" type="email" name="email" id="email" value="<?php if(isset($error)){ echo $_POST['email']; } ?>" tabindex="3" required />
</div>
<div>
<label class="label" for="password">Password</label>
<input class="password" type="password" name="password" id="password" tabindex="4" required />
</div>
<div>
<label class="label" for="passwordConfirm">Confirm Password</label>
<input class="password" type="password" name="passwordConfirm" id="passwordConfirm" tabindex="5" required />
</div>
<div>
<input class="showbox" type="checkbox" name="terms" id="terms" tabindex="6" onFocus="this.tabIndex=1;"onBlur="this.tabIndex=6;"required />
<label for="terms">I agree to the Terms</label>
</div>
</fieldset>
<fieldset>
<div>
<input name="submit" type="submit" value="Update" />
</div>
</fieldset>
</form>
Secondly I want them to be able to delete their entire account with a "Delete My Account" button via a input type 'submit' that would appear on same member page.
<fieldset>
<form action="delete.php?" method="post">
<input type="hidden" name="id" value="<?php echo $members['memberID']; ?>">
<input type="submit" name="submit" value="Delete My Account">
</form>
</filedset>
I've been searching for days now... mostly this platform and have not found any sound solution(s).
I'm using MySQL db using PDO $stmt = $db->prepare('INSERT INTO... to create insert for new users and that all works fine.
I include a separate connection config file for db connection as well.
I created a delete.php file for the statement.
<?php require('config.php');
$id=$_SESSION['memberID'];
$stmt = $db->prepare('DELETE FROM members where memberID = $id');
?>
I'm not able to find a solution to populate the member page with logged in user data then edit and update it and/or capture the users logged in memberID to submit the delete account request using that memberID.
Some guidance would be appreciated, Thanks!
Here is my login.php code
<?php
//include config
require_once('config.php');
//check if already logged in move to home page
if( $user->is_logged_in() ){ header('Location: memberpage.php'); }
//process login form if submitted
if(isset($_POST['submit'])){
$username = $_POST['username'];
$password = $_POST['password'];
if($user->login($username,$password)){
$_SESSION['username'] = $username;
header('Location: memberpage.php');
exit;
} else {
$error[] = '<h2 class="red ctr thanks">Wrong username or password or your account has not been activated.</h2>';
}
}//end if submit
?>
At first you must set id user.after login user in admin page
and next you can use of that
<?php
$userId= $_GET['id'];//get user id you can use session also
if (isset($_POST['submit'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConfirm = $_POST['passwordConfirm'];
$terms = $_POST['terms'];
if (($password===$passwordConfirm) and ($terms===1)){
$query = "UPDATE members SET username = :username ,email = :email,"
."password = :password WHERE id = :id";
$stmt = $db->prepare($query);
$stmt->bindParam(':username',$username, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->bindParam(':id',$userId, PDO::PARAM_INT);
}
}
$query = "SELECT * FROM `members` WHERE id = `$userId`"; //Get user info
$sth = $db->prepare($query);
$sth ->execute();
$result = $sth->fetchAll(PDO::FETCH_ASSOC);
if ($result) {
// output data of each row
foreach($result as $row){
$username = $row['username'];
$email = $row['email'];
$password = $row['password'];
}
}
?>
<form method="post" class="form-horizontal" action="<?php filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_FULL_SPECIAL_CHARS); ?>">
<fieldset>
<legend>Edit My Account
</legend>
<div>
<label class="label" for="username">Username</label>
<input class="user" type="text" name="username" id="username" value="<?php echo $username ?>" tabindex="2" required />
</div>
<div>
<label class="label" for="email">Email</label>
<input class="email" type="email" name="email" id="email" value="<?php echo $email?>" tabindex="3" required />
</div>
<div>
<label class="label" for="password">Password</label>
<input class="password" type="password" name="password" value="<?php echo $password ?>" id="password" tabindex="4" required />
</div>
<div>
<label class="label" for="passwordConfirm">Confirm Password</label>
<input class="password" type="password" name="passwordConfirm" id="passwordConfirm" tabindex="5" required />
</div>
<div>
<input class="showbox" type="checkbox" name="terms" id="terms" tabindex="6" onFocus="this.tabIndex=1;"onBlur="this.tabIndex=6;"required />
<label for="terms">I agree to the Terms</label>
</div>
</fieldset>
<fieldset>
<div>
<input name="submit" type="submit" value="Update" />
</div>
</fieldset>
</form>

Isn't show the register user in php mysql

I have a project and in this project, I mast to use the registers. I try to write many user registers but isn't show in the databases. I don't know what is the problem. Please, can you help me?
This is one of them:
form.php
<?php
session_start();
$_SESSION['massage'] = " ";
?>
<html>
<head>
</head>
<body>
<div class="module">
<fieldset>
<legend>Create an account:</legend>
<form class="flp" mathod ="POST" action="Register.php" enctype="multipart/form-data">
<div>
<input type="text" placeholder="User Name" name="username" required />
</div>
<div>
<input type="email" placeholder="Email" name="email" required />
</div>
<div>
<input type="password" placeholder="Password" name="password" required />
</div>
<div>
<input type="password" placeholder="Confrim Password" name="confrimpassword" required />
</div>
<center>
<input type="submit" name="Register" value="Go"/>
</center>
<div>
<?php echo $_SESSION['massage']; ?>
</div>
</fomr>
</fieldset>
</div>
</body>
</html>
Register.php
<?php
session_start();
$_SESSION['massage'] = " ";
//connect to database
$mysqli = new mysqli("localhost", "root", "", "accounts");
if (isset($_POST['Register'])){//to check the button
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$password2 = mysql_real_escape_string($_POST['confrimpassword']);
if($password == $password2){
//Create User
$password = md5($_POST['password']);//hash password before storing for security purposes
$sql = "INSERT INTO account (UserName, Email, PassWord) VALUES ('$username', '$email', '$password')";
mysql_query($mysqli, $sql);
}
else
{
$_SESSION['massage'] = "There error!";
}
mysql_close($mysqli);
}
?>

Adding a record from html form to oracle database

I have a HTML form that I want to add a record to an Oracle database when somebody hits submit. The table is hooking up somewhat, the problem is that when somebody submits their information they come up as NULL values in the database table.
HTML:
<form name="myForm" action="/Add_File.php" onsubmit="return validateForm()" method="post"><!--Form-->
<fieldset>
<label class ="label1" for "name">First Name: </label>
<input type="text" name="fname"><br />
<label class ="label1" for "name">Surname: </label><input type="text" name="sname"><br/>
<label for="email">E-mail Address: </label><input type="text" name="email"><br />
<label for "address">Address: </label> <input type="text" name="address"><br />
<label class="label" for "Password">Select a Password: </label> <input type="password" name="pass"><br />
<label class="label" for "Password">Retype-Password:</label> <input type="password" name="pass2"><br />
</fieldset>
<fieldset><input class="button" type="submit" onclick="message()" value="Submit"/>
<input class="button" type="reset" value="reset form" onclick="myFunction()"/>
</fieldset>
</form>
PHP code:
$dbuser = "scott";
$dbpassword = "tiger";
$db = "orabis";
$conn = oci_connect($dbuser,$dbpassword,$db);
if (!$conn){
echo "Connection error";
exit;
}
$fname=$_POST['First_Name'];
$sname=$_POST['Surname'];
$email=$_POST['Email_Address'];
$address=$_POST['Address'];
$selpass=$_POST['Select_A_Password'];
$confirm=$_POST['Retype_Password'];
$sql = "INSERT INTO Become_A_Member_110385461(First_Name,Surname,Email_Address,Address,Select_A_Password,Retype_Password)
VALUES ('".$fname."','".$sname."', '".$email."', '".$address."','".$selpass."', '".$confirm."')";
$stmt = oci_parse($conn, $sql);
if (!$stmt) {
echo "Error in preparing the statement";
exit;
}
oci_execute($stmt, OCI_DEFAULT);
print "Record Inserted";
oci_commit($conn);
oci_close($conn);
change like this
$fname=$_POST['fname'];
$sname=$_POST['sname'];
$email=$_POST['email'];
$address=$_POST['address'];
$selpass=$_POST['pass'];
$confirm=$_POST['pass2'];

Categories