jay7981 Posted February 17, 2013 Share Posted February 17, 2013 (edited) hey all, I have a text field that is populated with a mysql field however it is not populating with all of the info in that field it stops at the first space of any info in the mysql field ... why would this be happening ? i am using this type of setup info in the mysql field of name is: John Doe Mercer while($res=mysql_fetch_array($result)) { $name = mysql_real_escape_string($res['name']); } echo $name; Only output i get is John edit.php Edited February 17, 2013 by jay7981 Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/ Share on other sites More sharing options...
Jessica Posted February 17, 2013 Share Posted February 17, 2013 Because your echo is outside of your while loop. Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1412988 Share on other sites More sharing options...
jay7981 Posted February 17, 2013 Author Share Posted February 17, 2013 ive moved the closing bracket to the end of the echo and still the echo stops at teh first space, ive also editied the first post and attached the full code. Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1412990 Share on other sites More sharing options...
Jessica Posted February 17, 2013 Share Posted February 17, 2013 Did you check that the information in your database is what you think it is? What do you get when you run the query in MySQL or phpMyAdmin? What if you do a print_r() on $res? Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1412991 Share on other sites More sharing options...
Jessica Posted February 17, 2013 Share Posted February 17, 2013 (edited) The code you attached is dramatically different from the code you posted, and doesn't have anything like this code. Your code also stores First and Last name in separate fields (which is GOOD) but you're only echoing 'name' in your posted code. Edit: The fact that you're running mysql_real_escape_string on values you just SELECTED from the database makes me think your code has some serious issues. You're not checking for any SQL errors either. Edit 2: You ALSO are trying to use $ID before it's been defined for your update. Turn error reporting on! Edited February 17, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1412992 Share on other sites More sharing options...
jay7981 Posted February 17, 2013 Author Share Posted February 17, 2013 (edited) the posted code was simply an example to show you all what i was running into, and yes the info in the database is what i want but is not being displayed correctly Edit to answer, i use escape_string because i dont trust user input, i will be adding sql error checks later as the code works perfectly with the exception of the current issue i have. i have $ID well defined for both the update and select statement before it is used. error reporting is on (ALL) within my ini again here is the code with minor mods done edit.php Edited February 17, 2013 by jay7981 Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1412994 Share on other sites More sharing options...
jay7981 Posted February 17, 2013 Author Share Posted February 17, 2013 (edited) also when print_r($res) i get what i am expecting just not with the echo print_r($res['Department']); returns My Favorite Department but echo ($res['Department']); returns My ive figured it out ... for some reason i had to double quote the echos in the value ... <input type="text" name="Department" size="55" value="<?php echo ($res['Department']); ?>"> Edited February 17, 2013 by jay7981 Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1412997 Share on other sites More sharing options...
PaulRyan Posted February 17, 2013 Share Posted February 17, 2013 You need to put quotes around your input values: <input type="text" name="FName" value="<?php echo $FName;?>"> Otherwise it will only show up to the first space as it thinks that is the end of the value. Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1412998 Share on other sites More sharing options...
Jessica Posted February 17, 2013 Share Posted February 17, 2013 And that's why using your actual code and not an example matters. Quote Link to comment https://forums.phpfreaks.com/topic/274602-phpmysql-populated-textfield-not-working/#findComment-1413013 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.