Using php, i created an edit option that basically lets u change the data in the record. However, after clicking on submit, the data doesn't get saved on the table nor do i get any errors.. I am quite confused. Here r my codes:
<html>
<body>
<?php
include('db.php');
if (isset($_GET['Id'])) {
$Id=$_GET['Id'];
if (isset($_POST['submit'])) {
$Fname=$_POST['Fname'];
$Lname=$_POST['Lname'];
$Age=$_POST['Age'];
$Nationality=$_POST['Nationality'];
$PhoneNumber=$_POST['PhoneNumber'];
$Email=$_POST['Email'];
$query3=mysql_query("UPDATE `students` SET `Fname`='$Fname',`Lname`='$Lname',`Age`='$Age',`Nationality`='$Nationality',`PhoneNumber`='$PhoneNumber',`Email`='$Email' WHERE `Id`='$Id'");
if($query3) {
header('location:index1.php');
}
}
$query1=mysql_query("select * from students where Id='$Id'");
$query2=mysql_fetch_array($query1);
?>
<form method="post" action="">
First Name:<input type="text" name="name" value="<?php echo $query2['Fname']; ?>" /><br />
Last Name:<input type="text" name="name" value="<?php echo $query2['Lname']; ?>" /><br />
Age:<input type="text" name="age" value="<?php echo $query2['Age']; ?>" /><br />
Nationality:<input type="text" name="name" value="<?php echo $query2['Nationality']; ?>" /><br />
Phone Number:<input type="text" name="name" value="<?php echo $query2['PhoneNumber']; ?>" /><br />
Email:<input type="text" name="name" value="<?php echo $query2['Email']; ?>" /><br />
<br />
<input type="submit" name="submit" value="update" />
</form>
<?php
}
?>
</body>
</html>
Related
MY PHP doesn't update data. Here is my code:
<html>
<body>
<meta charset="utf-8">
<title>სატელეფონო ცნობარი</title>
<?php
include('connection.php');
if(isset($_GET['id'])) {
$id=$_GET['id'];
if(isset($_POST['submit'])) {
$tarigi=$_POST['addedon'];
$teleponi2=$_POST['tel2'];
$teleponi3=$_POST['tel3'];
$departamenti2=$_POST['department2'];
$departamenti3=$_POST['department3'];
$web=$_POST ['url'];
$email=$_POST['email'];
$address=$_POST['address'];
$comment=$_POST['comment'];
$query3=mysql_query("update phonebook set addedon='$tarigi', tel2='$teleponi2',tel3='$teleponi3', department2='$departamenti2' , department3='$departamenti3' url='$web', email='$email', address='$address', comment='$comment' where id=$id");
if($query3) {
header('location:listcnobari.php');
}
}
$query1=mysql_query("select * from phonebook where id='$id'");
$query2=mysql_fetch_array($query1);
?>
<fieldset style="width:325px;">
<form method="post" action="">
დამატების თარიღი:<input type="text" name="addedon" value="<?php echo $query2['addedon']; ?>" /><br />
ტელეფონი2:<input type="text" name="tel2" value="<?php echo $query2['tel2']; ?>" /><br />
ტელეფონი3:<input type="text" name="tel3" value="<?php echo $query2['tel3']; ?>" /><br>
დეპარტამენტი2:<input type="text" name="department2" value="<?php echo $query2['department2']; ?>" /><br />
დეპარტამენტი3:<input type="text" name="department3" value="<?php echo $query2['department3']; ?>" /><br />
ვებ.გვერდი:<input type="text" name="url" value="<?php echo $query2['url']; ?>" /><br />
ელ.ფოსტა:<input type="text" name="email" value="<?php echo $query2['email']; ?>" /><br />
მისამართი:<input type="text" name="address" value="<?php echo $query2['address']; ?>" /><br />
კომენტარი:<input type="text" name="comment" value="<?php echo $query2['comment']; ?>" /><br />
<input type="submit" name="submit" value="Update" />
</form>
<?php
}
?>
</body>
</html>
Change your query to
$query3=mysql_query("update phonebook set addedon='$tarigi', tel2='$teleponi2',
tel3='$teleponi3', department2='$departamenti2' , department3='$departamenti3', url='$web', email='$email',
address='$address', comment='$comment' where id=$id");
You missed a comma
department3='$departamenti3' url='$web'
You missed a comma.
change
department3='$departamenti3' url='$web'
to
department3='$departamenti3', url='$web'
I wish every time I reload or refresh the page. The disabled textbox still disabled. Because my purpose is to modify the textbox once time and then it will be disabled forever. Is this possible?
Below is my code
<tr>
<td><?php echo $lang_txt['leader_id'][$lang]; ?></td>
<td>:</td>
<td><?php if($_POST['txtLeaderID'] == ""){?><input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php }
else
{
?>
<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="<?php echo $merchant['LeaderID']; ?>" maxlength="20" /><?php
}
?>
</td>
</tr>
Your variant will be worked with
if(!$_POST['txtLeaderID']){echo('<input type="text" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')} else {echo('<input type="text" disabled="disabled" name="txtLeaderID" id="txtLeaderID" style="width:400px;" value="'.$merchant['LeaderID'].'" maxlength="20" />')}
For example:
<?php
if (!$_POST['username']){
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>
But it didn't work, if we open it in a new tab. You must save this propery anywhere (session, cookie, sql)and check the stored values. it will be work in a new tab.
For example with session:
<?php
session_start();
if (!isset($_SESSION['data'])) {
$_SESSION['data'] = true;
echo('
<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
Name: <input type="text" name="username" /><br />
Email : <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Send POST!" />
</form>
');}
else{
echo('
<form>
Name: <input type="text" name="username" disabled="disabled"/><br />
Email : <input type="text" name="email" disabled="disabled"/><br />
</form>
');}
?>
can anyone help me find the code thats causing my code not to work? my code wont update... ive been debuging this code for 3hours already stil cant fix it :(...i need your help guys.
php code:
<?php
if(isset($_GET['gogo'])){
include('include/connect.php');
$batchcode = $_GET['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
if($sql) {
while($rows = mysql_fetch_array($sql)){
$id[] = $rows['id'];
$name[] = $rows['name'];
$score1[] = $rows['score1'];
$score2[] = $rows['score2'];
$other_qual[] = $rows['score3'];
$interview[] = $rows['score4'];
$total[] = $rows['total'];
}
}
}
?>
<?php
if(isset($_POST['update'])){
include('include/connect.php');
//1
$u1id = $_POST['id1'];
$u1name = $_POST['name1'];
$u1score1 = $_POST['optA1'];
$u1score2 = $_POST['optB1'];
$u1other_qual = $_POST['other_qual1'];
$u1interview = $_POST['interview1'];
$u1total = $_POST['total1'];
//2
$u2id = $_POST['id2'];
$u2name = $_POST['name2'];
$u2score1 = $_POST['optA2'];
$u2score2 = $_POST['optB2'];
$u2other_qual = $_POST['other_qual2'];
$u2interview = $_POST['interview2'];
$u2total = $_POST['total2'];
//1
mysql_query("UPDATE score SET score1='$u1score1', score2='$u1score2', total='$u1total' WHERE id='$u1id'");
//2
mysql_query("UPDATE score SET score1='$u2score1', score2='$u2score2', total='$u2total' WHERE id='$u2id'");
header("Location: index.php");
}
?>
html code:
<form method="get">
<form method="post">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="gogo" /><br />
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>
<td>
Name: <br />
<input type="text" name="name1" value="<?php if(empty($name[0])){$name[0] = array(NULL);}else{echo $name[0];} ?>" readonly /> <br />
<input type="text" name="name2" value="<?php if(empty($name[1])){$name[1] = array(NULL);}else{echo $name[1];} ?>" readonly /> <br />
</td>
<td>
Score 1: <br />
<input type="text" name="optA1" value="<?php if(empty($score1[0])){$score1[0] = array(NULL);}else{echo $score1[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optA2" value="<?php if(empty($score1[1])){$score1[1] = array(NULL);}else{echo $score1[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Score 2: <br />
<input type="text" name="optB1" value="<?php if(empty($score2[0])){$score2[0] = array(NULL);}else{echo $score2[0];} ?>" onchange="optTotal1()" /> <br />
<input type="text" name="optB2" value="<?php if(empty($score2[1])){$score2[1] = array(NULL);}else{echo $score2[1];} ?>" onchange="optTotal2()" /> <br />
</td>
<td>
Other Qualification: <br />
<input type="text" name="other_qual1" value="<?php if(empty($other_qual[0])){$other_qual[0] = array(NULL);}else{echo $other_qual[0];} ?>" readonly /> <br />
<input type="text" name="other_qual2" value="<?php if(empty($other_qual[1])){$other_qual[1] = array(NULL);}else{echo $other_qual[1];} ?>" readonly /> <br />
</td>
<td>
Interview: <br />
<input type="text" name="interview1" value="<?php if(empty($interview[0])){$interview[0] = array(NULL);}else{echo $interview[0];} ?>" readonly /> <br />
<input type="text" name="interview2" value="<?php if(empty($interview[1])){$interview[1] = array(NULL);}else{echo $interview[1];} ?>" readonly /> <br />
</td>
<td>
Total: <br />
<input type="text" name="total1" value="<?php if(empty($total[0])){$total[0] = array(NULL);}else{echo $total[0];} ?>" readonly onKeyUp="optTotal1()" /> <br />
<input type="text" name="total2" value="<?php if(empty($total[1])){$total[1] = array(NULL);}else{echo $total[1];} ?>" readonly onKeyUp="optTotal2()" /> <br />
</td>
</tr>
</table>
<input type="submit" value="update" name="update" />
</form>
</form>
You cannot do a GET and POST at the same time. Use one or the other..
In your HTML remove the <form method="get"> and the corresponding </form> and just use POST. (<form method="post">)
See this: Post and get at the same time in php
So then in your PHP, change GET to POST like so:
if(isset($_POST['gogo'])){
include('include/connect.php');
$batchcode = $_POST['code'];
$sql = mysql_query("SELECT * FROM score WHERE batchcode = '".$batchcode."' ");
...
EDIT:
Or alternatively, you could keep your php code the same the way you have it and just make it 2 seperate forms in your HTML,.. The search form using GET and the other form using POST
So HTML would be this:
<form method="get">
Search batchcode: <input type="text" name="code" id="query" /><input type="submit" value="Go" name="gogo" /><br />
</form>
<form method="post">
<table>
<tr>
<td>
ID: <br />
<input type="text" name="id1" value="<?php if(empty($id[0])){$id[0] = array(NULL);}else{echo $id[0];} ?>" readonly /> <br />
<input type="text" name="id2" value="<?php if(empty($id[1])){$id[1] = array(NULL);}else{echo $id[1];} ?>" readonly /> <br />
</td>...
...
</form>
If your code won't update then it is very likely you are updating the wrong files. Make sure that you are updating the files on the server or even better updating the files on your local drive and then uploading them to the server.
Check that you have permissions to upload to the correct place too. Might be that your uploads are failing because of bad permissions.
Ok so Im trying to use radio buttons in my PHP code. I wrote a Madlib in PHP and I want to write in a radio button that when a user selects it, it will change the story etc. Happy ending or sad ending here the code I have so far. Any help would be appreciated.
<html>
<head>
<title>James Nygaard's Mablib</title>
</head>
<body bgcolor="<?php echo $bg; ?>" text="<?php echo $fg; ?>">
<h1 style="font-family:cursive;">Create your Madlib below:</h1>
<form action="" method="post">
Enter the name of a boy:
<input name="noun1" type="text" value="<?= $_POST['noun1'] ?>" /><br />
Enter an Adjective that describes a person:
<input name="adj1" type="text" value="<?= $_POST['adj1'] ?>" /><br />
Enter the name of a man:
<input name="noun2" type="text" value="<?= $_POST['noun2'] ?>" /><br />
Enter an Adjective that describes a person:
<input name="adj2" type="text" value="<?= $_POST['adj2'] ?>" /><br />
Enter the name of a woman:
<input name="noun3" type="text" value="<?= $_POST['noun3'] ?>" /><br />
Enter your favorite animal:
<input name="noun4" type="text" value="<?= $_POST['noun4'] ?>" /><br />
Enter a name:
<input name="noun5" type="text" value="<?= $_POST['noun5'] ?>" /><br />
Enter the name of your favorite city:
<input name="noun6" type="text" value="<?= $_POST['noun6'] ?>" /><br />
Enter a feeling that ends in "ness":
<input name="adj3" type="text" value="<?= $_POST['adj3'] ?>" /><br />
Enter a Verb that ends in "ing":
<input name="verb2" type="text" value="<?= $_POST['verb2'] ?>" /><br />
Enter the name of a boy:
<input name="noun7" type="text" value="<?= $_POST['noun7'] ?>" /><br />
Enter the name of a girl:
<input name="noun8" type="text" value="<?= $_POST['noun8'] ?>" /><br />
<input type="submit" value="Click here or press enter to see your MadLib" /><br />
</form>
<div style="color: #2F4F4F; font-family: cursive;">
<?php
$bg = "8FBC8F";
$fg = "2F4F4F";
if(isset($_POST['noun1'])) {
echo "<h1> The adventures of {$_POST['noun1']}. </h1>";
echo "This is where i will put the story. I already have the story but the code is really long so I left it out of this question.";
echo "<br> The end.";
}
?>
</div>
</body>
</html>
It's not especially clear in this small space, but I tried to follow your code style.
Select an option:
<label>
<input name="some_option" type="radio" value="option_1" <?php if(isset($_POST['some_option']) && $_POST['some_option'] == 'option_1') echo 'checked="checked" '; ?>/> Option 1
</label>
<label>
<input name="some_option" type="radio" value="option_2" <?php if(isset($_POST['some_option']) && $_POST['some_option'] == 'option_2') echo 'checked="checked" '; ?>/> Option 2
</label>
If you run that code you should see what's going on.
I want to make a text field and button that will allow the user to fetch his details on the text fields instead of writting his details every time he wants to make a new reservation.
like in this picture:
http://oi41.tinypic.com/23ie70j.jpg
I tried to make this but with my code but gives me double forms one with the details and one without.
<form method="post" action="reserv page.php">
enter the email: <input type = "text" name = "email"/>
<input type = "submit" name = "submit" value="submit" />
</form>
<?php
mysql_connect("localhost","userName","password");
mysql_select_db("database_Name");
if(isset($_POST['submit']))
{
$email = $_POST['email'];
$q = "SELECT * FROM tabe WHERE the_email = '$email'";
$run = mysql_query($q );
while($row = mysql_fetch_array($run))
{
?>
</br></br>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" value="<?php echo $row[1]; ?>" />
Last Name: <input name="lNamet" type="text" value="<?php echo $row[2]; ?>" />
User Name: <input name="uName" type="text" value="<?php echo $row[3]; ?>"/>
Email: <input name="email" type="text" value="<?php echo $row[4]; ?>" />
password: <input name="pass" type="password" value="<?php echo $row[5]; ?>"/>
contact: <input name="number" type="text" value="<?php echo $row[6]; ?>" />
<input name="confirm" type="submit" value="Confirm" />
</form>
</br></br>
<?php
}}
?>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" />
Last Name: <input name="lNamet" type="text" />
User Name: <input name="uName" type="text" />
Email: <input name="email" type="text" />
password: <input name="pass" type="password" />
contact: <input name="number" type="text" />
<input name="confirm" type="submit" value="Confirm" />
</form>
<form method="post" action="reserv page.php">
enter the email: <input type = "text" name = "email"/>
<input type = "submit" name = "submit" value="submit" />
</form>
<?php
mysql_connect("localhost","userName","password");
mysql_select_db("database_Name");
if(isset($_POST['submit']))
{
$email = $_POST['email'];
//limit the query to one entry :)
$q = "SELECT * FROM tabe WHERE the_email = '$email' LIMIT 1";
$run = mysql_query($q );
//check if email is registered
if(mysql_num_rows($run)>0)
{
//display filled up form
while($row = mysql_fetch_array($run))
{
?>
</br></br>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" value="<?php echo $row[1]; ?>" />
Last Name: <input name="lNamet" type="text" value="<?php echo $row[2]; ?>" />
User Name: <input name="uName" type="text" value="<?php echo $row[3]; ?>"/>
Email: <input name="email" type="text" value="<?php echo $row[4]; ?>" />
password: <input name="pass" type="password" value="<?php echo $row[5]; ?>"/>
contact: <input name="number" type="text" value="<?php echo $row[6]; ?>" />
<input name="confirm" type="submit" value="Confirm" />
</form>
</br></br>
<?php
}
}
//display blank form
else{
?>
<form action="payment.php" method="post" >
First Name:<input name="fName" type="text" />
Last Name: <input name="lNamet" type="text" />
User Name: <input name="uName" type="text" />
Email: <input name="email" type="text" />
password: <input name="pass" type="password" />
contact: <input name="number" type="text" />
<input name="confirm" type="submit" value="Confirm" />
</form>
<?php
}
}
?>
You're getting 2 forms because you're echoing one form if $_POST['submit'] is set and then another one regardless of anything. Print the second form only if $_POST['submit'] is not set. Since your code is so poorly written I will just give you an example:
if(isset($_POST['submit'])){
PRINT FETCHED FORM
}else{
PRINT EMPTY FORM
}
This, however, is not the "right" way to go. What people actually do is have variables null'd at start and then fill them up with data if there's a request and have a single form written in the file with input values as those variables.