raptor30506090 Posted March 30, 2011 Share Posted March 30, 2011 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/ Share on other sites More sharing options...
Maq Posted March 30, 2011 Share Posted March 30, 2011 In the future, use tags around your code. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194426 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 Sorry about that.. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194427 Share on other sites More sharing options...
Maq Posted March 30, 2011 Share Posted March 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194428 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 Hi i get this error Undefined index: id in C:\wamp\www\CMS\admin\modify.php on line 6 Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194431 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 Hi i get an error message here $query = "SELECT * FROM people WHERE ID = $_GET[id]"; if i replace it with just WHERE id=1 it will return the db content in the form.. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194434 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 the query broken? Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194462 Share on other sites More sharing options...
GalaxyTramp Posted March 30, 2011 Share Posted March 30, 2011 It would seem that the id is not being set. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194463 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 ok how do i go about fixing that i am new but trying hard Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194466 Share on other sites More sharing options...
KevinM1 Posted March 30, 2011 Share Posted March 30, 2011 Do you understand GET, POST, and the differences between the two? Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194470 Share on other sites More sharing options...
Maq Posted March 30, 2011 Share Posted March 30, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194471 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 yes post info get info i cant see whats wrong i followed a tut to do this Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194476 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 This is my url http://localhost/cms/admin/modify.php Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194478 Share on other sites More sharing options...
Maq Posted March 30, 2011 Share Posted March 30, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194481 Share on other sites More sharing options...
raptor30506090 Posted March 30, 2011 Author Share Posted March 30, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194493 Share on other sites More sharing options...
Maq Posted March 30, 2011 Share Posted March 30, 2011 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"; Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194498 Share on other sites More sharing options...
raptor30506090 Posted March 31, 2011 Author Share Posted March 31, 2011 Can any one help please.. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194832 Share on other sites More sharing options...
raptor30506090 Posted March 31, 2011 Author Share Posted March 31, 2011 if you make a very simple database and try this code it we have errors can you help please Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194833 Share on other sites More sharing options...
raptor30506090 Posted March 31, 2011 Author Share Posted March 31, 2011 <?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> Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194841 Share on other sites More sharing options...
runthis Posted March 31, 2011 Share Posted March 31, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194844 Share on other sites More sharing options...
raptor30506090 Posted March 31, 2011 Author Share Posted March 31, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194850 Share on other sites More sharing options...
raptor30506090 Posted March 31, 2011 Author Share Posted March 31, 2011 Thanks for yor reply i have just tryed your php code $query = "SELECT * FROM people WHERE ID ='{$_GET['id']}'"; still not working for me sorry to be a pain..... Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194853 Share on other sites More sharing options...
raptor30506090 Posted March 31, 2011 Author Share Posted March 31, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1194855 Share on other sites More sharing options...
raptor30506090 Posted March 31, 2011 Author Share Posted March 31, 2011 any one help... :'( please Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1195156 Share on other sites More sharing options...
Maq Posted March 31, 2011 Share Posted March 31, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/232193-can-any-one-help-please/#findComment-1195157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.