<form> $_SERVER[PHP_SELF]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

<form> $_SERVER[PHP_SELF]

Post by ol4pr0 »

Aight i have this form

@ the top

Code: Select all

require ("include/config.php");
require ("include/styles.php");
require ('db.php');
which runs just fine

config has all the mail tables and db the db tables and inserting constructions

db.php

Code: Select all

<?php
$connect= mysql_connect('localhost', 'root')
	or die("Cant connect: " .mysql_error());
$result=mysql_select_db($dbase)
	or die("Cant execute query: " .mysql_error());
$query = "CREATE TABLE IF NOT EXISTS ".$tablename." (Empresa varchar(20) Not Null, Codigo INT auto_increment, Desde varchar(20) Not Null, Envio varchar(20) Not Null, Information varchar(20) Not Null, Comentario varchar(20) Not Null, Codigo_Env INT(15), PRIMARY KEY (Codigo) )";
$result = mysql_query($query); 
if (!$result)
{ 
die ( "Execute error: " .mysql_error());
}
else
{
	echo "Connectando Con Base Datos ".$tablename." , avancar!\n";
}

$query ="INSERT INTO ".$tablename."  ('".$Empresa."','".$Codigo."','".$Desde."','".$Envio4."','".$Information."','".$Comentario."')";
if (!$result = mysql_query($query))";
die (  .mysql_error())"; 

?>
which give me this error when i start up the form

FORM CODE

Code: Select all

<?php
<form method="POST" action=<?php $_SERVER[PHP_SELF] php?> 
            <p class="e">
            Empresa<font size=8><input type=text name="Empresa" cols="25" rows="1" size="20" ></textarea><br>
            </font>Codigo<font size=8><input type=text name="Codigo" cols="20" rows="1" size="20"></textarea><br>
			</font>Desde<font size=8><input type=text name="Desde" cols="20" size="20"></textarea><br>
            </font>envio<font size=8><input type=text name="Envio" cols="20" size="20"></textarea><br>
			</font>Informacion<font size=8><input type=text name="Information" cols="20" size="20"></textarea><br>
            </font>Comentario<font size=8><textarea name="Comentario" rows="4" cols="20" size="18"></textarea><br>
	  <p>
	  <br>
            
          
          <p></td>
          <td width="328" height="211" class="e" align="right">
			  <class="e">
		  Peso Total<font size=8><input type=text name="Peso_Total" cols="8" size="10"</input></font><br>
			  Peso<font size=8><input type=text name="Peso" cols="8" size="10"</input></font><p>
			  Valor<font size=8><input type=text name="Valor" cols="12" size="16"</input></font>
			  <p>
			  <br>
			  <Div class="r"><input name="submit" type="submit" ID="Avancar" WIDTH="5" </form>

?>
THE ERROR which this give me @ the end =

Code: Select all

Connectando Con Base Datos pongo , avancar! 
Notice: Undefined variable: Empresa in c:\apache\htdocs\docs\db.php on line 19

Notice: Undefined variable: Codigo in c:\apache\htdocs\docs\db.php on line 19

Notice: Undefined variable: Desde in c:\apache\htdocs\docs\db.php on line 19

Notice: Undefined variable: Envio4 in c:\apache\htdocs\docs\db.php on line 19

Notice: Undefined variable: Information in c:\apache\htdocs\docs\db.php on line 19

Notice: Undefined variable: Comentario in c:\apache\htdocs\docs\db.php on line 19

_______________________________________________

and on button click of the query send error =;

Forbidden
You don't have permission to access /docs/&lt; on this server.

This is where my center.php = located ( &lt;iframe &gt;)
I hope i have been clear on what is going on and hope somebody has the answers



[/php_man]
Last edited by ol4pr0 on Wed Jan 21, 2004 2:25 pm, edited 1 time in total.
Sairon
Forum Newbie
Posts: 4
Joined: Mon Dec 30, 2002 6:51 pm

Post by Sairon »

replace $query ="INSERT INTO ".$tablename." ('".$Empresa."','".$Codigo."','".$Desde."','".$Envio4."','".$Information."','".$Comentario."')";

with
$query ="INSERT INTO ".$tablename." ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Desde']."','".$_POST['Envio4']."','".$_POST['Information']."','".$_POST['Comentario']."')";
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

...

Post by ol4pr0 »

it got me to reconize to fields.. thanks for that

however new error

Code: Select all

Notice: Undefined index: Empresa in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Codigo in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Desde in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Envio in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Information in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Comentario in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Peso_Total in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Peso in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Valor in c:\php4\pear\include\db.php on line 19

Code: Select all

$query ="INSERT INTO ".$tablename."  ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Desde']."','".$_POST['Envio']."','".$_POST['Information']."','".$_POST['Comentario']."','".$_POST['Peso_Total']."','".$_POST['Peso']."','".$_POST['Valor']."')";
if (!$result = mysql_query($query))"; // line 19
die (  .mysql_error())"; 
?>
where do i keep on going wrong

and why the

Code: Select all

Forbidden
You don't have permission to access /docs/&lt; on this server.
Last edited by ol4pr0 on Tue Jan 20, 2004 4:21 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

