toolman Posted October 26, 2009 Share Posted October 26, 2009 Hi there, I am trying to select from my database and echo the result. This is what I have: $result = mysql_query("select * from website_settings"); $row = mysql_fetch_array($result); and I am echoing using: <input name="website_name" value="<?php echo $row['website_name']; ?>" type="text" class="input" /> But it is not echoing. does anyone know what I have wrong? Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/ Share on other sites More sharing options...
Alex Posted October 26, 2009 Share Posted October 26, 2009 I don't see anything immediately wrong with that. Are you sure website_name is the name of the column? You might want to put in print_r($row) for debugging. Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944892 Share on other sites More sharing options...
toolman Posted October 26, 2009 Author Share Posted October 26, 2009 Thanks, I tried the print_r($row) and it produced this: Array ( [0] => [website_name] => ) Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944900 Share on other sites More sharing options...
JAY6390 Posted October 26, 2009 Share Posted October 26, 2009 The first record has no website_name value according to your output Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944906 Share on other sites More sharing options...
toolman Posted October 26, 2009 Author Share Posted October 26, 2009 I see. I noticed my top record is blank. What I am trying to do is to only allow one record which can be updated. However, when I insert another record, it automatically adds a blank record to the top. Any ideas whats going on? Thank for your help. Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944912 Share on other sites More sharing options...
JAY6390 Posted October 26, 2009 Share Posted October 26, 2009 Without seeing your code no...I can't read minds Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944913 Share on other sites More sharing options...
Alex Posted October 26, 2009 Share Posted October 26, 2009 You shouldn't be inserting more records then, just updating the one. Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944915 Share on other sites More sharing options...
toolman Posted October 26, 2009 Author Share Posted October 26, 2009 I see. i am getting into a bit of a pickle. This is now what I have, but it doesn't seem to be updating. $website_name = $_POST['website_name']; $sql = "INSERT INTO website_settings VALUES('$website_name')"; mysql_query($sql); $update = mysql_query("UPDATE website_settings SET website_name = $website_name"); $result = mysql_query("select * from website_settings"); $row = mysql_fetch_array($result); Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944924 Share on other sites More sharing options...
Alex Posted October 26, 2009 Share Posted October 26, 2009 You should have a primary incrementing key field so that you can identify certain records. Then use a WHERE clause to make sure you're only updating one record (and remove that insert query..). Another problem I see if that you don't have quotes around $website_name in your UPDATE query. Quote Link to comment https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/#findComment-944929 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.