Lee-Bartlett Posted November 20, 2008 Share Posted November 20, 2008 Im trying to duplicate somthing i done but on a smaller size, but thats proving to be alot harder for some reason. I have a db table called email, in that table there are 2 feilds, email and id. there will only ever be 1 entry to this table but i cant seem to pull that entry into my text boxx, or even get it to echo. heres my code. <?php require_once("includes/db_connection.php"); ?> <?php $email = $_GET['email']; $sql = "SELECT * FROM email WHERE id='1'"; $res = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($res)); { echo $email; $email = $row['email']; echo "<form action='' method='post'> <input type='text' name='id' value='" . $row['email'] . "'><input type='submit' value='update' name='updatebutton' ></form>"; } ?> Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/ Share on other sites More sharing options...
ratcateme Posted November 20, 2008 Share Posted November 20, 2008 if there is only one entry why do you need a where on your query wouldn't SELECT * FROM email do it. and remember if that ID was assigned my MySQL its ID numbers start from 0 not 1. Scott. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694723 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 Took out that and it still wont echo the email adress i put in there Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694724 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 If there is only ever one entry you don't need a loop either. <?php require_once "includes/db_connection.php"; $sql = "SELECT email FROM email"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { echo "<form action='' method='post'>\n"; echo "<input type='text' name='id' value='" . $row['email'] . "'>\n"; echo " <input type='submit' value='update' name='updatebutton'>\n"; echo "</form>\n"; } else { echo "No email found"; } } else { echo mysql_error() . "<br />$sql"; } ?> Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694727 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 strange still not seeing an email. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694735 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Are you getting any of the error messages? Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694737 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 nope, all i am getting back is a blank echo. and the feild isnt being echoed. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694738 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Can you post the entire output of 'view source' ? Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694741 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 What page source when you right click the page or the whole code. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694742 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 The output of a right-click -> view source. The relevent parts (ie; the above form) anyway. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694743 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 all it shows is the form, all the rest is in php and cant be seen. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694744 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Can I see it? Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694746 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 that is it all. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694747 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Ahhh.. Post the output of view source! Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694748 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 I posted it all. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694750 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 When you view the page in your browser, right click on it, click view source. Post that here! Not the php! Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694752 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 <form action='' method='post'> <input type='text' name='id' value=''> <input type='submit' value='update' name='updatebutton'> </form> Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694753 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Your email field within the database must be an empty string. The code could not possibly produce that output otherwise. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694755 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 In phpmyadmin, it has, table name email, 2 feilds email and id, in them 2, there is 1 for id and my email adress. and it is connecting to my db. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694756 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Add this to the top of your script. <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> While were at it, you best post the actual code your using. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694762 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 im using the code u gave me. error is Notice: Undefined variable: row in /home/nexodom/public_html/website/admin/email.php on line 12 <?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?> <?php require_once "includes/db_connection.php"; $sql = "SELECT email FROM email"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { echo "<form action='' method='post'>\n"; echo "<input type='text' name='id' value='" . $row['email'] . "'>\n"; echo " <input type='submit' value='update' name='updatebutton'>\n"; echo "</form>\n"; } else { echo "No email found"; } } else { echo mysql_error() . "<br />$sql"; } ?> Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694769 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Oh man... I am having a bad bad day. My fault. <?php require_once "includes/db_connection.php"; $sql = "SELECT email FROM email"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "<form action='' method='post'>\n"; echo "<input type='text' name='id' value='" . $row['email'] . "'>\n"; echo " <input type='submit' value='update' name='updatebutton'>\n"; echo "</form>\n"; } else { echo "No email found"; } } else { echo mysql_error() . "<br />$sql"; } ?> Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694771 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 cant figure out where to end it, $end, but i put the } in like all places. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694778 Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 What do you meen? Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694779 Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 u know u get the dollar end, i assumed it was the } cause u never closed the else. Link to comment https://forums.phpfreaks.com/topic/133563-solved-basicwhere-am-i-going-wrong/#findComment-694783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.