if (!$result = mysql_query($query))";
die ( .mysql_error())";

Change to :
$result = mysql_query($query) or die(mysql_error());
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

That made me more scared lol

Code: Select all

Connectando Con Base Datos pongo , avancar! 
Notice: Undefined index: Empresa in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Codigo in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Desde in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Envio in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Information in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Comentario in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Peso_Total in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Peso in c:\php4\pear\include\db.php on line 19

Notice: Undefined index: Valor in c:\php4\pear\include\db.php on line 19
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''','','','','','','','','')' at line 1
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Your form is a bit screwed up too ;)
Remove the <?php ?> tags surrounding the <form> ... </form> then remove all those backslashes around the form vars, e.g.
name="Empresa" instead of name=\"Empresa\"

You also appear to be running the query whether the form has been posted or not, so you should really wrap all the query stuff around a
if(isset($_POST['submit'])){
....
}
type thing.
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Well the error that it can not enter /index< is gone..
i closed ?> it before the form.. so that is one problem gone..

however it doesnt add anything into the database...
the only error that is still there is when the form is loaded up..

with the lines as posted, yea it is kinda messy...( its need irond if working lol )
however it should be able to work the backslashes are specially there cause of the echo " and <?php otherwise it will not be able to reed it.

let me repost all the involved scripts and see if it can be figured out, i have been reading and reading and reading i just can not find my error.

first i thought it might something with the require db.php loading up before the form is being processed.

All fields need to be optional, so it doesnt require a input.
thats why i dont use (isset) If that is not what you mean... i am lost lol

let me explain the directories as it is.

Oke sinds i tried! to install pear ( which didnt work ) i had to put all include pages in c:\php4\pear\include\*********
my webr00t = \apache\htdocs\****
first page has a frame referring to
apache\htdocs\index\center.php
When i start up the index page in \htdocs\ i get the errors as posted above
Notice: Undefined index




DB.php

Code: Select all

<?php
$dbase ="home";
$tablename ="pongo";
$connect= mysql_connect('localhost', 'root')
	or die("Cant connect: " .mysql_error());
$result=mysql_select_db($dbase)
	or die("Cant execute query: " .mysql_error());
$query = "CREATE TABLE IF NOT EXISTS ".$tablename." (Empresa varchar(20) Not Null, Codigo INT auto_increment, Desde varchar(20) Not Null, Envio varchar(20) Not Null, Information varchar(20) Not Null, Comentario varchar(20) Not Null, Codigo_Env INT(15), PRIMARY KEY (Codigo) )";
$result = mysql_query($query); 
if (!$result)
{ 
die ( "Execute error: " .mysql_error());
}
else
{
	echo "Connectando Con Base Datos ".$tablename." , avancar!\n";
}
$query ="INSERT INTO ".$tablename."  ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Desde']."','".$_POST['Envio']."','".$_POST['Information']."','".$_POST['Comentario']."','".$_POST['Peso_Total']."','".$_POST['Peso']."','".$_POST['Valor']."')";
if (!$result = mysql_query($query))"; 
die (  .mysql_error())"; 

?>
center php

Code: Select all

<?
require ("include/config.php");  
/*is for the index.php page outside <iframe>*/

require ("include/styles.php");
/* contains all css */

require ("include/db.php");


//form
?>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="600" height="432" class="center table">
  <tr>
    <td width="100%" height="432">
    <div class="center" style="width: 555; height: 282">
      <center>
      <table border="0" cellpadding="0" cellspacing="0" width="614" height="280">
        <tr>
          <td width="283" height="320" class="e" align="right">
          <form action='<?$_SERVER['PHP_SELF'];?>' method='post'>
            <p class="e">
            Empresa<font size=8><input type=text name="Empresa" cols="25" rows="1" size="20" ></input><br>
            </font>Codigo<font size=8><input type=text name="Codigo" cols="20" rows="1" size="20"></input><br>
            </font>Desde<font size=8><input type=text name="Desde" cols="20" size="20"></input><br>
            </font>envio<font size=8><input type=text name="Envio" cols="20" size="20"></input><br>
            </font>Informacion<font size=8><input type=text name="Information" cols="20" size="20"></input><br>
            </font>Comentario<font size=8><input name="Comentario" rows="4" cols="20" size="18"></input><br>
      <p>
      <br>
            
          
          <p></td>
          <td width="328" height="211" class="e" align="right">
              <class="e">
          Peso Total<font size=8><input type=text name="Peso_Total" cols="8" size="10"</input></font><br>
              Peso<font size=8><input type=text name="Peso" cols="8" size="10"</input></font><p>
              Valor<font size=8><input type=text name="Valor" cols="12" size="16"</input></font>
              <p>
              <br>
              <Div class="r"><input name="submit" type="submit" ID="Avancar" WIDTH="5" CLASSID="CLSID:B6FC3A14-F837-11D0-9CC8-006008058731">
      
        </form> 
        </tr>
      </table>
      
      </center>
    </div>
    </td>
  </tr>
</table>

</body>
</html>
i did take out all backslashes to make it somewhat more clearly to read ;-)

i really want this to work for ones, and i should all happen on one page.

I know the way to have it happen on like 3 pages. Its just not what i want it to do
Post Reply