Jump to content

Can any one help please.


raptor30506090

Recommended Posts

<?php $conn = mysql_connect("localhost","root","") or die(mysql_error());
      $db =   mysql_select_db("testdata", $conn) or die(mysql_error());

//THIS IS WERE SOME OF THE PROBLEM IS AT THE GET ID IF I TAKE THAT AWAY AND SELECTS ID NUMBER THEN THE FORM CONNECTS TO DB.
    if (!isset($_POST['submit'])){
$query = "SELECT * FROM people WHERE ID = $_GET[id]";
$result = mysql_query($query);
$username = mysql_fetch_array($result);

}
?> 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UPDATE</title>
</head>

<body>
<h2>You are updating user.</h2>


<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Username:<input name="inputUser" type="text" value="<?php echo $username['user']; ?>" /><br />
Password:<input name="inputPass" type="text" value="<?php echo $username['pass']; ?>" /><br />
<input name="id" type="hidden" value="<?php echo 'id'; ?>" />
<input name="submit" type="submit" value="Update" />
</form>



<?php 
if(isset($_POST['submit'])){

$user = "UPDATE people SET `user`='$_POST[inputUser]', ` pass`='$_POST[inputPass]' WHERE ID = $_POST[id]"; mysql_query($user) or die(mysql_error());

echo "User has been updated";
header("Location: index.php");
}



?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/
Share on other sites

im just running it in my localhost im connecting to DB top of the code i put a comment i dont now any other way to update content in my database just trying to get this to work..

Your form method is POST so you should be using POST.  Change these lines to:

    if (!isset($_POST['submit'])){
        $id = mysql_real_escape_string($_POST['id']);
$query = "SELECT * FROM people WHERE ID = $id";

 

<?php $conn = mysql_connect("localhost","root","") or die(mysql_error());
      $db =   mysql_select_db("testdata", $conn) or die(mysql_error());

//THIS IS WERE SOME OF THE PROBLEM IS AT THE GET ID IF I TAKE THAT AWAY AND SELECTS ID NUMBER THEN THE FORM CONNECTS TO DB.
    if (!isset($_POST['submit'])){
$query = "SELECT * FROM people WHERE ID = $_GET[id]";
$result = mysql_query($query);
$username = mysql_fetch_array($result);

}
?> 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>UPDATE</title>
</head>

<body>
<h2>You are updating user.</h2>


<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
Username:<input name="inputUser" type="text" value="<?php echo $username['user']; ?>" /><br />
Password:<input name="inputPass" type="text" value="<?php echo $username['pass']; ?>" /><br />
<input name="id" type="hidden" value="<?php echo 'id'; ?>" />
<input name="submit" type="submit" value="Update" />
</form>



<?php 
if(isset($_POST['submit'])){

$user = "UPDATE people SET `user`='$_POST[inputUser]', ` pass`='$_POST[inputPass]' WHERE ID = $_POST[id]"; mysql_query($user) or die(mysql_error());

echo "User has been updated";
header("Location: index.php");
}



?>

</body>
</html>

 

Ok, in the url are you actually referencing an id, like www.foobar.com/index.php?id=2

if so change your result variable to

 

$result = mysql_query($query)or die(mysql_error());

 

and find the error, or reference get id as

 

$query = "SELECT * FROM people WHERE ID ='{$_GET['id']}'";

 

tested and works for me, but i would suggest getting your $_GET variable out of the database call and make sure its a number only and not a sql injection, this can help as of php5 for the sql injection atleast

 

$id = filter_input(INPUT_GET, ‘id’, FILTER_SANITIZE_STRING);

 

then you would update the same, but replace $_GET[id] with $id

 

 

ok i dont seem to be getting very far with this the problem is that its not getting the ip from the database by the

$_GET[iD]

the query is

$query = "SELECT * FROM people WHERE ID = $_GET[id]";

and i have a hidden

<input name="id" type="hidden" value="<?php echo 'id'; ?>" />

is this any help..

 

Many thanks

Ok iv done what you say

if (!isset($_POST['submit'])){	
$query = "SELECT * FROM people WHERE ID = '$id'";
$result = mysql_query($query) or die(mysql_error());
$username = mysql_fetch_array($result);
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_STRING);
}

 

But still getting the same error

Undefined variable: id in line 5

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.