Forum Moderators: coopster
<html>
<body>
<form action=feg-submitform2.php method=GET>
Clave: <br><input type=text name=clave size=25 maxlength=25><br><br>
Sección: <br><input type=text name=seccion size=25 maxlength=25><br><br>
Nombre: <br><input type=text name=nombre size=25 maxlength=25><br><br>
Descripción: <br><textarea name="descripcion" rows="10" cols="50"></textarea><br><br>
Extras: <br><textarea name="extras" rows="10" cols="50"></textarea><br><br>
<p>
<input type=submit>
</form>
</body>
</html>
and this is feg-submitform2.php:
<html>
<body>
<?php
mysql_connect (localhost, root, password);
mysql_select_db (fegal);
mysql_query ("INSERT INTO productos (clave, seccion, nombre, descripcion, extras)
VALUES ('$clave', '$seccion', '$nombre', '$descripcion', '$extras')
");
print ($clave);
print (" ");
print ($seccion);
print (" ");
print ($nombre);
print (" ");
print ($descripcion);
print (" ");
print ($extras);
print ("<p>");
print ("El producto anterior fue registrado");
?>
</body>
</html>
when i press submit in the HTML form, the information i entered in the form is not inserted in MySQL, i just see the message: “El producto anterior fue registrado”, i can’t see the product information i entered, and i should be able to see printed that data (clave, sección, and so on). i check in phpmyadmin and i can see that a new row is created but is completely empty, so i suppose the form inserts data in the database, but the text i type in the form is not passed to the database table. i have tried processing the info in the same page (using action="<?php echo $PHP_SELF?>"). i do not know what’s wrong. can anyone help me please? Thanx in advance.
If you want to access those you will need to use
$_GET['$nombre'] or $_POST['$nombre']
instead of just $nomre
(respectively $HTTP_GET_VARS['$nombre'] or $HTTP_POST_VARS['$nombre'] if you are using an older version of PHP < 4.1.0, highly unlikely though ;))
For more information read the php-documentation:
[php.net...]
[php.net...]
to:
$_GET['$clave'], $_GET['$seccion'], $_GET['$nombre'], $_GET['$descripcion'], $_GET['$extras']
and then for:
$_POST['$clave'], $_POST['$seccion'], $_POST['$nombre'], $_POST['$descripcion'], $_POST['$extras']
and it doesn’t work, when i press submit in my form, i get a message:
“Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 6”.
line 6 is as follows:
mysql_query ("INSERT INTO productos (clave, seccion, nombre, descripcion, extras)
VALUES ($_GET['$clave'], $_GET['$seccion'], $_GET['$nombre'], $_GET['$descripcion'], $_GET['$extras'])
");
i also tried using $HTTP_POST_VARS but i get the same error.
security is not a problem with my data, because i’ll be the only one populating the database and i’m the only person using this computer.
i know this is a very stupid problem, that’s what i think that (probably) the answer is not so hard. please somebody with the answer help me. thanx in advance.
[php.net...]
[edited by: andreasfriedrich at 1:55 pm (utc) on Dec. 9, 2002]
this error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 6
means i don’t have to put “$_GET['$nombre']” in the SQL query.
instead i have done this:
<?php
$_GET['$clave'];
$_GET['$seccion'];
$_GET['$nombre'];
$_GET['$descripcion'];
$_GET['$extras'];
mysql_connect ("localhost", "root", "password");
mysql_select_db ("fegal");
mysql_query ("INSERT INTO productos (clave, seccion, nombre, descripcion, extras)
VALUES ('$clave', '$seccion', '$nombre', '$descripcion', '$extras')
");
and instead of an error i get a warning:
Warning: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 6
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 6
Warning: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 7
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 7
Warning: MySQL: A link to the server could not be established in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 7
Warning: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 10
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 10
Warning: MySQL: A link to the server could not be established in /Users/rodrigos/Sites/testing/feg-submitform2.php on line 10
what all of this mean?
how do i have to use the “$_GET['$nombre']”?
i just need some more hints to make it on my own, someone give me more advice please. thanx in advance
now, i have this code:
<?php
mysql_connect ("localhost", "root", "password");
mysql_select_db ("fegal");
mysql_query ("INSERT INTO productos (clave, seccion, nombre, descripcion, extras)
VALUES ('$_GET[$clave]', '$_GET[$seccion]', '$_GET[$nombre]', '$_GET[$descripcion]', '$_GET[$extras]')
");
could it be possible that the connection with MySQL is not working?
… i think that’s the problem, i can’t even access MySQL with phpmyadmin!
what can i do to restart the connection with MySQL?
How to restart mysql depends on whether you are on a shared host or have root access. In the former case you may need to have your provider restart it or there might be a way to do that from your admin area. In the latter case shut mysqld down using mysqladmin and restart it again.
Andreas
and now i have this code:
<?php
mysql_connect ("localhost", "root", "password");
mysql_select_db ("fegal");
mysql_query ("INSERT INTO productos (clave, seccion, nombre, descripcion, extras)
VALUES ('$_GET[$clave]', '$_GET[$seccion]', '$_GET[$nombre]', '$_GET[$descripcion]', '$_GET[$extras]')
");
but still, the information entered in the form doesn’t get it through the database. i check in phpmyadmin and i just see a new row without the information i entered in the form.
what’s wrong now?
should read
mysql_query ("INSERT INTO productos (clave, seccion, nombre, descripcion, extras)
VALUES ('$_GET[clave]', '$_GET[seccion]', '$_GET[nombre]', '$_GET[descripcion]', '$_GET[extras]')
");
Andreas