code is not coming into signup_ad.php
signup_ad.php:
<? php
mysql_connect("localhost","root","") or die("not connected");
mysql_select_db("sample") or die("no db found");
if(isset($_POST)
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$query= "insert into signup(fname,lname) values('$fname','$lname')";
$result=mysql_query($query);
if (!$result) {
$message='invalid query';
die($message); }
}
?>
value is not entering into db..and also not giving any error. Do i need to include my signup_ad.php file ?
signup.php:
<form action="signup_ad.php" method="post" >
<label>
First Name
</label>
<input type="text" required autocomplete="off" name="fname" />
<label>
Last Name
</label>
<input type="text" required autocomplete="off" name="lname"/>
<button type="submit" class="button button-block" name="btn-signup" value="submit" action="login.php" />Get Started</button>
You forget a quotation before semicolon:
$query= "insert into signup(fname,lname) values('$fname','$lname')";
Related
this is the html
<form action="addadd.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>
First Name<br>
<label for="firstname"></label>
<input type="text" name="firstname" id="firstname" />
</p>
<p>
Last Name<br>
<label for="lastname"></label>
<input type="text" name="lastname" id="lastname" />
</p>
<p>
Mobile<br>
<label for="mobile"></label>
<input type="text" name="mobile" id="mobile" />
</p>
<p>
Email<br>
<label for="email"></label>
<input type="text" name="email" id="email" />
</p>
<p>
<input type="submit" name="button" id="button" value="Submit" />
<input type="reset" name="button3" id="button3" value="Reset" />
</p>
</form>
This is the php
database connection
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die("connection to database failed".mysql_error());
}
$dataselect = mysql_select_db("qoot",$con);
if(!$dataselect)
{
die("Database namelist not selected".mysql_error());
}
?>
<?php
$unm = $_SESSION['name'];
$fname=$_POST['firstname'];
$lname=$_POST['lastname'];
$ema=$_POST['email'];
$mob=$_POST['mobile'];
?>
<?php
$qry=mysql_query("INSERT INTO address( firstname, lastname, mobile, email)VALUES('$fname',$lname','$ema','$mob')", $con);
?>
Now the problem is that this is inserting nothing in to my database.
What else can i try in order to check where things go wrong?
updated database connection details
Place your tablename address in backticks
Using mysqli_
<?php
/start session
session_start();
//establish connection
$con = mysqli_connect("localhost","root","","qoot");
if(!$con)
{
die("connection to database failed".mysqli_error($con));
}
//read the values from form
$unm = $_SESSION['name'];
$fname=$_POST['firstname'];
$lname=$_POST['lastname'];
$ema=$_POST['email'];
$mob=$_POST['mobile'];
?>
<?php
//insert to database
$qry=mysqli_query($con,"INSERT INTO `address` ( firstname, lastname, mobile, email)VALUES('$fname',$lname','$ema','$mob')") or die(mysqli_error($con));
?>
P.S I'd say you are at risk of mysql injection, check here How can I prevent SQL injection in PHP?. You should really use prepared statements to avoid any risk.
my code wont insert into the student table I dont know whats wrong could you guys possibly help? I tried to print and error message in each line to find out where the error was but I got no errors so I'm confused
<?PHP
if(isset($_POST['submit'])) {
$link = mysql_connect('localhost','root','');
if (!$link) {
die('Could not connect :' . mysql_error());
}
$Selected= mysql_select_db("elearningg", $link);
if (!$Selected) {
die("Could not connect: " . mysql_error());
}
$sql = "INSERT INTO student (FirstName, LastName, UserName,Password, confirmP ,phoneNum,Email) VALUES ('$_POST[FN]','$_POST[LN]','$_POST[userName]','$_POST[password]','$_POST[confirmPass]','$_POST[number]','$_POST[email]') ";
mysql_query($sql,$link);
mysql_close($link);
}
?>
and here's the html form:
<form method="post" action="Register.php">
<div class="contact-to">
<P> <input name="FN" type="text" class="text" value="First name" >
<input name="LN" type="text" class="text" value="Last name" style="margin-left: 10px">
<input name="userName" type="text" class="text" value="username" style="margin-left: 10px">
</div>
<div class="contact-to">
<input name="password" type="text" class="text" value="Password" style="margin-left: 10px">
<input name="confirmPass" type="text" class="text" value="Confirm password" style="margin-left: 10px">
<input name="number" type="text" class="text" value="Phone Number" >
<input name="email" type="text" class="text" value="email" >
</div>
<div> <input value="submit" type="submit" class="submit"> </div>
</form>
If you're trying to validate $_POST['submit'] after user clicks the button, you should include attribute name inside your input submit tag like this:
<input value="submit" type="submit" name="submit" class="submit">
And then you can check $_POST:
if(isset($_POST['submit'])) {
// your code
}
PHP will always return false in your condition without a attribute name...
Also, consider using mysqli with prepared statements, or PDO with prepared statements, they're much safer.
Change your sql insert query code to this:
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
function debug($data){
echo '<pre>';
print_r($data);
echo '</pre>';
}
function getConnected($host,$user,$pass,$db) {
$mysqli = new mysqli($host, $user, $pass, $db);
if($mysqli->connect_error)
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
return $mysqli;
}
if(isset($_POST['submit'])) {
debug('Connecting database...');
$link = getConnected('localhost','root','', 'stackoverflow');
debug('Database connected...');
$sql = "
INSERT INTO `student` (`FirstName`, `LastName`, `UserName`, `Password`, `confirmP`, `phoneNum`, `Email`)
VALUES (
'{$_POST['FN']}',
'{$_POST['LN']}',
'{$_POST['userName']}',
'{$_POST['password']}',
'{$_POST['confirmPass']}',
'{$_POST['number']}',
'{$_POST['email']}'
)";
if (!mysqli_query($link, $sql)) {
debug("Errormessage: ". mysqli_error($link)."\n");
}else{
debug('Query executed successfully...');
}
mysqli_close($link);
}
?>
Also change your form submit button code to this:
<div> <input name="submit" value="submit" type="submit" class="submit"> </div>
I'm creating update password page in php but getting problem i.e. insted of post request i'm getting get. i'm using post method in form. why this happen
please help
here is my code
<?php
if(isset($_POST['add'])){
if(empty($_POST['add'])){
$error='Username or Password did not match';
}
else
{
$password=$_POST['pass'];
$connection = mysql_connect("localhost", "root", "") or die("Connection fail");
$db=mysql_select_db("chanshal", $connection);
$result=mysql_query("UPDATE login SET password='$password' where id=1", $connection );
echo 'Entered data succesfully';
mysql_close($connection);
}
}
$title='Change Password';
$content='
<div class="gallery-box">
<form action="" method="post">
<label style="padding-right:50px;">Password</label> <input type="password" name="pass" value="">
<br />
<br />
<label style="padding-right:50px;">New Password</label> <input type="password" name="new-pass" value="">
<br />
<br />
<input style="width:150px;" name="add" type="submit" value="Update">
</form>
</div>
';
include 'admin-template.php';
You are taking $_POST['pass'], but the new password field has the name new-pass in your form:
$password=$_POST['pass'];
<input type="password" name="new-pass" value="">
So I would say your POST request is working fine, you just update your table with the same data all the time.
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'];
pswThe index.php part seems to work fine, but the handler throws a internal server error (500).
index.php
<div id="contact">
<h1>Contact us</h1>
<form id="ContactForm" method="post" action="submit.php">
<p>
<label>Name<span>(optional)</span></label>
<input id="name" name="name" class="inplaceError" maxlength="120" type="text" autocomplete="on"/>`enter code here`
<span class="error" style="display:none;"></span>
</p>
<p>
<label>Email<span>(optional)</span></label>
<input id="email" name="email" type="text" />
</p>
<p>
<label>Subject<span>(optional)</span></label>
<input id="website" name="website" />
</p>
<p>
<label>Your message<br /> <span>700 characters allowed</span></label>
<textarea id="message" name="message" cols="6" rows="5"></textarea>
</p>
<p class="submit">
<input id="send" type="submit" value="Submit" name="submit"/>
<span id="loader" class="loader" style="display:none;"></span>
</p>
<input id="newcontact" name="newcontact" type="hidden" value="1"></input>
</form>
submit.php -->
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website']; //subject
$message = $_POST['message'];
$connection = mysql_connect ("localhost", "root", "pswd") or die ('DB connection fail:' .mysql_error());
mysql_select_db ("contactform");
$query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES ('NULL','$name','$email','$sub','$msg','NULL')";
//good to know about the quotes, but the page still insist there's an error
mysql_query($query) or die ('Error uploading DB');
mysql_close($connection);
echo "<span id="success_message" class="success">YAY! It worked.</span>";
} else {
echo "<span class='error'>Try again.</span>";
}
I think you've got an error with your query string. It should look like
$query = "INSERT INTO contact (name, email, website, message, added_date)VALUES ('$name','$email','$sub','$msg',NULL)";
The double quotes were breaking up your string, and the different parts weren't being concatenated.
As Mikecito mentioned. You'll want to remove the quotes around NULL.
$query = "INSERT INTO contact (pk_contact, name, email, website, message, added_date)VALUES (NULL,'$name','$email','$sub','$msg',NULL)";
Assuming you have set you mysql table so the added_date field is a mysql timestamp format, attempting to enter 'NULL' into the table will result in a mysql error.
Also make sure the mysql table allows null values to be entered into the pk_contact and added_date fields.