| 
	
 | 
 Posted by ZeldorBlat on 09/07/06 16:05 
drakorq wrote: 
> I got stuck on this, and it would be really great if anybody could 
> point me in the right direction. 
> 
> I was trying setting up these scripts following instructions in a book 
> from 2003, so I thought maybe some of the code might be outdated. 
> 
> Basically this is what Is supposed to happen: 
> 1.- Display a form, enter details into fields and click submit. 
> 2.- After having clicked on submit you're redirected to another page 
> that will display the entered values and store them in the MySQL DB 
> specified. 
> 
> Now what happens is that no errors are displayed after clicking on the 
> submit button in the form, but neither are the entered values. In 
> PHPMyAdmin I can see that the Db is still empty. 
> 
> I created a total of 3 files that reside in the same folder: 
> 
> The form, that when clicking on submit is redirected to the next file: 
> 
> <html> 
> <head> 
> <title>product_registration.htm</title> 
> <meta http-equiv="Content-Type" content="text/html; 
> charset=iso-8859-1"> 
> </head> 
> 
> <body> 
> <h1>Registration of products</h1> 
> <FORM METHOD="post" ACTION="insert_into_and_response.php"> 
> <p>Enter the product number: <input type="text" name"number" size="10" 
> value="128"></p> 
> <p>Name of product: <input type="text" name"name" size="30" 
> value="Mango"></p> 
> <p>Price per kilo: <input type="text" name"price" size="10" 
> value="24,40"></p> 
> <p><input type="submit" value="Send data" name="B1"> 
> <input type="reset" value"Reset"  name="B2"></p> 
> </body> 
> </html> 
> 
> The file that sends the data to DB, and shows you what you just entered 
> in the form: 
> <html> 
> <head> 
> <title>insert_into_and_response.php</title> 
> <meta http-equiv="Content-Type" content="text/html; 
> charset=iso-8859-1"> 
> </head> 
> 
> <body> 
> <?php 
> $pris_punkt= ereg_replace(",",".",$price); 
> include ("dbconnect.php"); 
> $sql = "INSERT INTO table_productspecs 
> (product_number, product_name, kiloprice) 
> VALUES 
> ($number, '$name', $price_punkt)"; 
> mysql_query($sql); 
> ?> 
> <h1>Received following data</h1> 
> <p>Product number: <?php print $number ?>.</p> 
> <p>Name of product:: <?php print $name ?>.</p> 
> <p>Price per kilo: <?php print $price ?>.</p> 
> 
> </body> 
> </html> 
> 
> The configuration file containing all the details required to connect 
> to the DB: 
> <?php 
> $dbconnection = mysql_pconnect("localhost","dbuser","password") 
> or die("Could not establish connection with mysql_connect."); 
> mysql_select_db("DB-name",$dbconnection) 
> ?> 
> 
> The code that made the DB: 
> CREATE TABLE table_productspecs 
> (idx INT AUTO_INCREMENT PRIMARY KEY, 
> product_number INT NOT NULL UNIQUE, 
> product_name VARCHAR(30) NOT NULL, 
> kiloprice DECIMAL(5,2) NOT NULL); 
 
Two problems: 
 
First (and it might be a typo) the HTML for the form elements is 
incorrect: 
<input type="text" name"number" size="10" value="128"> 
 
Needs an equal sign on the name attribute: 
<input type="text" name="number" size="10" value="128"> 
 
The second potential problem is that the script you've posted requires 
register_globals to be enabled in php.ini.  Recent versions of PHP have 
this disabled by default.  Either turn it on (bad) or fix the script to 
not require it (good).
 
  
Navigation:
[Reply to this message] 
 |