I need to update my data in database. I am successfully created the user registration and login form in php, so i need to update and delete data in database. And I am getting error message update function.
There is condition: id(primary) and email(unique) & username(unique).
Error message in this program:
"Error updating record: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1."
<?php
session_start();
require('connect.php');
if(isset($_POST['submit'])){
$id = $_POST['id'];
$username = $_POST['username'];
$name = $_POST['name'];
$email = $_POST['email'];
$password = md5($_POST['password']);
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$location = $_POST['location'];
$course = $_POST['course'];
$mobile = $_POST['mobile'];
$sql = " UPDATE user SET username ='$username', name = '$name', email = '$email', password='$password', dob ='$dob', gender ='$gender',location ='$location', course = '$course', mobile = '$mobile' WHERE id= $id ";
if (mysqli_query($mysqli, $sql)) {
$smsg = "Record updated successfully";
} else {
$fmsg = "Error updating record: " . mysqli_error($mysqli);
}
}
?>
<html>
<head>
<title>User Update PHP & MYSQL</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap-theme.min.css" >
<link rel="stylesheet" href="main.css" >
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<a class= "float-right" href = "logout.php"> LOGOUT </a>
<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
<form class="form-signin" method="POST">
<h2 class="form-signin-heading">Edit Profile</h2>
<div class="input-group">
<input type="hidden" name="id" placeholder="ID">
<input type="text" name="username" class="form-control" placeholder="username" required></div>
<label for="inputname" class="sr-only">Full Name</label>
<input type="text" name="name" id="inputname" class="form-control" placeholder="Full Name"required>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address"required>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="inputDoB" class="sr-only">DOB</label>
<input type="date" name="dob" id="inputDoB" class="form-control" placeholder="DOB"required>
<td>Gender:</td>
<input type="radio" name="gender" value="m">Male
<input type="radio" name="gender" value="f">female
</tr>
<label for="inputlocation" class="sr-only">Location</label>
<input type="text" name="location" id="inputlocation" class="form-control" placeholder="Location"required>
<label for="inputcourse" class="sr-only">Course</label>
<input type="text" name="course" id="inputcourse" class="form-control" placeholder="Course" required>
<label for="inputmobile" class="sr-only">Mobile</label>
<input type="text" name="mobile" id="inputmobile" class="form-control" placeholder="Mobile" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" name="submit">Update</button>
</div>
</body>
</head>
</html>
You have not added value to id.
It is a hidden variable, so, it can only be set through PHP or JS not with user input.
Therefore, your query after where clause is blank and causing error.
Solution:
Assign id a value.
<input type="hidden" name="id" placeholder="ID" value="<?php echo $user_id;?>">
And to avoid this error, check if id is posted.
Modify:
if(isset($_POST['submit'])) {
To:
if(isset($_POST['submit']) && ! empty($_POST['id'])){
Related
Below is the html code for my form and the php code which i am using to pass data to a class method.Now the problem that i have is that the control does not seem to enter the if loop which i concluded by testing as you can see."test0" gets printed but "test1" and other subsequent "tests" do not get printed.
<form action="" method="post" enctype=multipart/form-data>
<div class="form-group">
<label for="job name">Job name:</label>
<input type="text" class="form-control" id="jobnm" value="<?php echo $_GET['jobnm'];?>" disabled>
</div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" name="name" required>
</div>
<div class="form-group">
<label for="email">Email address:</label>
<input type="email" class="form-control" name="mail" required>
</div>
<div class="form-group">
<label for="phone">Enter a phone number:</label><br><br>
<input type="tel" id="phone" name="phone" placeholder="+91-1234567890" pattern="[0-9]{10}" required><br><br>
<small>Format: 1234567890</small><br><br>
</div>
<label >Gender</label>
<div class="radio">
<label><input type="radio" name="optradio" value="m">Male</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio" value="f">Female</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio" value="o">Other</label>
</div>
<div class="custom-file">
<input type="file" class="custom-file-input" name="cvFile" required>
<label class="custom-file-label" for="customFile">Upload resume</label>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-danger" >Reset</button>
</form>
<?php
require_once 'db-config.php';
require_once 'classCandi.php';
echo "test0";
if(isset($_POST['submit']))
{
echo "test1";
$jobID = $_GET['jobid'];
echo "test2";
$canName = $_POST['name'];
$canEmail = $_POST['mail'];
$canPhone = $_POST['phone'];
$canRadio = $_POST['optradio'];
echo "test3";
//Upload file
$fnm = "cv/";
$cvDst = $fnm . basename($_FILES["cvFile"]["name"]);
move_uploaded_file($_FILES["cvFile"]["tmp_name"],$cvDst);
echo "test4";
$obj = new Candi($conn);
$obj->storeInfo($jobID,$canName,$canEmail,$canPhone,$canRadio,$cvDst);
echo "test5";
echo '<script language="javascript">';
echo 'alert("Submitted");';
echo '</script>';
echo "test6";
}
The below code won't be true anytime! It's because you didn't understand how $_POST works.
if(isset($_POST['submit']))
There's no input element in your frontend that has name="submit". And to see, there's none of the inputs have name attribute at all.
Instead, the better way to do is, understand how this works and change your code so that, it includes:
a name attribute for all the input and form elements.
a check on the values and not $_POST['submit']
And finally...
don't copy and paste without understanding the code.
don't check on $_POST['submit'] truthness.
Example, for $canName = $_POST['name']; to work, you need to have:
<input type="text" name="name" id="name" value="<?php echo $something; ?>" />
// ^^^^^^^^^^^
And have your attribute and values in quotes please:
enctype="multipart/form-data"
// ^ ^
I'm currently trying to complete this project for school and I would really appreciate some help.
I have been trying to learn PHP so I could extract data from my HTML and put it into my MySQL (which I'm accessing through XAMP). I have a problem that says:
The requested URL was not found on this server.
The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.' when I press the register button. I don't know what this means? I have a table called usertable in the database Login so I feel like it should work.
This is my PHP code:
<?php
session_start();
$con = mysqli_connect('localhost', 'root', 'ocr2020');
mysqli_select_db($con, 'login');
$name = $_POST['user'];
$pass = $_POST['pass'];
$fname= $_POST['forename'];
$sname = $_POST['surname'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$dateofB= $_POST['dateB'];
$s= "select * from usertable where name='$name'";
$s2= "select * from usertable";
$result= mysqli_query($con,$s);
$num= mysqli_num_rows($result);
$num2= mysqli_num_rows($s2);
$id= $num2+1;
if($num==1){
echo" Username Is No Longer Available";
}else{
$reg= " insert into usertable(patientID, Forename, Surname, Username, Password, Email, Mobile,
DateOfBirth) values ('$id', '$fname', '$sname', '$name', '$pass', '$email', '$mobile', '$dateOfB')";
mysqli_query($con, $reg);
echo" Registration Successful";
}
?>
As I said, I would really appreciate any help or advice. Thanks!
Edit:
Here is the updated code having taken on everyone's comments:
<?php
ini_set('display_errors', 1);
ini_set('log_errors',1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);.
session_start();
$con = mysqli_connect('localhost', 'root', 'ocr2020');
mysqli_select_db($con, 'login');
$name = $_POST['user'];
$pass = $_POST['pass'];
$fname= $_POST['forename'];
$sname = $_POST['surname'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$dateofB= $_POST['dateB'];
$s= "select * from usertable where name='$name'";
$result= mysqli_query($con,$s);
$num= mysqli_num_rows($result);
if($num>0){
echo" Username Is No Longer Available";
}else{
$reg= " insert into usertable(patientID, Forename, Surname, Username, Password, Email, Mobile, DateOfBirth) values ('$id', '$fname', '$sname', '$name', '$pass', '$email', '$mobile', '$dateOfB')";
mysqli_query($con, $reg);
echo" Registration Successful";
}
?>
Here is the code from the login.php page which is where I press the 'register button' and it creates the problem:
<html>
<section id="loginBox">
<div class="container">
<div class="login-box">
<div class="row">
<div class="col-md-6 login-left">
<h3> Login Here </h3>
<form action="registration.php" method="POST">
<div class="form-group">
<label> Username </label>
<input type="text" name="user" placeholder="Enter your username" class="form-control" required>
</div>
<div class="form-group">
<label> Password </label>
<input type="password" name="password" placeholder="Enter your password" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary"> Login </button>
</form>
</div>
<div class="col-md-6 login-right">
<h3> Register Here </h3>
<form action="validation.php" method="POST">
<div class="form-group">
<label> Username </label>
<input type="text" name="user" placeholder="Enter your username" class="form-control" required>
</div>
<div class="form-group">
<label> Password </label>
<input type="password" name="password" placeholder="Enter your password" class="form-control" required>
</div>
<div class="form-group">
<label> Forename </label>
<input type="text" name="forename" placeholder="Enter your forename" class="form-control" required>
</div>
<div class="form-group">
<label> Surname </label>
<input type="text" name="surname" placeholder="Enter your surname" class="form-control" required>
</div>
<div class="form-group">
<label> Mobile</label>
<input type="text" name="mobile" placeholder="Enter your mobile" class="form-control" required>
</div>
<div class="form-group">
<label> Email </label>
<input type="text" name="email" placeholder="Enter your email" class="form-control" required>
</div>
<div class="form-group">
<label> Date of Birth</label>
<input type="date" name="dateB" placeholder="Enter your date of birth" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary"> Register </button>
</form>
</div>
</div>
</div>
</div>
</section>
</body>
</html>
I need update my profile in the mysql database and to setup the user type in the program. How to upload image in this register program? have tried everything, new to php and I am getting an error every time running my below program. How to delete the stored values?
Register.php
<?php
session_start();
require('connect.php');
if(isset($_POST['submit'])){
$username = $_POST['username'];
$name = $_POST['name'];
$email = $_POST['email'];
$password = md5($_POST['password']);
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$location = $_POST['location'];
$course = $_POST['course'];
$mobile = $_POST['mobile'];
$query = "INSERT INTO `user`(username, name, password, email, dob, gender, location, course, mobile) VALUES ('$username', '$name', '$password', '$email', '$dob', '$gender', '$location', '$course', '$mobile')";
$result = mysqli_query ($mysqli,$query);
if($result){
$smsg = "Thank you!Your registration form has been successfully submitted.";
}else{
$fmsg = "This email already exists ";
}
}
?>
<html>
<head>
<title>User Registration PHP & MYSQL</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap-theme.min.css" >
<link rel="stylesheet" href="styles.css" >
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
<form class="form-signin" method="POST">
<h2 class="form-signin-heading">Please Register</h2>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">ID</span>
<input type="text" name="username" class="form-control" placeholder="username" required></div>
<label for="inputname" class="sr-only">Full Name</label>
<input type="text" name="name" id="inputname" class="form-control" placeholder="Full Name"required>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address"required>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="inputDoB" class="sr-only">DOB</label>
<input type="date" name="dob" id="inputDoB" class="form-control" placeholder="DOB"required>
<td>Gender:</td>
<input type="radio" name="gender" value="m">Male
<input type="radio" name="gender" value="f">female
</tr>
<label for="inputlocation" class="sr-only">Location</label>
<input type="text" name="location" id="inputlocation" class="form-control" placeholder="Location"required>
<label for="inputcourse" class="sr-only">Course</label>
<input type="text" name="course" id="inputcourse" class="form-control" placeholder="Course" required>
<label for="inputmobile" class="sr-only">Mobile</label>
<input type="text" name="mobile" id="inputmobile" class="form-control" placeholder="Mobile" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" name="submit">Register</button>
<a class="btn btn-lg btn-primary btn-block" href="login.php">Login</a>
</div>
</body>
</head>
</html>
Edit.php
<?php
session_start();
require('connect.php');
if(isset($_POST['submit']) && ! empty($_POST['id'])){
$id = $_POST['id'];
$name = $_POST['name'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$location = $_POST['location'];
$course = $_POST['course'];
$mobile = $_POST['mobile'];
$sql = " UPDATE user SET name = '$name',
dob ='$dob',
gender ='$gender',
location ='$location',
course = '$course',
mobile = '$mobile'
WHERE id= $id ";
if (mysqli_query($mysqli, $sql)) {
$smsg = "Record updated successfully";
} else {
$fmsg = "Error updating record: " . mysqli_error($mysqli);
}
}
?>
<html>
<head>
<title>User Update PHP & MYSQL</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap-theme.min.css" >
<link rel="stylesheet" href="main.css" >
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<a class= "float-right" href = "logout.php"> LOGOUT </a>
<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
<form class="form-signin" method="POST">
<h2 class="form-signin-heading">Edit Profile</h2>
<div class="input-group">
<input type="hidden" name="id" placeholder="ID" value="<?php echo $id;?>"></div>
<label for="inputname" class="sr-only">Full Name</label>
<input type="text" name="name" id="inputname" class="form-control" placeholder="Full Name"required>
<label for="inputDoB" class="sr-only">DOB</label>
<input type="date" name="dob" id="inputDoB" class="form-control" placeholder="DOB"required>
<td>Gender:</td>
<input type="radio" name="gender" value="m">Male
<input type="radio" name="gender" value="f">female
</tr>
<label for="inputlocation" class="sr-only">Location</label>
<input type="text" name="location" id="inputlocation" class="form-control" placeholder="Location"required>
<label for="inputcourse" class="sr-only">Course</label>
<input type="text" name="course" id="inputcourse" class="form-control" placeholder="Course" required>
<label for="inputmobile" class="sr-only">Mobile</label>
<input type="text" name="mobile" id="inputmobile" class="form-control" placeholder="Mobile" required>
<button class="btn btn-lg btn-primary btn-block" type="submit" name="submit" value="Update data">Update</button>
</div>
</body>
</head>
</html>
Login.php
<?php
//start session
session_start();
if(!isset($_SESSION['username'])){
header('location:login.php');
}
?>
<html>
<head>
<title>HomePage</title>
<link rel="stylesheet" href="main.css" >
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" >
</head>
<body>
<div class= "container" >
<b><a class= "float-right" href = "logout.php"> LOGOUT </a></b>
<h1> Welcome</h1>
<h2>
<?php
require("connect.php");
$query = "SELECT * FROM user";
echo '<table border="1" cellspacing="1" cellpadding="1">
<tr>
<td> <font face="Arial"><b>Username</font></b></td>
<td> <font face="Arial"><b>Full name</font></b></td>
<td> <font face="Arial"><b>Email ID</font></b></td>
<td> <font face="Arial"><b>Password</font></b></td>
<td> <font face="Arial"><b>Date of Birth</font></b></td>
<td> <font face="Arial"><b>Gender</font></b></td>
<td> <font face="Arial"><b>location</font></b></td>
<td> <font face="Arial"><b>Degree</font></b></td>
<td> <font face="Arial"><b>Mobile</font></b></td>
<td> <font face="Arial"><b>Update</font></b></td>
<td> <font face="Arial"><b>Delete</font></b></td>
</tr>';
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
$id=$row["id"];
$username = $row["username"];
$name = $row["name"];
$email = $row["email"];
$password = $row["password"];
$dob = $row["dob"];
$gender = $row["gender"];
$location = $row["location"];
$course = $row["course"];
$mobile = $row["mobile"];
echo '<tr>
<td>'.$username.'</td>
<td>'.$name.'</td>
<td>'.$email.'</td>
<td>'.$password.'</td>
<td>'.$dob.'</td>
<td>'.$gender.'</td>
<td>'.$location.'</td>
<td>'.$course.'</td>
<td>'.$mobile.'</td>
<td>Edit</td>
<td>Delete</td>
</tr>';
}
$result->free();
}
?></h2>
</div>
</body>
</html>
You can get the file in the post variable from the form and here is the code to upload file and saving it into the storage/uploads folder
$info = pathinfo($_FILES['your_file_name']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = "newname.".$ext;
$target = 'avatar/'.$newname;
move_uploaded_file( $_FILES['your_file_name']['tmp_name'], $target);
Here is the post which will helps you create random string for the filename (you can save this filename into the database) https://stackoverflow.com/a/13212994/5928015
This question already has answers here:
How to prevent duplicate usernames when people register?
(4 answers)
Closed 1 year ago.
I'm trying to force users to pick a unique username and returning an error message if they don't. All other validation (password matching, etc.) is working but validating an unused username just returns ID Registration failed message.
I've updated this with the HTML as requested.
I just want it to tell the user the errors I've outlined in those cases.
<?php
require('connect.php');
if(isset($_POST) & !empty($_POST)){
// If the values are posted, insert them into the database.
// if (isset($_POST['app_id']) && isset($_POST['password'])){
$app_id = mysqli_real_escape_string($connection, $_POST['app_id']);
$first = mysqli_real_escape_string($connection, $_POST['first']);
$last = mysqli_real_escape_string($connection, $_POST['last']);
$gender = mysqli_real_escape_string($connection, $_POST['gender']);
$birth = mysqli_real_escape_string($connection, $_POST['birth']);
$email = mysqli_real_escape_string($connection, $_POST['email']);
$password = mysqli_real_escape_string($connection, md5($_POST['password']));
$confirmpassword = mysqli_real_escape_string($connection, md5($_POST['confirmpassword']));
if($password == $confirmpassword){
$fmsg = "";
//username validation
$newidvalq = "SELECT * FROM 'user' WHERE app_id='$app_id'";
$newidres = mysqli_query($connection, $newidvalq);
$idcount = 0;
$idcount = mysqli_num_rows($newidres);
if($idcount >= 1){
$fmsg .= "That app ID is already being used, please try a different ID";
}
//email validation
$emailvalq = "SELECT * FROM 'user' WHERE email='$email'";
$emailres = mysqli_query($connection, $emailvalq);
$emailcount = 0;
$emailcount = mysqli_num_rows($emailres);
if($emailcount >= 1){
$fmsg .= "That email is already being used";
}
//DB Insert
$query = "INSERT INTO `user` (app_id, first, last, gender, birth, password, email) VALUES ('$app_id', '$first', '$last', '$gender', '$birth', '$password', '$email')";
//Result Validation
$result = mysqli_query($connection, $query);
if($result){
$smsg = "app ID Created Successfully";
}else{
$fmsg .= "app Registration Failed";
}
}else{
$fmsg = "Your Passwords do not match";
}
}
?>
<html>
<head>
<title>User Registeration Using PHP & MySQL</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >
<link rel="stylesheet" href="styles.css" >
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<form class="form-signin" method="POST">
<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
<?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?>
<h2 class="form-signin-heading">Please Register</h2>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">#</span>
<input type="text" name="app_id" class="form-control" placeholder="app ID" value="<?php if(isset($app_id) & !empty($app_id)) {echo $app_id;} ?>" required>
</div>
<input type="text" name="first" class="form-control" placeholder="First Name" value="<?php if(isset($first) & !empty($first)) {echo $first;} ?>"required>
<input type="text" name="last" class="form-control" placeholder="Last Name" value="<?php if(isset($last) & !empty($last)) {echo $last;} ?>"required>
<input type="text" name="gender" class="form-control" placeholder="Gender" value="<?php if(isset($gender) & !empty($gender)) {echo $gender;} ?>"required>
<input type="date" name="birth" class="form-control" placeholder="Birthday" required>
<label for="inputEmail" class="sr-only">Email Address</label>
<input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" value="<?php if(isset($email) & !empty($email)) {echo $email;} ?>"required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Enter a Password" required>
<label for="inputPassword" class="sr-only">RetypePassword</label>
<input type="password" name="confirmpassword" id="inputPassword" class="form-control" placeholder="Confirm Your Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
<a class="btn btn-lg btn-primary btn-block" href="login.php">Login</a>
</form>
</div>
</body>
</html>
assign $idcount with 0 first before using and then in the if condition use ($idcoun>=1)
And According to your logic if the userid and email exist also then also you are inserting the data which make no sense according to your need
Enclose your INSERT block in:
if( $fmsg == "" ) { ..to here.. }
So that if there was an error, no record will be inserted to database, and error will be displayed.
Add action attribute to form tag like:
<form class="form-signin" method="POST" action="">
It is required in some versions of html not html5.
This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 6 years ago.
I checked source code ten times but can't find anymistake,for some reason i remember it was working now it doesn't work,i didn't change anything elsewhere to blame everything wors except update,when iclick Edit button it gives error,meaning that there was something wrong with query.
<?php
$editId = $_GET['id'];
$event = mysqli_query($con, "SELECT * FROM events WHERE id = '$editId'")->fetch_assoc();
if(isset($_POST['submit'])){
$name = $_POST['name'];
$description = $_POST['description'];
$date = $_POST['date'];
$artists = $_POST['artists'];
$tickets = $_POST['tickets'];
$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', ticket='$tickets' WHERE id = '$editId'");
}
?>
<?php if(isset($updateQuery) && $updateQuery): ?>
<div class="alert alert-success">
<strong>Successfully Edited</strong>
</div>
<?php endif; ?>
<?php if(isset($updateQuery) && !$updateQuery): ?>
<div class="alert alert-danger">
<strong>Error</strong>
</div>
<?php endif; ?>
<form action="<?php echo $app_host; ?>/admin/?page=editevent&id=<?php echo $editId; ?>" method="post">
<div class="form-group">
<label for="name">Name</label>
<input value="<?php echo $event['name']; ?>" required="true" type="text" class="form-control" id="name" name="name">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description"><?php echo $event['description'];; ?></textarea>
</div>
<div class="form-group">
<label for="date">Date</label>
<input value="<?php echo $event['date']; ?>" required="true" type="text" class="form-control" id="date" name="date">
</div>
<div class="form-group">
<label for="artists">Artists</label>
<input value="<?php echo $event['artists']; ?>" required="true" type="text" class="form-control" id="artists" name="artists" data-role="tagsinput">
</div>
<div class="form-group">
<label for="tickets">Ticket Link</label>
<input value="<?php echo $event['tickets']; ?>" required="true" type="text" class="form-control" id="tickets" name="tickets" data-role="tagsinput">
</div>
<input name="submit" type="submit" class="btn btn-default" value="Edit Event" />
</form>
Okay,so you declare a variable ,
$tickets = $_POST['tickets'];
and than you say
$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', ticket='$tickets' WHERE id = '$editId'");
}
and solution is simple:
$updateQuery = mysqli_query($con, "UPDATE events SET name='$name',description='$description',date='$date', artists='$artists', tickets='$tickets' WHERE id = '$editId'");
}
simply changed 'ticket' in query to 'tickets'.