Page 1 of 1

WARNING message despite good SELECT

Posted: Thu Sep 03, 2009 9:13 pm
by zunebuggy
I have a form where a user enters a unique number that IS in my database.

On submit,it runs my enter_num.php php script.

in the php script I have echo'd the variable that holds the unique number. It returns the correct number.

That number is then used in the SQL query.

I echo the SQL SELECT statement and the statement is good. I can copy and paste the echo'd text directly in phpMyAdmin and it returns 1 row as I expected.

Then I save field6 into variable $field_vi which is also a unique field. (note these are not the actual field names, I am just using them as the example here).

I echo'd $field_vi and it holds the value I expect.

My next query uses this value in the WHERE clause.

NOTE: I know I am open a connection, closing it and then opening it again for the second query. This may not be right, but at first I did not do this and it wasn't working, so I tried this way. It still didn't work.

I echo'd the $sql2 SELECT statement and it is correct...

I can copy and paste this select into phpMyAdmin and it returns a single row result with all my css fields.

I echo'd ALL the css variables and they all have the expected values.

But in my HTML, the values where I insert these variables in my html are ALL blank... The HTML page displays, but when I view page source,the css style statements are all there, but the variables are ALL blank.

Also before the <html> tag is the following WARNING (multiple times):
<br />
<b>Warning</b>: mysql_result() [<a href='function.mysql-result'>function.mysql-result</a>]: Unable to jump to row 0 on MySQL result index 2 in <b>/home/content/b/b/e/servername/html/mysite/enter_num.php</b> on line <b>15</b><br />
How do I get rid of the Warnings above from my html code AND why are my variables blank in the html code but populated just before that?

Here is my php code.

Code: Select all

 
<?php
$enter_num=$_POST['ent_numb'];
$dbhost = 'my.hostlink.host.com';
$dbuser = 'dbusername';
$dbpass = 'mypassword'; 
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'mydbname';
mysql_select_db($dbname);
$sql="SELECT uniq_number, field1, field2, field3, field4, field5, field6, field7 FROM mytablel WHERE uniq_number = '".$enter_num."'"; 
 
$result = mysql_query($sql);
 
    $u_num = mysql_result($result, 0, "uniq_number");
    $field_i = mysql_result($result, 0, "field1");
    $field_ii = mysql_result($result, 0, "field2");
    $field_iii = mysql_result($result, 0, "field3");
    $field_iv = mysql_result($result, 0, "field4");
    $field_v = mysql_result($result, 0, "field5");
    $field_vi = mysql_result($result, 0, "field6");
    $field_vii = mysql_result($result, 0, "field7");
 
mysql_close($conn);
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$dbname = 'mydbname';
mysql_select_db($dbname);
$sql2="SELECT image, image_repeat, image_pos, pad_left, pad_top, border, font_name, font_style, font_weight, font_size, letter_space, font_color, back_color FROM stile WHERE css_clas = '".$field_vi."'";
 
$result2 = mysql_query($sql2) or die(mysql_error());
 
    $back_image = mysql_result($result2, 0, "image");
    $bak_repeat = mysql_result($result2, 0, "image_repeat");
    $back_pos = mysql_result($result2, 0, "image_pos");
    $pad_lef = mysql_result($result2, 0, "pad_left");
    $pad_topp = mysql_result($result2, 0, "pad_top");
    $mem_border = mysql_result($result2, 0, "border");
    $mem_font = mysql_result($result2, 0, "font_name");
    $mem_font_sty = mysql_result($result2, 0, "font_style");
    $mem_font_wt = mysql_result($result2, 0, "font_weight");
    $mem_font_sz = mysql_result($result2, 0, "font_size");
    $let_space = mysql_result($result2, 0, "letter_space");
    $mem_font_col = mysql_result($result2, 0, "font_color");
    $mem_bak_col = mysql_result($result2, 0, "back_color");
mysql_close($conn);
 
echo "<html>\n";
echo "<head>\n";
echo "<meta http-equiv=\"Content-Language\" content=\"en-us\">\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n";
echo "<title>My Title</title>\n";
echo "<meta name=\"description\" content=\"My description.\">\n";
echo "<style type=\"text/css\">\n";
echo "  .mystyle{\n";
echo "  background-image:url(\'".$back_image."\');\n";
echo "  background-repeat: ".$back_repeat.";\n";
echo "  background-position: ".$back_pos.";\n";
echo "  padding-left: ".$pad_lef."px;\n";
echo "  padding-top: ".$pad_topp."px;\n";
echo "  border:".$mem_border.";\n";
echo "  width:320px;\n";
echo "  height:320px;\n";
echo "  font-family:".$mem_font.";\n";
echo "  font-style:".$mem_font_sty.";\n";
echo "  font-weight:".$mem_font_wt.";\n";
echo "  font-size:".$mem_font_sz.";\n";
echo "  letter-spacing:".$let_space.";\n";
echo "  color:".$mem_font_col.";\n";
echo "  background-color:".$mem_bak_col.";\n";
//MORE HTML HERE.....
echo "</head>\n";
echo "</html>\n";
?>
 
I'm sure it's something as simple as I missed a single quote somewhere.... Or and extra one.... *sigh*

:banghead:

Thank you.

Re: WARNING message despite good SELECT

Posted: Thu Sep 03, 2009 9:40 pm
by califdon
I don't recognize that warning message, and I don't know what effect the Unix newline characters may or may not have within a style sheet, and I am not sure that the following will have any effect on the condition you are experiencing, but it will surely make it easier to read your code, which can sometimes help in debugging a problem. You don't need to concatenate PHP variables within a double-quoted string, and I would rewrite those lines like this:

Code: Select all

echo "<style type='text/css'> ";
echo "  .mystyle {";
echo "  background-image:url('$back_image'); ";
echo "  background-repeat: $back_repeat; ";
echo "  background-position: $back_pos; ";
...
  etc.

Re: WARNING message despite good SELECT

Posted: Thu Sep 03, 2009 10:30 pm
by zunebuggy
You know, that is what it was. I got rid of the double quotes and the variables were no longer blank. AND strangely enough, the Warning message displayed in the browser is is only viewable in the html source and not on the page because it is before the <html> tag, but it is still there when I view the source in Google Chrome. It is not there in Firefox and IE so it is a strange Chrome idiosyncrasy that I will not ponder or worry about. The source code is perfect in Firefox and IE.

I have been building my html in Frontpage and converting pages to php echo using and online converter that works pretty well (both bad practice I know...), but I think I would do better to learn to do it manually. The online converter is a time saver though...

Thank you.
:D

This site and the members are all lifesavers for us learning to code and debug... kudos.