chrissie18 Posted November 24, 2008 Share Posted November 24, 2008 hello i have a code and it`s not correct getting: Notice: Undefined index: dername Notice: Undefined index: welcomet in my php script can you help me out this is my code: if(isset($logged['id'])) { if(isset($_GET['update'])) { $email = addslashes(htmlspecialchars($_POST[email])); $location = addslashes(htmlspecialchars($_POST[location])); $dername = addslashes(htmlspecialchars($_POST[dername])); $welcomet = addslashes(htmlspecialchars($_POST[welcomet])); //updates there profile in the db $update = mysql_query("UPDATE `members` SET `email` = '$email', `welcomet` = '$welcomet', `dername` = '$dername', `location` = '$location' WHERE `username` = '$logged[username]'"); echo "Profile updated!"; } $getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'"); $user = mysql_fetch_array($getuser); echo "<form action='editprofile.php?update' method='post'> Email: <input type='text' name='email' size='30' maxlength='55' value='$user[email]'><br> Location: <input type='text' name='location' size='30' maxlength='40' value='$user[location]'><br> dealer naam: <input type='text' name='dername' size='30' maxlength='40' value='$user[dername]'><br> Welkom text: <input type='text' name='welcomet' size='90' maxlength='240' value='$user[welcomet]'><br> <input type='submit' value='Update'> </form>"; Thanx alot, chris Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/ Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 You'll need to use ".$user['dername']." instead. This is better PHP syntax. Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697690 Share on other sites More sharing options...
chrissie18 Posted November 24, 2008 Author Share Posted November 24, 2008 ok i changed it but what`s the problem with the Notice: Undefined index: dername in can`t get them fixed tried different things Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697696 Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 Need to change this line too: $dername = addslashes(htmlspecialchars($_POST['dername'])); You need to use quotes for every non-numeric array key to avoid getting this error. Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697703 Share on other sites More sharing options...
kenrbnsn Posted November 24, 2008 Share Posted November 24, 2008 You're testing to see if a value coming in from the URL is set. That does not guarantee that the $_POST array has been set. You should add a name to the the "submit" button and check whether that has been set. <?php if(isset($logged['id'])) { if(isset($_POST['submit'])) { $email = addslashes(htmlspecialchars($_POST['email'])); $location = addslashes(htmlspecialchars($_POST['location'])); $dername = addslashes(htmlspecialchars($_POST['dername'])); $welcomet = addslashes(htmlspecialchars($_POST['welcomet'])); //updates there profile in the db $update = mysql_query("UPDATE `members` SET `email` = '$email', `welcomet` = '$welcomet', `dername` = '$dername', `location` = '$location' WHERE `username` = '$logged[username]'"); echo "Profile updated!"; } $getuser = mysql_query("SELECT * FROM `members` WHERE `username` = '$logged[username]'"); $user = mysql_fetch_array($getuser); echo "<form action='editprofile.php?update' method='post'> Email: <input type='text' name='email' size='30' maxlength='55' value='$user[email]'><br> Location: <input type='text' name='location' size='30' maxlength='40' value='$user[location]'><br> dealer naam: <input type='text' name='dername' size='30' maxlength='40' value='$user[dername]'><br> Welkom text: <input type='text' name='welcomet' size='90' maxlength='240' value='$user[welcomet]'><br> <input type='submit' value='Update' name='submit'> </form>"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697711 Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 Ah I missed the point didn't I Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697712 Share on other sites More sharing options...
chrissie18 Posted November 24, 2008 Author Share Posted November 24, 2008 you are not the only one i think haha but hey still not working same errors tried everything stupid thing ??? Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697715 Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 You know they are not fatal errors - you could just turn them off and your system will still work. error_reporting(0); Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697717 Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 You could get rid of the error by checking every value first i.e. $dername = isset($_POST['dername'])?addslashes(htmlspecialchars($_POST['dername'])):""; Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697719 Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 You could also check to see if the form value is blank and not let them submit it if it is. Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697722 Share on other sites More sharing options...
mtoynbee Posted November 24, 2008 Share Posted November 24, 2008 There is always someone who thinks outside the box. Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697725 Share on other sites More sharing options...
chrissie18 Posted November 24, 2008 Author Share Posted November 24, 2008 yeah the page is already blank dername is blank and welcomet is blank the rest is filled up in (mysql) they are filled up with text but it seems he don`t want to get the text from it Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697726 Share on other sites More sharing options...
chrissie18 Posted November 24, 2008 Author Share Posted November 24, 2008 omfg whahaha i found the problem i checked again the mysql database and i wrote the dername with a D not d know it is working Thnx for all the help Link to comment https://forums.phpfreaks.com/topic/134037-solved-need-little-bit-help-code-is-not-correct/#findComment-697729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.