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
Share on other sites

I have no clue what this means...

IF I TAKE THAT AWAY AND SELECTS ID NUMBER THEN THE FORM CONNECTS TO DB.

 

Is the query broken?  You can't connect?  What happens?  Please elaborate.

Link to comment
Share on other sites

Obtaining variables via GET is essentially through HTTP.  Show us the URL that is being called.

 

i.e. Your GET is looking for a variable 'id', so your URL should looking something similar to:

www.blah.com/index.php?id=17

Link to comment
Share on other sites

This is my url   

 http://localhost/cms/admin/modify.php

Then the error makes sense, right?

Undefined index: id

I don't see an 'id' variable in that URL.

 

How is this URL being generated?

Link to comment
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";

Link to comment
Share on other sites

 

<?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
Share on other sites

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Did you try what I said and use POST instead of GET?  The URL you're using to call the page does NOT contain an 'id' variable and your form action is POST, hence the 'undefined variables: id' error.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.