Well I am new to coding,What I am trying is to update data in database through Php .I am trying hard to update data but i don't know where is problem coming ,there is no error too.My first file is
"ppp.html"
<html>
<form action="l.php"method="post">
<input type ="text" name ="complaint">
</input>
<input type="submit"></input>
</html>
Now my "L.php "
It also don't show any error .It goes through easily
<?php
$complaint="";
if(
isset($_POST['complaint']))
{$complaint =$_POST['complaint'];}
mysql_connect("localhost","root","") or die ("couldnt attack ");
mysql_select_db("site")or die('i surrender');
$query=("SELECT * FROM site2 where category='$complaint'") or die("couldnt select");
$result=mysql_query($query) or die ('hghyt');
while ($complaint= mysql_fetch_array($result))
{
echo"<td>".'<br>'.$complaint['category']."</tr>";
ECHO"<TR>"."<A HREF='update.php'>"."UPDATE"."</A>";
echo "<br/>";
ECHO"</table>";
}
?>
Sorry for very wrong query and very inappropriate way of coding but I am learning it all by myself through internet
Now my "update.php file"
<html>
<form action="update1.php" method="post">
<input type= "text" name="blue"></input>
<input type= "submit"></input>
</form>
</html>
It also goes of in easy way,and don't show any problem ,now my last file "update1.php"
<?php
$complaint="";
if(isset ($_POST['complaint']))
{$complaint =$_POST['complaint'];}
$blue="";
if(isset ($_POST['blue']))
{$blue =$_POST['blue'];}
mysql_connect("localhost","root","") or die ("couldnyt coibnovdbs");
mysql_select_db("site") or die ("no databse");
$query=("update site2 set category='$blue' where category ='$complaint'") or die ("couldnt attack");
$result=mysql_query($query) or die("kjkk");
?>
Please help me .It is bothering me,I cant find any solution for it.I think problem is in last file only but it is not showing any errors.
Thank you
Considering the flow of your website, update1.php never receives the value in $complaint, hence fails to update. You need to pass the value to it.
For example, the following edits should suffice.
Edit L.php
echo"<td>".'<br>'.$complaint['category']."</tr>";
ECHO"<TR>"."<A HREF='update.php?complaint=".$complaint['category']."'>"."UPDATE"."</A>";
Edit update.php
<html>
<form action="update1.php" method="post">
<input type="hidden" name="complaint" value="<?php echo $_GET['complaint'] ?>"
<input type= "text" name="blue"></input>
<input type= "submit"></input>
</form>
</html>
Related
I'm using php 5.5.3..In my scenario i have created a form to insert a task on which user have to fill 3 field namely description of task,due date and priority of task..immediately after that i have added a submit button..whenever i'm going to click on submit button the values should entered in database is my task. Now i wanna asked that how should i add due due date in database..i have tried with specific format but it doesn't work..my configuration id like :
Task.html :
<html>
<head>
<title>Creating a Personal To-Do List</title>
<h3>Add new Task</h3>
</head>
<body>
<form method="post" action="task.php">
Description :
<br/>
<input type="text" name="name"/>
<p>
Due date :
<br/>
<input type="text" name="date" size="20"/>
<p><br/>
Priority :
<br/>
<select name="priority">
<option name="high">High</option>
<option name="medium">Medium</option>
<option name="low">low</option>
</select>
<p>
<input type="submit" name="submit" value="Save Task">
</form>
</body>
</html>
And Task.php :
<?php
$db_hostname="localhost";
$db_database="music";
$db_username="root";
$db_password="p3";
if(isset($_POST['submit']))
{
if(empty($_POST['name']))
die("Error : Task name is required");
$name=$_POST['name'];
if(empty($_POST['date']))
die("Error : Please enter a valid date");
$task_date = $_POST['date'];
if(empty($_POST['priority']))
die("Error : Please select a priority");
$priority=$_POST['priority'];
$db_server=mysql_connect($db_hostname,$db_username,$db_password);
if(!$db_server)
{
die("Error:unable to connect to server");
}
else
echo "Connected to server";
mysql_select_db($db_database)
or die("Error:unable to connect to database");
echo "</br>Connected to $db_database database";
$task_date = date('Y-m-d');
echo $task_date;
$insert_query=mysql_query("Insert into task(name,due,priority)values('$name','$task_date','$priority'))");
if(($insert_query)==TRUE)
{
echo "<br/>";
echo "New Task inserted ";
}
}
?>
Please let me know where should i make changes?or is their any another way to do this?..
Try this:
$insert_query=mysql_query("Insert into task(name,due,priority)values('$name','$task_date','$priority')")
Instead of this:
$insert_query=mysql_query("Insert into
task(name,due,priority)values('$name','$task_date','$priority'))")
Consider using PDO or Mysqli, Mysql is deprecated.
Try this it works.
$insert_query=mysql_query("INSERT INTO task(name,due,priority) VALUES ('".$name."','".$task_date."','".$priority."')") or die(mysql_error());
mysql_error() function will tell the errors if data not inserted... and you are using this '$priority'))"); double braces...
I am looking to delete a particular row from a database using the code below. The code below is within a file called "delete.php" and it is taking input from an input box that is located on another php file called "yourReports.php".
When the form is submitted on "yourReports.php" it should delete the row from the database, however it doesn't appear to be working.
delete.php
<?php
$mysqli = mysqli_connect("localhost", "root", "DBPASS","DBNAME") or die ('Could not connect to database!');
$_POST['delete'];
$deletereport = mysqli_real_escape_string($mysqli, $_POST['delete']);
mysqli_query($mysqli,"DELETE FROM reports WHERE reportName = '".$deletereport."'");
header('Location: yourreports.php');
?>
yourReports.php
<form action="delete.php" method="post" name="form1">
<label><strong>Enter Report Name To Delete:</strong></label>
<input name="delete" id="delete" type="text">
<input value="Delete Report" name="delete" class='myButton' type="submit">
</form>
Any help would be appreciated.
Thanks
Set the method and name attribute of form to post
<form action="delete.php" method="post" name="form1">
Check if the query fails:
if(! mysqli_query($mysqli,"DELETE FROM reports WHERE reportName = '".$deletereport."'")){
echo mysqli_error();
}
[Updated]
You cannot have two inputs with the same name. Your input and delete button both have the name delete. So try considering different names for inputs.
change
mysqli_query($mysqli,"DELETE FROM reports WHERE reportName = '".$deletereport."'");
To
mysqli_query($mysqli,"DELETE FROM reports WHERE reportName = '{$deletereport}'");
I'm working on a Uni assignment and am having trouble inserting records to MySQL database using a form. My set up is below.
I can view entries in the database with no problem. I'm new to this so sorry in advance :(
conninfo.php
<?php
$strServer="localhost";
$strDatabase="djdatabase"; // CHANGE TO YOUR DATABASE NAME HERE
$strUser="root";
$strPwd=""; // Leave blank for WAMPServer
$strDB=mysql_connect($strServer,$strUser,$strPwd)or die("Could not open database");
$database=mysql_select_db("$strDatabase",$strDB);
?>
addnewdata.php
<?php include "conninfo.php";
$newdj=$_POST["dj"]; //pick up from form
$newfn=$_POST["fn"];
$newem=$_POST["em"];
$newwe=$_POST["we"];
$newpi=$_POST["pi"];
$newev=$_POST["ev"];
$query = "INSERT INTO dj(DJName, FirstName, Email, Website, Picture, EventNumber)VALUES('$newdj', '$newfn', '$newem', '$newwe', '$newpi', '$newev)";
mysql_query($query);
header("location:showall.php");
?>
enternewdata.php
<?php include "conninfo.php";?>
<html>
<head>
</head>
<body>
<form action="addnewdata.php" method="post">
DJ Name:<input type="text" name="dj"><br>
FirstName: <input type="text" name="fn" /><br>
Email: <input type="text" name="em" /><br>
Website: <input type="text" name="we" /><br>
Picture: <input type="text" name="pi" /><br>
EventID: <input type="text" name="ev" /><br>
<br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
Many Thanks for your help :)
had better use SET command to insert data
$query = "INSERT INTO dj SET
DJName=".$newdj.",
FirstName=".$newfn.",
Email=".$newem.",
Website=".$newwe.",
Picture=".$newpi.",
EventNumber=".$newev."";
$save = mysql_query($query);
if($save){
header("location:showall.php");
}else{
die(mysql_error());
}
You are missing a quote ' wich is causing the error that you cannot see because you haven't done any debug. Anyway you should just change to this
'$newwe', '$newpi', '$newev')"; //a quote was missing after '$newv
I would suggest you to also debug query by adding or die('INVALID QUERY: ' . mysql_error());
so code would look like
mysql_query($query) or die('INVALID QUERY: ' . mysql_error());
Since you said this is an university test I don't know if you are supposed to use mysql_* function (wich are deprecated), but I would strongly reccommend to switch to mysqli or PDO if you can for security reason.
You missed ' on your query on $newev that gives you an error
$query = "INSERT INTO dj(DJName, FirstName, Email, Website, Picture, EventNumber)VALUES('$newdj', '$newfn', '$newem', '$newwe', '$newpi', '$newev)";
I'm trying to display data from my database table selected from a 'date'.
The query executes, but when I echo I don't get any result. Could you please help me with this?
<?php include 'includes/connection.php'; ?>
<html>
<head>
<title> </title>
</head>
<body>
<?php
if(isset($_POST['submitted'])){
$sql = "SELECT * FROM dagtaken WHERE datum = $_POST[datum]";
$result = mysql_query($sql) or die (mysql_error());
while ($row = mysql_fetch_array($result)){
echo $row['aantal'];
}
}else{
?>
<form action='' method='POST'>
<p><input type="date" name="datum"></p>
<p><input type='submit' value='Dagtaak toevoegen' />
<input type='hidden' value='1' name='submitted' /></p>
</form>
<?php } ?>
</body>
</html>
The query shouldn't execute, since dates are very obviously strings and require quotes. That said...
Try this:
mysql_query("SLEECT * FROM `dagtaken` WHERE `datum`='".mysql_real_escape_string($_POST['datum'])."'");
Now on to the actual problem, you are checking if(isset($_POST['submitted'])), but nowhere do I see <input name="submitted" in your source (EDIT Never mind, it has a stupid amount of whitespace pushing it off the edge). Try if(isset($_POST['datum'])), since that's the variable you actually use.
You haven't named your submit button, so your PHP code never kicks in. Don't check for form fields when all you really need is to check if a POST has occured.
Quick fix for you code:
<input type="submit" name="submitted" value="Dagtaak toevoegen" />
^^^^^^^^^^^^^^^^^
Better fix:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
your code here ...
}
First, Escape your data. SQL injection is now very easy
Second, do you have data in your database?
Try print_r($row) instead of echo $row...
$_POST is with quotes...=> $_POST["datum"]
Last addition, is your date the same as your input?
hey guys i want to creat my own form in joomla and use the post method .
so i download extension to make my own code in articles in joomla like this
<form action="http://localhost/ocr/includes/Create_Subject.php" method="post">
username <input type="text" name="menu_name" value=""/><br/>
password <input type="text" name="id" value=""/><br/>
<input type="submit" name="save" value="Submit" />
</form>
and then i go to my website data base and create a table called show to add into it my values which i get it from my form and also
make a php file called (Create_Subject.php) and i put it in includes file in my website and called it by action like u see in my code in my html and the code of that php here
<?php
$coonect=mysql_connect("localhost","root","");
if(!$coonect){
echo "Data_base error";
die(mysql_error());
}
?>
<?php
$username=$_POST['menu_name'];
$id=$_POST['id'];
$db_select=mysql_select_db("ocr");
if(!$db_select){
die(mysql_error());
echo" error";
}
$query= "INSERT INTO show (
name , id )
VALUES( '{$username}' ,{$id} ) " ;
if(mysql_query($query)){
header("www.google.com");
exit;
}else{
echo"<p> error </p>";
}
?>
`
and when iam run the site show to my an error what am doing wrong any heleeeep plez ....:))
Here you can find plenty of information about SQLQuering with Joomla!
http://docs.joomla.org/Accessing_the_database_using_JDatabase
You can ask anything you want if you have any trouble...