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>"; } ?> Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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"; } ?> Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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' ? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Can I see it? Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 that is it all. Quote Link to comment Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Ahhh.. Post the output of view source! Quote Link to comment Share on other sites More sharing options...
Lee-Bartlett Posted November 20, 2008 Author Share Posted November 20, 2008 I posted it all. Quote Link to comment 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! Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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"; } ?> Quote Link to comment 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"; } ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 What do you meen? Quote Link to comment 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. 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.