Page 1 of 1

Actually having it add something into database

Posted: Thu Jan 22, 2004 9:11 am
by ol4pr0
Some of you might already have seen this form however it got it loads up without errors. ;-) after deciding to clean it up

However it does not add anything in to the database. infact i got 3 questions.

1: are php functions private by default, since it would reconize the ".$tablename." in the INSERT INTO line.
2: how can i actually have form input being added into the database.
3. how can i make this page return automaticly to the form again.

Code: Select all

<?
require ("include/styles.php"); //css 
require ("include/db.php"); //database

/* variable url pagina local */
if (isset($_POST['stage']) &&('process' == $_POST['stage'])) {
	process_form();
} else {
	print_form();
}

// impri
function print_form() {
	echo <<<END
<head>
<body>
<table border="0" cellpadding="0" cellspacing="0" bordercolor="#111111" width="600" height="450">
<tr>
<td width="100%" height="450">
<div align="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" class="r">
	<form action="$_SERVER[PHP_SELF]" method="post" class="e">
            Empresa<font size=8><input type=text name="Empresa"></input><br>
			<input type="hidden" name="stage" value="process">
            </font>Codigo<font size=8><input type=text name="Codigo"></input><br>
			<input type="hidden" name="stage" value="process">
			</font>Desde<font size=8><input type=text name="Desde"></input><br>
			<input type="hidden" name="stage" value="process"> 
            </font>envio<font size=8><input type=text name="Envio"></input><br>
			<input type="hidden" name="stage" value="process">
			</font>Informacion<font size=8><input type=text name="Information"></input><br>
			<input type="hidden" name="stage" value="process">
            </font>Comentario<font size=8><textarea name="Comentario" rows="4" cols="20" size="18"></textarea><br>
			<input type="hidden" name="stage" value="process">  
	  <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" size="10"></input></font><br>
			  Peso<font size=8><input type=text name="Peso" size="10"></input></font><p>
			  Valor<font size=8><input type=text name="Valor" 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">
			  </div>	  
		</form>
END;
}

/* conectarse con el base datos a entro db.php, aqui solo ponerlo el informacion */

function process_form() {
$query ="INSERT INTO pongo VALUES  ('".$_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())"; 
}
?>

Posted: Thu Jan 22, 2004 12:59 pm
by infolock

Code: Select all

function process_form()
{
// are all these values going into the field PONGO or is pongo the table name?  if it's the table name, instead of the table name put field names like i've done
$query ="INSERT INTO (empresa, codigo, desde, envio, envio, information, comentario, peso_total, peso, valor) VALUES  ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Desde']."','".$_POST['Envio']."','".$_POST['Information']."','".$_POST['Comentario']."','".$_POST['Peso_Total']."','".$_POST['Peso']."','".$_POST['Valor']."')"; 

//then do this and see if you get any errors...
$result = mysql_query($query) or die (mysql_error());
}

Posted: Thu Jan 22, 2004 1:00 pm
by ol4pr0
yea pongo = table name.

all the others are fields

let me try and get back ;-)

Oke did it... well i feel i am getting better sinds now there was ecually a error being returned.. :>
Connectando Con Base Datos pongo , avancar! 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 '(Empresa, Codigo, Desde, Envio, information, comentario, peso_t
it might be me .. or just because you could boil a egg on my head now with the 40 degrees C however i am lost

Posted: Thu Jan 22, 2004 1:39 pm
by infolock
oh lol. i guess i had a typo in the insert syntax and forgot to put the table name heh

Code: Select all

$query ="INSERT INTO pongo (empresa, codigo, desde, envio, envio, information, comentario, peso_total, peso, valor) VALUES  ('".$_POST['Empresa']."','".$_POST['Codigo']."','".$_POST['Desde']."','".$_POST['Envio']."','".$_POST['Information']."','".$_POST['Comentario']."','".$_POST['Peso_Total']."','".$_POST['Peso']."','".$_POST['Valor']."')";
that should work..

Posted: Thu Jan 22, 2004 1:42 pm
by ol4pr0
Oke so for the next time i should

first call on all fields and than do the $_post['fieldname'] correct?

Now i know because i am using a function this might cuase it not te be returned to the <form page>

is there a way to have it return to the form page

and are php functions private?

Posted: Thu Jan 22, 2004 1:48 pm
by infolock
the private part i'm not sure about.

but as far as the $_POST question, i'm not very sure. so instead i'll just give you some examples and explain every portion of that question to make sure i answer it..

basicallly, you can call $_POST['whatever'] anywhere you want..

so, you could do this :

Code: Select all

$sql = "INSERT into ".$_POST['mytable']." (".$_POST['my_field_name']." VALUES ('".$_POST['my_value']."')";
or

Code: Select all

$value = $_POST['my_value'];
$sql = "Select my_field from my_table where my_field = '".$value."');
or any other combination you want.


==========EDIT========
first call on all fields and than do the $_post['fieldname'] correct?
yes. call the field names, then put the values as mysql wont know what to do with those values until you declare so..

Posted: Thu Jan 22, 2004 1:55 pm
by ol4pr0
Gracias., let me see if i can figure out how to have this page return to its form withouth having to press F5 ;-)