LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-30-2008, 03:11 PM   #1
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Rep: Reputation: 31
php page displaying text that is supposed to be part of php code


Hello all,

I am working on php and putting html and php into the same page. My code is as follows:
Code:
<?
//connect to mysql
mysql_connect("localhost","user","password");

//select which database you want to edit
mysql_select_db("databasename");

//If cmd has not been initialized
if(!isset($cmd))
{
   //display all the items
   $result = mysql_query("select * from items order by type");

   //run the while loop that grabs all the items scripts
   while($r=mysql_fetch_array($result))
   {
      //grab the columns from items
      $rbuilding=$r["building"];//take out the building
      $rroom=$r["room"];//take out the room
      $rtype=$r["type"];
      $rmodel=$r["model"];
      $rserial=$r["serial"];
      $rspecial=$r["special"];
      $rcomments=$r["comments"];
	 //make the title a link
	 echo "<a href='edit.php?cmd=edit&building=$rbuilding&room=$rroom&type=$rtype&model=$rmodel&serial=$rserial&special=$rspecial&comments=$rcomments'>Edit</a>";
//	 echo "<br \>";
	  }
}

?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
   if (!isset($_POST["submit"]))
   {
      $building = $_GET["rbuilding"];
      $room = $_GET["rroom"];
      $type = $_GET["rtype"];
      $make = $_GET["rmake"];
      $model = $_GET["rmodel"];
      $serial = $_GET["rserial"];
      $special = $_GET["rspecial"];
      $comments = $_GET["rcomments"];

      $sql = "SELECT * FROM items WHERE building='$building' && room='$room' && type='$type' && make='$make' && model='$model' && serial='$serial' && special='$special' && comments='$comments'";
      $result = mysql_query($sql);
      $myrow = mysql_fetch_array($result);
	
 ?>

     <form action="edit.php" method="post">

      Building: <INPUT TYPE="TEXT" NAME="building" VALUE="<? $myrow["building"] ?>" SIZE=30 /><br />
      Room: <INPUT TYPE="TEXT" NAME="room" VALUE="<? echo $myrow["room"] ?>" SIZE=30 /><br />
      Type: <INPUT TYPE="TEXT" NAME="type" VALUE="<? echo $myrow["type"] ?>" SIZE=30 /><br />
      Make: <INPUT TYPE="TEXT" NAME="make" VALUE="<? echo $myrow["make"] ?>" SIZE=30 /><br />
      Model: <INPUT TYPE="TEXT" NAME="model" VALUE="<? echo $myrow["model"] ?>" SIZE=30 /><br />
      Serial: <INPUT TYPE="TEXT" NAME="serial" VALUE="<? echo $myrow["serial"] ?>" SIZE=30 /><br />
      Special: <INPUT TYPE="TEXT" NAME="special" VALUE="<? echo $myrow["special"] ?>" SIZE=30 /><br />
      Comments: <INPUT TYPE="TEXT" NAME="comments" VALUE="<? echo $myrow["comments"] ?>" SIZE=30 /><br />

      <input type="submit" name="submit" value="submit">

      </form>

<? } ?>
<?
	if ($_POST["$submit"])
	{
	$building = $_POST["building"];
	$room = $_POST["room"];
	$type = $_POST["type"];
	$make = $_POST["make"];
	$model = $_POST["model"];
	$serial = $_POST["serial"];
	$special = $_POST["special"];
	$comments = $_POST["comments"];

	$sql = "UPDATE items SET building='$building',room='$room',type='$type',make='$make',model='$model',serial='$serial',special='$special',comments='$comments'"; 
	$result = mysql_query($sql);
	echo "Thank you! Information updated.";
	}
}
?>
However when I run this code I get my text boxes, but they are filled in with
Code:
<? echo $myrow[
, and after each text box it prints
Code:
" SIZE=30 />
, and before my text boxes
Code:
Edit"; // echo "
"; } } ?>
I was hoping that you would be able to see my mistake. I have been almost to the point of banging my head against the desk.

Thanks as always for your help.

DragonM15
 
Old 07-30-2008, 03:26 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

You might try something like this:
Code:
  // Original:
  Building: <INPUT TYPE="TEXT" NAME="building" VALUE="<? echo $myrow["building"] ?>" SIZE=30 /><br />
 
  // New:
  Building: <input type="TEXT" name="building" value=<? echo "\"$myrow["building"]\""; ?> size=30 /><br />
In other words, control the quotes from your PHP, instead of your XHTML.

'Hope that helps .. PSM
 
Old 07-30-2008, 03:45 PM   #3
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
That made the amount of text inside the text box decrease to
Code:
<?
instead of
Code:
<? echo $myrow[
Apache error_log shows no errors either

Thanks,
DragonM15
 
Old 07-30-2008, 06:27 PM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
I think you named your file file.html. It should by file.php

I was able to reproduce your error in file.html, but the form shows fine in file.php

jlinkels
 
Old 07-30-2008, 07:42 PM   #5
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
Its in a php file... edit.php
I tried it on 2 computers (one windows with php and one slackware 12.1 with php) and both give the same problem.

DragonM15
 
Old 07-30-2008, 07:50 PM   #6
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
As a side-note I am running apache-2.2.9 on a Slackware 12.1 box. All my other PHP files work perfect, it is just this one that isn't working properly.

DragonM15
 
Old 07-30-2008, 08:36 PM   #7
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
I tried it on my own server after editing a few statements to get it to work without that particular database. It works all right.

See if it runs on your server, and if so, undo all my changes until it goes wrong.

What is the contents of the array returned by the database? Are there some stray quotes in?

The file name I used is build.php - should have been edit.php of course but typing was faster than thinking

PHP Code:
<?
//connect to mysql
//mysql_connect("localhost","user","password");

//select which database you want to edit
//mysql_select_db("databasename");

//If cmd has not been initialized
if(!isset($cmd))
{
   
//display all the items
   //$result = mysql_query("select * from items order by type");

   //run the while loop that grabs all the items scripts
   //while($r=mysql_fetch_array($result))
$r=2;
   while(
$r 0)
    
$r--;
   {
      
//grab the columns from items
      
$rbuilding=$r["building"];//take out the building
      
$rroom=$r["room"];//take out the room
      
$rtype=$r["type"];
      
$rmodel=$r["model"];
      
$rserial=$r["serial"];
      
$rspecial=$r["special"];
      
$rcomments=$r["comments"];
     
//make the title a link
     
echo "<a href='edit.php?cmd=edit&building=$rbuilding&room=$rroom&type=$rtype&model=$rmodel&serial=$rserial&special=$rspecial&comments=$rcomments'>Edit</a>";
//     echo "<br \>";
      
}
}

?>
<?
//if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
if(1)
{
   if (!isset(
$_POST["submit"]))
   {
      
$building $_GET["rbuilding"];
      
$room $_GET["rroom"];
      
$type $_GET["rtype"];
      
$make $_GET["rmake"];
      
$model $_GET["rmodel"];
      
$serial $_GET["rserial"];
      
$special $_GET["rspecial"];
      
$comments $_GET["rcomments"];

      
$sql "SELECT * FROM items WHERE building='$building' && room='$room' && type='$type' && make='$make' && model='$model' && serial='$serial' && special='$special' && comments='$comments'";
      
//$result = mysql_query($sql);
      //$myrow = mysql_fetch_array($result);
    
 
?>

     <form action="edit.php" method="post">

      Building: <INPUT TYPE="TEXT" NAME="building" VALUE="<? $myrow["building"?>" SIZE=30 /><br />
      Room: <INPUT TYPE="TEXT" NAME="room" VALUE="<? echo $myrow["room"?>" SIZE=30 /><br />
      Type: <INPUT TYPE="TEXT" NAME="type" VALUE="<? echo $myrow["type"?>" SIZE=30 /><br />
      Make: <INPUT TYPE="TEXT" NAME="make" VALUE="<? echo $myrow["make"?>" SIZE=30 /><br />
      Model: <INPUT TYPE="TEXT" NAME="model" VALUE="<? echo $myrow["model"?>" SIZE=30 /><br />
      Serial: <INPUT TYPE="TEXT" NAME="serial" VALUE="<? echo $myrow["serial"?>" SIZE=30 /><br />
      Special: <INPUT TYPE="TEXT" NAME="special" VALUE="<? echo $myrow["special"?>" SIZE=30 /><br />
      Comments: <INPUT TYPE="TEXT" NAME="comments" VALUE="<? echo $myrow["comments"?>" SIZE=30 /><br />

      <input type="submit" name="submit" value="submit">

      </form>

<? ?>
<?
    
if ($_POST["$submit"])
    {
    
$building $_POST["building"];
    
$room $_POST["room"];
    
$type $_POST["type"];
    
$make $_POST["make"];
    
$model $_POST["model"];
    
$serial $_POST["serial"];
    
$special $_POST["special"];
    
$comments $_POST["comments"];

    
$sql "UPDATE items SET building='$building',room='$room',type='$type',make='$make',model='$model',serial='$serial',special='$special',comments='$comments'"
    
//$result = mysql_query($sql);
    
echo "Thank you! Information updated.";
    }
}
?>
I am running Apache 1.3, PHP 4.3

jlinkels
 
Old 07-31-2008, 11:00 AM   #8
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
jlinkels, I put your exact code into a new php file titled edit1.php and I also modified all statements involving edit.php to edit1.php. However that actually made the page look worse.

The error looks like:
http://i59.photobucket.com/albums/g2...pediterror.jpg

As always, the apache error log shows no errors.

DragonM15
 
Old 07-31-2008, 02:27 PM   #9
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
It is not worse, on the contrary it provides more information.

I created exactly the same screen output as you have by setting short_open_tag = Off in /etc/php4/apache/php.ini. It starts exactly at "0) $r--; ...." as yours does. You have to restart apache after changing.

Watch out, there might be more php.ini files around on your system.

I hope this is your problem, although I am amazed if it happens on two different systems, and you say other scripts do work. Do they use the short open tags as well, or the long <?php tag?

In PHP 2 '>' was allowed as closing tag, after that it became depreciated and unusable. I assume you don't run PHP 2, do you?

jlinkels
 
Old 07-31-2008, 04:58 PM   #10
DragonM15
Member
 
Registered: Sep 2003
Location: USA
Distribution: Slackware (Multiple Versions)
Posts: 455

Original Poster
Rep: Reputation: 31
Well... That fixed the problem! I feel like an idiot right about now, but the problem is fixed. Ill bet that fixes one of my other problems with my delete php. And for the record, in Slackware the php.ini is in /etc/httpd/php.ini for anyone having the same problem I was.

No I am not using php2 I am using php-5.2.6 (current version).

And also, the pages that were in the making that I was also having problems with had <? ?>'s and were having problems. All the ones that worked were <?php 's.

Thank you for your help in solving my problem!

DragonM15

P.S. That only took 2 days of staring and pulling my hair out....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfixadmin PHP setup file - only displays PHP code davidmbecker Linux - Software 3 04-17-2008 10:33 AM
php page can't display but download as php file? taiwf Linux - Software 2 03-07-2006 05:57 PM
how to redirect PHP code to another page bahadur Programming 3 03-21-2005 05:59 AM
how to compare 2 text files by using php code antony_csf Programming 3 10-14-2004 05:52 AM
PHP code did not create a cookie and it did not changed the background and text color Linh Programming 5 07-29-2004 10:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration