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); 2 2435
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).
*** drakorq escribió/wrote (7 Sep 2006 08:10:05 -0700):
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.
Certainly it is. It also have several typos.
<p>Enter the product number: <input type="text" name"number" size="10"
value="128"></p>
name="number"
$sql = "INSERT INTO table_productspecs
(product_number, product_name, kiloprice)
VALUES
($number, '$name', $price_punkt)";
mysql_query($sql);
Rather than:
"INSERT INTO table (column) VALUES ('$foo')"
Use this:
"INSERT INTO table (column) VALUES ('" . mysql_escape_string($foo) . "')"
You can also use mysql_real_escape_string()
<p>Product number: <?php print $number ?>.</p>
<p>Product number: <?php print htmlspecialchars($number) ?>.</p>
or
<p>Product number: <?=htmlspecialchars($number)?>.</p>
$dbconnection = mysql_pconnect("localhost","dbuser","password")
or die("Could not establish connection with mysql_connect.");
Using a persistent connection means that PHP will remain connected to the MySQL server even when no one is visiting the site. This can make MySQL run out of connection slots even under low load. I suggest you use mysql_connection() unless you have a good reason.
--
-+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
++ Mi sitio sobre programación web: http://bits.demogracia.com
+- Mi web de humor con rayos UVA: http://www.demogracia.com
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: phil |
last post by:
I am having a problem with the C api with prepared statements, the data
recorded in the database does not match the data I am sending. It seems to
be some sort of bit shifted version of the data,...
|
by: Lyn |
last post by:
Hi,
I am working on a genealogy form. The only table (so far) lists everybody
in the family, one record per person. Each record has an autonum ID.
The parent form (frmMainForm) displays the...
|
by: cover |
last post by:
I have a form that writes to an MySQL database just fine but would
like to email people to give them a heads up that an entry was made
under their name (1 of 6 names on writing to the database). ...
|
by: Amer Neely |
last post by:
I have a simple form that is giving me grief in IE (6) and has me
stumped. It works fine with Mozilla. No JavaScript involved.
Visit http://www.softouch.on.ca/cgi-bin/confirmation_ie.pl
Other...
|
by: h7qvnk7q001 |
last post by:
I'm trying to implement a simple server-side form validation (No
Javascript). If the user submits a form with errors, I want to
redisplay the same form with the errors highlighted. Once the form...
|
by: Chris |
last post by:
Hi,
I have a form for uploading documents and inserting the data into a mysql
db. I would like to validate the form. I have tried a couple of Javascript
form validation functions, but it...
|
by: vladimir.plotnikov |
last post by:
Hello!
I have problem:
I have IPB forum installed. After search in IPB (search takes about 3-4
seconds for post table about 300 000 records) mysql shows "Sending
Data"
status and takes about...
|
by: David W. Fenton |
last post by:
I've been struggling the last two days with something I thought was
very easy, which is to open a web page with a form on it and
populate the form with data passed in a query string (either POST or...
|
by: bleachie |
last post by:
Hi,
My e-mail form seems to work fine in IE7 but doesn't work in FireFox2.0 - it just goes to the index.php instead of echoing the completed message.
Hope someone can help me out.
Form.html...
|
by: starter08 |
last post by:
Hi,
I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket.
On the server side I have a cgi...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |