So I created an edit profile page and everything went fine. But later on I wanted to use similar code to update another thing inside my database. Its a very odd bugg because when I add to many values that need to be update it refuse to work.
<?php
session_start();
if(isset($_POST['submit'])){
$Creator = $_SESSION['username'];
$dbName = $_POST['Name'];
$dbBase_damage = $_POST['Base_damage'];
$dbDamage = $_POST['Damage'];
$dbPellets = $_POST['Pellets'];
$dbAttackspeed = $_POST['Attackspeed'];
$dbRS = $_POST['RS(first)'];
$dbRS2 = $_POST['RS(consecutive)'];
$dbLoaded = $_POST['Loaded'];
$dbReserve = $_POST['Reserve'];
$dbCritical = $_POST['Critical'];
$dbAbility = $_POST['Ability'];
$dbPiece_set = $_POST['Piece_set'];
$dbBonus_set = $_POST['Bonus_set'];
$dbDescription = $_POST['Description'];
if ($dbName && $dbBase_damage && $dbDamage && $dbAttackspeed && $dbLoaded && $dbCritical) {
mysql_connect ("localhost", "root", "") or die ("Could not connect");
mysql_select_db("weapons") or die ("Could not connect to the database");
$wepquery = mysql_query("SELECT * FROM weapon WHERE Creator='$Creator' AND Name='$dbName'") or die ("The query could not be completed, please try again later!");
if (mysql_num_rows($wepquery) != 0) {
mysql_query ("
UPDATE weapon SET Base_Damage='$dbBase_damage', Damage='$dbDamage',
Pellets='$dbPellets', Attackspeed='$dbAttackspeed', RS(first)='$dbRS', RS(consecutive)='$dbRS2',
Loaded='$dbLoaded', Reserve='$dbReserve', Critical='$dbCritical', Ability='$dbAbility', Piece_set='$dbPiece_set',
Bonus_set='$dbBonus_set' Description='$dbDescription' WHERE Creator='$Creator' AND Name='$dbName'
") or die ("Could not update!");
echo "It just werks!";
}else echo ("That username could not be found!");
}else echo ("Something went wrong!");
}
?>
When I use this code I get an error that 'Base_Damage' is undefined index. But when I remove 'Base_Damage', it can not update at all. I have double checked the database and created 'weapon ideas' with it without problems. But for some reason when I reduce the amount of values that need to be update it works just fine. If you wonder about the "$Creator = $_SESSION['username'];", I get the Creator username depending on who is logged in from "nav.php"
My html code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0" />
<title>TF2 NUT</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<div id="Container">
<div id="header">
<h1>Welcome to TF2 NUT!</h1>
</div>
<div id="nav">
<?php
include_once "nav.php";
?>
</div>
<div id="Content">
<h2>Update your submissions</h2>
<form action="edit_sub.php" method="POST">
<table>
<tr>
<td>
Choose weapon to edit:
</td>
<td>
<input type="text" name="Name" id="Name" />
</td>
</tr>
<tr>
<td>
Base damage:
</td>
<td>
<input type="text" name="Base_damage" id="Base_damage" />
</td>
</tr>
<tr>
<td>
Damage:
</td>
<td>
<input type="text" name="Damage" id="Damage" />
</td>
</tr>
<tr>
<td>
Pellets:
</td>
<td>
<input type="text" name="Pellets" id="Pellets" />
</td>
</tr>
<tr>
<td>
Attackspeed:
</td>
<td>
<input type="text" name="Attackspeed" id="Attackspeed" />
</td>
</tr>
<tr>
<td>
Reload speed:
</td>
<td>
<input type="text" name="RS(first)" id="RS(first)" />
</td>
</tr>
<tr>
<td>
Reload(consecutive):
</td>
<td>
<input type="text" name="RS(consecutive)" id="RS(consecutive)" />
</td>
</tr>
<tr>
<td>
Loaded:
</td>
<td>
<input type="text" name="Loaded" id="Loaded" />
</td>
</tr>
<tr>
<td>
Reserve:
</td>
<td>
<input type="text" name="Reserve" id="Reserve" />
</td>
</tr>
<tr>
<td>
Critical:
</td>
<td>
<input type="text" name="Critical" id="Critical" />
</td>
</tr>
<tr>
<td>
Ability:
</td>
<td>
<input type="text" name="Ability" id="Ability" />
</td>
</tr>
<tr>
<td>
Piece set:
</td>
<td>
<input type="text" name="Piece_set" id="Piece_set" />
</td>
</tr>
<tr>
<td>
Bonus set:
</td>
<td>
<input type="text" name="Bonus_set" id="Bonus_set" />
</td>
</tr>
</table>
Description:
<br />
<textarea style="resize: none;" rows="8" cols="40" id="Descripton" name="Description"></textarea>
<br />
<input type='submit' name="submit" value='Update' />
</form>
</div>
<div id="aside">
</div>
<div id="footer">
<h6>Responsible for the stuff on this site is Anton Magnusson</h6>
<h6>If I have done something wrong(I hope not ;_;) just contact me: anton_peace#hotmail.com</h6>
</div>
</div>
Anyone can help? :P
i guess your if statment is not readable and thats why you couldnt update
first your name name="Base_damage" ia not same as your variable index $dbBase_Damage = $_POST['Base_Damage'];
it should be
$dbBase_Damage = $_POST['Base_damage']; // with small d
try replave this also
if ($dbName && $dbBase_Damage && $dbDamage && $dbAttackspeed && $dbLoaded && $dbCritical)
edit:
in your query replace this
RS(first)='$dbRS', RS(consecutive)='$dbRS2'
by
`RS(first)`='$dbRS', `RS(consecutive)`='$dbRS2'
EDIT2:
please replace
or die ("Could not update!");
with
or die(mysql_error()); // like that you can see what error or what goes wrong.
EDIT3.
Bonus_set='$dbBonus_set' , Description=
^^//you missed coma here
Related
i am trying to retrieve values from an if statement, that is getting the values from a database here is the code i have;
<!DOCTYPE html>
<?PHP
include('session.php');
include('recipedbconfig.php');
if(isset($_POST['submit'])) {
$postrcpnmesrch = $_POST['rcpnmesrch'];
if($_SERVER["REQUEST_METHOD"] == "POST") {
$sql = "SELECT * FROM recipe_table WHERE recipe_name = '".$postrcpnmesrch."'";
$result = mysqli_query($db, $sql);
$row = mysqli_fetch_assoc($result);
}
}
?>
<html>
<head>
<title>Fresh Veg Admin, Edit Recipes</title>
<link rel=stylesheet type="text/css" href="/FVRC/FVRC.css">
</head>
<body>
<h1>Fresh Veg Admin, Edit Recipes</h1>
<p>User:<b> <?PHP echo $login_session; ?></b>, logged in.</p>
<form action="/FVRC/addeditrecipes.php">
<button type="submit">Back</button>
</form>
<br/>
<hr/>
<table>
<form method="POST">
<tr>
<td>
<input type="text" placeholder="Search for recipes" name="rcpnmesrch">
</td>
<td>
<button type="submit">Search</button>
</td>
</tr>
</form>
</table>
<br/>
<hr/>
<form action="editrecipecheck.php" method="POST">
<table cellspacing=0 cellpadding=5>
<tr>
<td>
</td>
<td>
<label>Recipe Name:</label>
</td>
<td>
<input type="text" placeholder="Recipe Name" name="rcpnme" value="<?php echo $row['recipe_name']; ?>" required>
</td>
</tr>
<tr>
<td>
<label>Ingredient One:</label>
</td>
<td>
<input type="text" placeholder="Ingredient" name="ingnme1" required>
</td>
i need the values that the $row array contains, so it can be referenced to in the inputs:
<td>
<input type="text" placeholder="Recipe Name" name="rcpnme" value="<?php echo $row['recipe_name']; ?>" required>
</td>
but as it is local i cant figure it out, i may just be having a brain fart moment, any help would be appreciated
all i get as an error message is this:
<br />
<b>Notice</b>: Undefined index: recipe_name in <b>E:\Program Files\xampp\htdocs\FVRC\editrecipe.php</b> on line <b>52</b>
<br />
I have tried to get this working for a couple hours now, i think its related to the fact that i have a $_GET['ID']; on the first script but im not sure:
Script 1 (FORM):
<?php
require_once('db_access.php');
$editID = $_GET['id'];
$query = mysql_query("SELECT * from routes where id = '".$editID."'");
$row = mysql_fetch_assoc($query);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
<table border=1>
<tr>
<td align=center>Route Edit Data</td>
</tr>
<tr>
<td>
<table>
<form method="post" action="complete_edit.php">
<tr>
<td>ID #</td>
<td>
<input type="hidden" name="formid" value="<?php echo $row['id'] ?>">
</td>
</tr>
<tr>
<td>Route Name</td>
<td>
<input type="text" name="route_title" size="40"
value="<?php echo $row['route_title']?>">
</td>
</tr>
<tr>
<td>Total Price</td>
<td>
<input type="text" name="total_price" size="40"
value="<?php echo $row['total_price']?>">
</td>
</tr>
<tr>
<td>Down Payment</td>
<td>
<input type="text" name="down_payment" size="40"
value="<?php echo $row['down_payment']?>">
</td>
</tr>
<tr>
<td>Weekly Net</td>
<td>
<input type="text" name="weekly_net" size="40"
value="<?php echo $row['weekly_net']?>">
</td>
</tr>
<tr>
<td>Location</td>
<td>
<input type="text" name="location" size="40"
value="<?php echo $row['location']?>">
</td>
</tr>
<tr>
<td>Remarks</td>
<td>
<input type="text" name="remarks" size="40"
value="<?php echo $row['remarks']?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
SCRIPT 2(PROCESSING):
<?php
$id = $_POSt['formid'];
$editroute = $_POST['route_title'];
$editprice = $_POST['total_price'];
$editdownpay = $_POST['down_payment'];
$editweeklynet = $_POST['weekly_net'];
$editlocation = $_POST['location'];
$editremarks = $_POST['remarks'];
$query = "UPDATE routes SET id = '$id', route_title = '$editroute', total_price = '$editprice', down_payment = '$editdownpay', weekly_net = '$editweeklynet', location = '$editlocation', remarks = '$editremarks' WHERE id = '$id'";
header('Location:index.php');
?>
The first lot of code is where my form is placed and the second is where the processing happens
Thanks for your help people :)
Alex
$id = $_POSt['formid'];
$_POSt is not $_POST
Im so silly after reading the comments to the question here i realised that i had no mysql_query string :)
Thanks guys for giving me my mind haha :)
Alex
I have already created database and table in it.But it is showing an error "input data failed"
the code of reg form is as follow
Code of form login2.php:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Form</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen, projection" />
</head>
<body>
<div id="div-regForm">
<div class="form-title" align ="center">VIDEO CHAT </div>
<br></br>
<div class="form-sub-title" align="center">If already registered</div>
<P align="center">
<td><input type="submit" class="blueButton" value="Sign in" align="right"/>
</P>
<br></br>
<div class="form-title">For New User</div>
<div class="form-title">Sign Up</div>
<div class="form-sub-title">It's free and anyone can join</div>
<form id="regForm" action="validate_login.php" method="post">
<table>
<tbody>
<tr>
<td><label for="fname">First Name:</label></td>
<td><div class="input-container">
<input name="fname" id="fname" type="text" />
</div></td>
</tr>
<tr>
<td><label for="lname">Last Name:</label></td>
<td><div class="input-container">
<input name="lname" id="lname" type="text" />
</div></td>
</tr>
<tr>
<td><label for="email">Your Email:</label></td>
<td><div class="input-container">
<input name="email" id="email" type="text" />
</div></td>
</tr>
<tr>
<td><label for="npass">New Password:</label></td>
<td><div class="input-container">
<input name="npass" id="npass" type="password" />
</div></td>
</tr>
<tr>
<td><label for="cpass">Confirm Password:</label></td>
<td><div class="input-container">
<input name="cpass" id="cpass" type="password" />
</div></td>
</tr>
<tr>
<td><label for="sex-select">I am:</label></td>
<td>
<div class="input-container">
<select name="sex-select" id="sex-select">
<option value="0">Select Sex:</option>
<option value="1">Female</option>
<option value="2">Male</option>
</select>
</div>
</td>
</tr>
<td>
<div class="input-container">
<tr>
<td> </td>
<td><input type="submit" class="greenButton" value="Sign Up" value="Sent" />
<img id="loading" src="img/ajax-loader.gif" alt="working.." />
</td>
</tr>
</tbody>
</table>
</form>
<div id="error">
</div>
</div>
</body>
</html>
to enter data in database code validate_login.php:
`
<?php
// Grab User submitted information
$db_host= "localhost";
$db_user = "root";
$db_pass = "";
$db_name = "testdb";
#mysql_connect("$db_host", "$db_user", "$db_pass")
or die("Could not connect to MySQL server!");
/*#mysql_select_db("$db_name") or die("No DATABASE");
echo"hi how r u";*/
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$email = $_POST["email"];
$npass = $_POST["npass"];
$cpass = $_POST["cpass"];
$gender = $_POST["sex-select"];
// Select the database to use
#mysql_select_db("testdb")
or die("Could not select database!");
$order = "Insert INTO 'data_user'
(fname, lname, email, npass, cpass, sex-select)
VALUES
('$fname',
'$lname','$email','$npass', '$cpass','$gender')";
$result = mysql_query($order); //order executes
if($result){
echo("<br>Input data is succeed");
} else{
echo("<br>Input data is fail");
}
?>
tell me the solution asap
Step1:
Please change the column name as sex-select to sex_select
Step2:
And remove quotes in table name 'data_user' to data_user
I've been trying to submit two buttons, one to delete and one to edit/add. But I can't seem to get it right.
HTML:
<!-- Edit/Delete Account Form -->
<form method="get" action="edit.php" onsubmit="setTimeout('location.reload()');">
<div id="edit-form" class="modal hide fade">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4><?php _e('Edit/Delete Account'); ?></h4>
</div>
<div class="modal-body">
<div id="message"></div>
<div class="control">
<div id="edit-account-form">
<table id="add-account" class="table">
<tbody>
<tr>
<td valign="middle">
Account Number
</td>
<td>
<input type="hidden" id="editid" name="editid" value=""/>
<input type="text" id="number" name="number" value="Enter Some text here "/>
</td>
</tr>
<tr>
<td>
Account Description
</td>
<td>
<input type="text" id="description" name="description" value="Enter Some text here "/>
</td>
</tr>
<tr>
<td>
Level 01
</td>
<td>
<input type="text" id="level01" name="level01" value="Enter Some text here "/>
</td>
</tr>
<tr>
<td>
Level 02
</td>
<td>
<input type="text" id="level02" name="level02" value="Enter Some text here "/>
</td>
</tr>
<tr>
<td>
Level 03
</td>
<td>
<input type="text" id="level03" name="level03" value="Enter Some text here "/>
</td>
</tr>
<tr>
<td>
Level 04
</td>
<td>
<input type="text" id="level04" name="level04" value="Enter Some text here "/>
</td>
</tr>
<tr>
<td>
Tax
</td>
<td>
<input type="text" name="account" value="Enter Some text here "/>
</td>
</tr>
<tr>
<td>
Allow General Journals
</td>
<td>
<select>
<option selected disabled>Select</option>
<option>Yes</option>
<option>No</option>
</select>
</td>
</tr>
<tr>
<td>
Allow Payments
</td>
<td>
<select>Select</select>
</td>
</tr>
<tr>
<td>
Allow Expense Claims
</td>
<td>
<select>Select</select>
</td>
</tr>
<tr>
<td>
Show On Dashboard
</td>
<td>
<select>Select</select>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" data-complete-text="<?php _e('Done'); ?>" name="add" class="btn btn-primary pull-right"><?php _e('Submit'); ?></button>
<p class="pull-left"><button type="submit" name="delete" class="btn btn-primary pull-right"><?php _e('Delete'); ?></button></p>
</div>
</div>
</form>
PHP:
<?php
//Account Details
$number = $_GET['number'];
$description = $_GET['description'];
$level01 = $_GET['level01'];
$level02 = $_GET['level02'];
$level03 = $_GET['level03'];
$level04 = $_GET['level04'];
$id = $_GET['editid'];
$dbc = mysqli_connect('localhost', 'root', 'root', 'accounting') or die('Connection error!');
if(isset($_POST['delete'])) {
$check = "DELETE FROM accountSlave WHERE `id` = '$id' ";
mysqli_query($dbc, $check) or die('Database error, delete account!');
}
if(isset($_POST['add'])) {
//$check = "DELETE FROM accountSlave WHERE `id` = '$id' ";
$check = "UPDATE accountSlave SET `accountNumber` = '$number', `accountDescription` = '$description', `accountLevel1` = '$level01', `accountLevel2` = '$level02', `accountLevel3` = '$level03', `accountLevel4` = '$level04' WHERE `id` = '$id'";
mysqli_query($dbc, $check) or die('Database error, add account!');
}
header('location:master-accounts.php');
?>
It works when I have one query. I've tried one query to add and to delete and it worked. But I need to submit a delete if delete button clicked and vice versa.
I followed this post to try get it right multiple buttons on a form
Any help or suggestions will be appreciated!
You need to use $_GET instead of $_POST. It should be like
if(isset($_GET['delete'])) {
and
if(isset($_GET['add'])) {
Because your form submit method is GET not the POST
You have to check which button is pressed and according to that do your operation.
Also you have to use $_GET not $_POST because your form method is GET.
if(isset($_GET['add'])) {
// code for add
} elseif(isset($_GET['delete'])) {
// code for delete
}
<?php
if(isset($_POST['submit']))
{
$uname=$_POST['uname'];
$pswd=$_POST['pswd'];
$cpswd=$_POST['cpswd'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$address=$_POST['add'];
$mobile=$_POST['mobile'];
$con=mysqli_connect("localhost","root","","registration");
$sql1="select usname, email from registration1 where usname='$uname' or email='$email'";
$query=mysqli_query($con,$sql1) or die(mysqli_error($con));
$rownum=mysqli_num_rows($query);
if($rownum != 0)
{
echo "User With This User Name or Email Address Is Already Available";
}
else
{
$sql2="insert into registration1 (usname,psswd,fsname,lsname,email,address,mobileno) values ('$uname','$pswd','$fname','$lname','$email','$address','$mobile')";
mysqli_query($con,$sql2) or die(mysqli_error($con));
echo "Registration Successful";
}
}
?>
I am redirecting to home.php which is written in form action, the php code in this is not executing. can anybody help me to resolve this
this is my html code i am redirecting to home .php on clicking submit button values entered in textbox is not entering into database on clicking submit button.
`<html>
<head>
<title>Registration Form</title>
</head>
<body>
<center>
<form method="post" action="home.php">
<table>
<tr>
<td>
<p>User Name</p>
</td>
<td>
<input type="text" name="uname"/>
</td>
</tr>
<tr>
<td>
<p>Password</p>
</td>
<td>
<input type="password" name="pswd" />
</td>
</tr>
<tr>
<td>
<p>Confirm Password</p>
</td>
<td>
<input type="password" name="cpswd" />
</td>
</tr>
<tr>
<td>
<p>First Name</p>
</td>
<td>
<input type="text" name="fname" />
</td>
</tr>
<tr>
<td>
<p>Last Name</p>
</td>
<td>
<input type="text" name="lname" />
</td>
</tr>
<tr>
<td>
<p>Email Address</p>
</td>
<td>
<input type="email" name="email" />
</td>
</tr>
<tr>
<td>
<p>Address</p>
</td>
<td>
<input type="text" name="add" />
</td>
</tr>
<tr>
<td>
<p>Mobile No.</p>
</td>
<td>
<input type="text" name="mobile" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" name="submit" />
</td>
</tr>
</table>
</form>
</center>
</body>
</html>`
If there is no Output / No Errors .. Please Make Sure $_POST['submit'] Variable is Posted Vai From..
at first want to say please describe the error properly.there can be many reason.
option 1:maybe $_POST['submit'] or other values is not initialized properly.then it wont enter the if block ever
option 2:$con=mysqli_connect("localhost","root","password"); check if this connection establishment is okay or not.
option 3:i am not sure.but i think while fetching multiple column you need to use an array().
please debug the code..find out after which line the code stop executing.you can do this by using echo 'xxx'; as checkpoint in your code and report us
note:use mysqli_real_escape_string() and various php mysqli function to be safe from mysqli injection
<input type="submit" value="submit" name="submit" />
<input type="hidden" name="submit" value="submit" />
</form>
this is how your form should be done..add that hidden type
EDIT 1: if it doesn't work.then put echo 'step 1,2,3...' in your home.php.and check after which statement it stops executing.for exemple you can put a echo right after if() to check if it is entering in your if block or not