forumnz Posted May 3, 2007 Share Posted May 3, 2007 Each thing in the db has its own id and I want a user to be able to edit what they choose to. Here is my code. Before I had the id and $nm it just added a new row but since i added the above, it decided not to work: <html> <body> <?php if ($submit) { // process form $db = mysql_connect("localhost", "designervi_mag", "***"); mysql_select_db("designervi_mag",$db); $sql = "INSERT INTO mag (stg1,stg2,stg3) VALUES ('$stg1','$stg2','$stg3') WHERE id='$nm'"; $result = mysql_query($sql); echo "Thank you! Information entered.\n"; } else{ // display form ?> <form method="post" action="<?php echo $PHP_SELF?>"> 1:<input name="nm" type="checkbox" value=""><br /> Link<input type="Text" name="stg1"><br> Image<input type="Text" name="stg2"><br> Text<input type="Text" name="stg3"><br> <input type="Submit" name="submit" value="Enter information"> </form> <?php } // end if ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
DaveEverFade Posted May 3, 2007 Share Posted May 3, 2007 You're not catching the mysql_error() in there. Try that to see what the error is. Also try echoing $sql to check it's ok. Another favourite of mine when debugging is putting this right at the top (just after <?php) error_reporting(E_ALL); ini_set('display_errors', '1'); If you can't resolve the issue using the errors, post them back in here... Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted May 3, 2007 Share Posted May 3, 2007 R u inserting the rows 1st time or want to update a row for current user. Quote Link to comment Share on other sites More sharing options...
forumnz Posted May 3, 2007 Author Share Posted May 3, 2007 Hi all, thanks DaveEverFade. Ive tried that but it came up with: Notice: Undefined variable: nm in /home/designervi/domains/designervision.co.nz/public_html/mag/i.php on line 22 UPDATE mag (stg1,stg2,stg3) VALUES ('..','..','..') WHERE id=Thank you! Information entered. mmarif4u: Update for current user Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted May 3, 2007 Share Posted May 3, 2007 Then i think u have to use update instead of insert command. Quote Link to comment Share on other sites More sharing options...
forumnz Posted May 3, 2007 Author Share Posted May 3, 2007 Thanks, i got that a min ago. Heres my new code - still doesn't work. Help? <html> <body> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); if ($submit) { // process form $db = mysql_connect("localhost", "designervi_mag", " "); mysql_select_db("designervi_mag",$db); $sql = "UPDATE mag (stg1,stg2,stg3) VALUES ('$stg1','$stg2','$stg3') WHERE id=$nm"; $result = mysql_query($sql); echo $sql; echo "Thank you! Information entered.\n"; } else{ // display form ?> <form method="post" action="<?php echo $PHP_SELF?>"> 1:<input name="$nm" type="checkbox" value=""><br /> Link<input type="Text" name="stg1"><br> Image<input type="Text" name="stg2"><br> Text<input type="Text" name="stg3"><br> <input type="Submit" name="submit" value="Enter information"> </form> <?php } // end if ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted May 3, 2007 Share Posted May 3, 2007 update query would be like this: $sql = "UPDATE mag set stg1='$stg1',stg2='$stg2',stg3='$stg3' WHERE id='$nm'"; Quote Link to comment Share on other sites More sharing options...
forumnz Posted May 3, 2007 Author Share Posted May 3, 2007 It still comes up with: Notice: Undefined variable: nm in /home/designervi/domains/designervision.co.nz/public_html/mag/i.php on line 22 UPDATE mag set stg1='',stg2='',stg3='' WHERE id=''Thank you! Information entered. Quote Link to comment Share on other sites More sharing options...
jitesh Posted May 3, 2007 Share Posted May 3, 2007 ----------------------------------------------------------------------------- extract($_POST); $sql = "UPDATE mag set stg1='$stg1',stg2='$stg2',stg3='$stg3' WHERE id='$nm'"; ------------------------------------------------------------------------------ Quote Link to comment Share on other sites More sharing options...
yzerman Posted May 3, 2007 Share Posted May 3, 2007 you have do define $nm. I can only assume you get the id from the url - if this is the case - add this to the top of your script: <?PHP if (is_numeric($_REQUEST['id'])) { // check and see that the id is numeric $nm = $_REQUEST['id']; //put the rest of your code here } else { //if the ID is not numeric - its probably not valid - so add this at the end of the if statement that holds the rest of your code. echo '<font color="red" size="+1">You have entered an incorrect ID, please go back and try again</font>'; exit(); } ?> Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted May 3, 2007 Share Posted May 3, 2007 UPDATE mag set stg1='',stg2='',stg3='' WHERE id=''Thank you! Information entered. Look at the stg1='' valus its empty it mean that ur data is not coming from form ok do it like this: $stg1=$_POST['stg1']; $stg1=$_POST['stg1']; $stg1=$_POST['stg1']; $sql="UPDATE mag set stg1='$stg1',stg2='stg2',stg3='stg3' WHERE id='$nm'"; Quote Link to comment Share on other sites More sharing options...
forumnz Posted May 3, 2007 Author Share Posted May 3, 2007 Nope - not working! Help please? Quote Link to comment Share on other sites More sharing options...
forumnz Posted May 4, 2007 Author Share Posted May 4, 2007 please? Quote Link to comment Share on other sites More sharing options...
jitesh Posted May 4, 2007 Share Posted May 4, 2007 $sql="UPDATE mag set stg1='$stg1',stg2='$stg2',stg3='$stg3' WHERE id='$nm'"; echo $sql; // echo this query and then post this echo query here. Quote Link to comment Share on other sites More sharing options...
yzerman Posted May 4, 2007 Share Posted May 4, 2007 forumz, I answered you in my first post. you are not defining the variable $nm you need to define that variable before this will work, and that variable needs to correlate to an ID that is pulled from the database. In your code your defining nm, by using a checkbox - why I do not know, but the only 2 outputs you will ever get from a checkbox is either "on" or "off", meaning your query is never going to work. Quote Link to comment 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.