Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
this code is for showing data and updating data.when query string is setted text boxes appersand submit button will also appears
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<from action="category_listing.php" method="post">
<table border="5" width="250">
<?php
$queryy="select COUNT(*) from category"; //count rows
$results= mysqli_query($link, $queryy);
while ($res= mysqli_fetch_array($results))
{$total_rows=$res[0];}
$offset=$total_rows-1;
$qry="select ID from category LIMIT $offset,1";
$res= mysqli_query($link, $qry);
while ($res2= mysqli_fetch_array($res))
{
$lastvalue=$res2[0];
}
$query="select * from category";
$result= mysqli_query($link, $query);
while ($r= mysqli_fetch_array($result))
{
if(isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) && ($_REQUEST['id']>=0 ) && $_REQUEST['id']<=$lastvalue)
{
$id=$_REQUEST['id'];
if($r[0]==$id)
{
$name=$r[1];
echo '<tr><td>';
echo 'Name';
echo '</td>';
echo '<td><input type=text value="'.$r[1].'"></td></tr>';
echo '<tr><td colspan="2">';
echo '<input type="submit" name="btnupdate" value="Update">';
echo '<input type="submit" value="Cancel">';
echo '</td></tr>';
}
}
else
{
static $var=1;
if($var==1){echo '<tr><th>ID</th><th>Name</th> <th>Action</th></tr>';} //headers of category
echo "<tr><td>$r[0]</td><td>$r[1]</td>";
echo "<td><a href='category_listing.php?id=$r[0]'>Edit</a></td></tr>";
$var++;
}
}
?>
</table>
<input type="hidden" name="hidden" value="<?php if(isset($id)) echo $id;?>"/>
</from>
</body>
</html>
I just set query string. when it is setted in URL. Text box appears and after pressing submit, page is not submitting.
change
<from action="category_listing.php" method="post">
to
<form action="category_listing.php" method="post">
</from> to </form>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to add some data to mysql table from another mysql table and at the same time i want to add some form $_POST values to the same table in the same row.
Note : IM NEW TO PHP AND MYSQLI
Basically im looking for the correct syntax, please do help me and thanks in advance.
<?php
if(isset($_POST['ask'])) {
require('includes/connection.php');
$problem = $_POST['problem'];
$expecting = $_POST['expecting'];
//SELECT * FROM users WHERE email = '$email' AND
$string = "INSERT INTO ask(users_id,username,email,age,sex,problem,expecting) SELECT id,username,email,age,sex FROM users AND VALUES('$problem','$expecting') WHERE users.email = '$_SESSION[email]'";
$query = mysqli_query($dbc,$string);
if($query) {
echo 'yes';
} else {
echo 'something is wrong' . $query . mysqli_error();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="ask">
<h1>Ask</h1>
<form method="post" action="logged.php">
<p><label>Problem: </label><input type="text" name="problem" value="<?php if(isset($problem)) { echo $problem; } ?>"></p>
<p><label>Expecting: </label><input type="text" name="expecting" value="<?php if(isset($expecting)){ echo $expecting; } ?>"></p>
<p><input type="submit" name="ask" value="Ask"></p>
</form>
</div>
<form method="post" action="logged.php">
<input type="submit" name="logout" value="Logout">
</form>
</body>
</html>
Your first problem is wrong database design. Instead of duplicating user's data in the questions table, you have only to link it. Read up on database normalization, and change your ask table by removing username,email,age,sex fields.
Then get user_id from users table with SELECT query.
Then run a conventional INSERT query
INSERT INTO ask(users_id,problem,expecting)
Note that you have to use prepared statements for database interactions.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I'm trying to update my MySQL Table via PHP - It says successful, but isn't actually updating. Here is snippets of my PHP code used;
List of rows in my Table.
<?php
$sql="SELECT * FROM $tbl";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
echo $rows['title'];
echo $rows['date'];
echo $rows['month'];
?>
update
Edit Forum
<?php
$id=$_GET['id'];
$sql="SELECT * FROM $tbl WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<form name="form" method="post" action="update.php">
<input name="title" type="text" id="title" value="<? echo $rows['title']; ?>">
<input name="date" type="text" id="date" value="<? echo $rows['date']; ?>" >
<input name="month" type="text" id="month" value="<? echo $rows['month']; ?>">
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
<input type="submit" name="Submit" value="Submit">
Process of the Table update
<?php error_reporting(E_ALL); ini_set('display_errors', 1); //added to all pages
$title = $_POST['title']
$date = $_POST['date']
$month = $_POST['month']
$id = $_POST['id']
$sql="UPDATE $tbl SET title='$title', date='$date', month='$month' WHERE id='$id'";
$result=mysql_query($sql);
if (!$sql) {
die(mysql_error());
}
?>
If I update my table directly running SQL Queries in PhpMyAdmin it works perfectly fine. But when I do it through PHP it outputs as successful but doesn't actually change the data. Where am I going wrong?
PS: I have tried using mysql_error()); but nothing reports back.
You are missing the semicolons (;) after assigning your $_POST variables:
$title = $_POST['title']
$date = $_POST['date']
$month = $_POST['month']
$id = $_POST['id']
Add a ; right after each of those statements and you should be good to go.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Im just learning and....
It just wont connect is there something stupid that im doing wrong?
Add.php
<?php
mysql_connect("db517452461.db.1and1.com","dbo517452461","******") or die
(mysql_error());
echo "Oops ";
mysql_select_db("admin") or die (mysql_error());
echo "Ooops ";
$ref= ($_POST['ref']);
$firstname = ($_POST['firstname']);
mysql_query("insert admin set ref='".$ref."', firstname='".$firstname."'");
echo "<script>alert('Record successfuly saved.');window.location.href='paragview.php';
</script>";
?>
index.php
<html>
<body>
<div style="border:1px solid;">
<form action="add.php" method="post">
Ref: <input type="text" name="ref"><br>
Firstname <input type="text" name="firstname"><br>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form>
</div>
</body>
</html>
Ive checked my host, username and password over and over again.
SShttp://i.cubeupload.com/FTYOhp.jpg
Your database name is something else rather than the one mentioned in the image.
Change this line:
mysql_select_db("admin") or die(mysql_error());
To:
mysql_select_db("db517452461") or die(mysql_error());
As a side note, I recommend you to use mysqli or PDO as mysql is now deprecated.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i got this script below. How do i get the answer from the selected item?
how can i get the option back with the $_POST?
<?php
mysql_select_db("internetsites");
$query1 = "SELECT * FROM internetsites ORDER BY name_site";
$result = mysql_query($query1) or die(mysql_error());
?>
<form name="delete" action="delete.php" method="post">
choose a site you want to delete.
<select>
<?php
while($row = mysql_fetch_array($result))
{
echo "<option value=" . $row['name_site'] . "'>" . $row['name_site'] . "</option>";
}
?>
</select>
<input type="submit" value="delete">
Can someone help me?
You give your select a name atribute, then you take the whole code inside <form method="post" action="delete.php"></form> and then you use $_POST['nameattribute'].
Try this, To Post form elements need input name attribute,
<form name="delete" action="delete.php" method="post">
choose a site you want to delete.
<select name="name_site" id="name_site">
<?php
while($row = mysql_fetch_array($result))
{
echo "<option value='".$row['name_site']."'>" . $row['name_site'] . "</option>";
}
?>
</select>
<input type="submit" name="submit" value="delete">
</form>
in delete.php,
<?php
if(isset($_POST['submit'])){
echo $_POST['name_site'];
}
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
In the following code, everything works except that when you click the submit button, nothing happens at all
Please tell me what's wrong, the connection and everything is fine (it is included in the Header.php file) and submit forms on other pages work, but this one seems to just do nothing, page doesn't even load
Thanks!
Here is the code
<?php
//connection is in header
include "../Header.php";
//checks if logged in
if (!$User)
{
header("Location: ../index.php"); exit();
}
//heres the form
echo"<form><center><br /><br /><br /><br /><font size='3'><br />You are changing your Post Color<br />
Your current color is $myU->PostColor<br /><br /></font><form>
Color:<br /><textarea name='color' rows='1' cols='15'></textarea><br /><br />
<input type='submit' name='Submit' value='submit'></form></center></form>";
$Color = mysql_real_escape_string(strip_tags($_POST['Color']));
$submit = mysql_real_escape_string(strip_tags($_POST['submit']));
if ($submit) {
mysqli_query("UPDATE `socialli_main`.`Users` SET `PostColor` = '$Color' WHERE `Users`.`ID` ='$myU->ID'");
header("Location: ../index.php"); exit();
}
include "../Footer.php";
A submit button will submit the form that it is inside. You don't have a <form> element at all. You need to add one.
More importantly than adding a <form> tag is actually setting attributes on it. Try the following.
<form action='' method='POST'>
And you also end your </form> tag many times...
Here is how I would fix up your code anyways:
<?php
//connection is in header
include "../Header.php";
//checks if logged in
if (!$User)
header("Location: ../index.php"); exit();
?>
<form action='' method='POST'>
<div style="text-align:center;">
<br /><br /><br /><br /><br />
<span style="font-size:1.6em;">
You are changing your Post Color
</span><br>
<span style="font-size:1.3em;">
Your current color is <?=$myU->PostColor?>
</span><br>
Color:<br />
<textarea name='color' rows='1' cols='15'></textarea>
<br /><br />
<input type='submit' name='Submit' value='submit'>
</div>
</form>
<?php
$Color = mysql_real_escape_string(strip_tags($_POST['Color']));
$submit = mysql_real_escape_string(strip_tags($_POST['submit']));
if ($submit){
mysqli_query("UPDATE `socialli_main`.`Users` SET `PostColor` = '$Color' WHERE `Users`.`ID` ='$myU->ID'");
header("Location: ../index.php"); exit();
}
include "../Footer.php";
?>