11Tami Posted January 5, 2007 Share Posted January 5, 2007 Hi, I need some special help for this situation. I'll send you a whole bunch of helpful links if you can help me fix it. In this code you put in a web site into the first form field. When you submit the name it looks in the database to see if the name is there. If it finds the name, it then pulls out the value for a field called "datafield" from the particular website name. That field called "datafield" is then supposed to carry over to the form on the bottom of this page and appear in the form field all on its own. (Due to the value for the input field value="$row[datafield]") <input type="text" name="datafield" value="$row[datafield]">This code is a working copy and works perfectly, all except for the datafield is not carrying over to the form. Can someone help me spot the problem and why it isn't appearing in the form field? Thank you [i]so much [/i] for your help. [code]<?php$con = mysql_connect("m","database","password") OR die('Could not connect: ' . mysql_error()); mysql_select_db("database", $con) OR die(mysql_error()); if(!$_POST){?><form action="" method="post"><span style='margin-left: 0px; font-weight:bold; font-family: arial,sans-serif; color: rgb(0, 0, 128); font-size: 14px;'>Enter a web site name to viewlink requests options. Web site names can be in upper or lower case. <br /><br /></span><input type="text" size="12" name="websitename" value="<?=$_POST['websitename'] ?>" /> <input type="submit" style="width:107px" value="Request Options" /></form><?}else{$modify = mysql_real_escape_string($_POST['websitename']); $query = "SELECT DISTINCT websitename, datafield FROM getname WHERE websitename = '$modify'";$result = mysql_query($query) or die('Error with query' . mysql_error());if (mysql_num_rows($result) == 0){echo "$modify not found. Please recheck name and try again";}while ($row = mysql_fetch_array($result)){if ($_POST['text']==""){echo '<form method="post" action=""><input type="text" name="text"><br /><input type="text" name="emailaddress"><br /><input type="text" name="datafield" value="$row[datafield]"><br /><br /><input type="submit" value="submit"></form>';}else{$mailto = 'aemailaddress@website.com';$sendersmessage = $_POST['text'];$fromdatabase=$_POST['datafield'];$subject = 'Subject sent to email';$sendersemail = $_POST['emailaddress'];$from = "From: ".$senderemail. "\n" ;$messageproper = "Field from database: $fromdatabase\n" . "Email of sender: $senderemail\n" . "Senders Message: $sendersmessage\n";mail($mailto,$subject,$messageproper,$from);print 'email sent';}}}?>[/code] Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 5, 2007 Share Posted January 5, 2007 When you're using variables inside quotes in PHP they need to be double quotes.[code=php:0]$variable = 'test';echo "the variable is $variable"; // will output as explected "the variable is test"echo 'the variable is $variable'; // since it's single quotes will output "the variable is $variable"[/code]This is also why double quote are a teensy bit slower than single quotes, if you use double quotes php will parse everything inside of them as well, looking for variables to replace, whereas if you use single quotes php doesn't care about parsing the insides.your echo is using single quotes, therefore PHP wont replace the value you want... I also think (not 100% sure) that when you are using arrays, they should be surrounded by {} eg. [code=php:0]echo "test {$array['test']}";[/code]I'm not 100% sure on this because I always put {} around variables inside quotes anyway. Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 5, 2007 Author Share Posted January 5, 2007 Thank you very much, thats all working fine. I need to know why this isn't working.name="datfield" value="$row[datafield]" The datafield should be showing in the form field from the database and its not. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 5, 2007 Share Posted January 5, 2007 try changing[code=php:0]echo '<form method="post" action=""><input type="text" name="text"><br /><input type="text" name="emailaddress"><br /><input type="text" name="datfield" value="$row[datafield]"><br /><br /><input type="submit" value="submit"></form>';[/code]to[code=php:0]echo '<form method="post" action=""><input type="text" name="text"><br /><input type="text" name="emailaddress"><br /><input type="text" name="datfield" value="' . $row[datafield] . '"><br /><br /><input type="submit" value="submit"></form>';[/code]and you'll see what I meant ;). I was trying to get you to see your own error instead of just telling you the answer :D it's a test! Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 5, 2007 Author Share Posted January 5, 2007 :D Don't you now after looking through all this code, we aren't good at tests?I tried it, no luck. Thanks. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 5, 2007 Share Posted January 5, 2007 now that I look at it, it looks like you're pulling "websitename" from the query, but you're trying to do $row[datafield]? what about $row['websitename']? Quote Link to comment Share on other sites More sharing options...
11Tami Posted January 5, 2007 Author Share Posted January 5, 2007 Afraid not. This is why I need help with this because its kind of hard to explain. What it is saying is pull out a "row" only for the database field named datafield. There are two fields in the database table. One is called websitename and the other is called datafield. I am only asking for what is entered into the row of datafield. The row that I want is identified by the website name that is asked for. [quote]so fields in table are|website name| and |datafield||Joes Buffet| and |stuff in datafield| Is the row just for Joes Buffet.[/quote]When somone asks for Joes Buffet, since I have $row[datafield] listed in the form, its supposed to put "stuff in datafield" into the input text field all on its own. The check that shows this is working is here.if (mysql_num_rows($result) == 0){echo "$modify not found. Please recheck name and try again";If Joes Buffet or whatever is not found in the database I will get the just above error message. Right now I know its working because when I put in a bogus name, I get the error message. When I put a name that is in the database I don't get the message.So I think the error is here unless someone can prove to me otherwise. [code]while ($row = mysql_fetch_array($result)){if ($_POST['text']==""){[/code]I have the "if" command in the "while" statement, because I didn't know another way to do it. Hope someone can help, thanks. 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.