RE: Data won't insert

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jeffrey

Most probably site 2 has register_globals set to Off whilst site 1 has them
set to On...

Try using $_POST['name'] for $name, $_POST['age'] for $age and
$_SERVER['PHP_SELF'] for $PHP_SELF

Cheers
Rich
-----Original Message-----
From: Baumgartner Jeffrey [mailto:j.baumgartner@itp-europe.com]
Sent: 23 January 2003 10:42
To: php-db@lists.php.net
Subject:  Data won't insert


I've learned the basics of PHP and MySQL by using a web hosting service over
the past few weeks. Call this site 1. And I am finally feeling that I am
getting the hang of things.

Now, another web host that I have been using is letting me try out PHP and
MySQL on their server. Call this site 2.

The problem I am having is that if I take pages with php scripts from site
1; change the user, password and database names; and upload them to site 2 -
data does not insert into tables. However, the scripts are connecting to the
database (no die messages or other error messages are appearing) and the
tables have been prepared via phpmyadmin without problem. Likewise, I can
insert data via phpmyadmin without problem.

Below is a sample script that is causing such a problem. I appreciate that
it is sloppy (it was one of my first). But it works on site 1 and not site
2.  Could this be a matter of the permissions the site 2 web host has
granted me? And if so, why can I do things with phpmyadmin but not via my
own scripts?

Many thanks,

Jeffrey Baumgartner


<?php
$dbcnx = mysql_connect("localhost", "USER", "PASSWORD");

$db = mysql_select_db("TABLENAME", $dbcnx) or die("Couldn't get DB");

If (isset($name)) {
echo "<P>" . $name . "</p> <P>" . $age . "</p>";
}

?>

<FORM ACTION="<?php echo($PHP_SELF);  ?>" METHOD="POST">
<P> Name: <INPUT TYPE=TEXT NAME="name" SIZE="62"></p>
<P> Age: <INPUT TYPE=TEXT NAME="age" SIZE="8"></p>
<INPUT TYPE=SUBMIT NAME="submitInfo" VALUE="Submit">

<?php

if (isset($name))  {
$query = "INSERT INTO formtest (name,age) VALUES ('$name' , '$age')" ;

if (mysql_query($query)){
echo "<P>" . $name . "</p> <P>" . $age . "</p>";
}

else {
echo ("<p>Tough cookies, sunshine</p>");
exit();
}
}


?>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux