473,507 Members | 8,335 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php lost variable 0 from the form when i try to save it into mysql database - please help

Hello to anyone who is tring to help me :-)

As I was writed in the topic I have problem when somone input 0 value in the
form.
PHP is losting this value when it try to write it to mySQL.
I have php version 4.3.11 mysql 4.1.14 and apache 2.0.53

Please help because I don't know what is wrong.

The column type in database is float. When I try to add some record thru the
phpmyadmin for exapmle, everything is all right.
It is also right when the value is 0.0 but mysql save it as 0

Below is code from php (first the form in html, second sql statement in php)

--html--
<tr class=wiersz_2 valign="center" align="center" >
<td align="right">Zasadowo¶ć typu p :</td>
<td>
<input maxlength="6" size="6" name="zasadowosc_typu_p" tabindex="3">
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
--html--

--php--
if(!empty($_POST['zasadowosc_typu_p'])) $zasadowosc_typu_p_b =
(double)$_POST['zasadowosc_typu_p'];
else
|
$zasadowosc_typu_p_b = -1; (I even try to change
temporary type of this variable)
if(!empty($_POST['twardosc_ogolna_w'])) $twardosc_ogolna_w_b =
$_POST['twardosc_ogolna_w'];
else
$twardosc_ogolna_w_b = -1;
..
..
..
$SQL = "INSERT INTO pomiary (obiekt, nazwa_pomiaru, wartosc, id_datap)";
$SQL .= " (SELECT '{$_SESSION['obiekt_b']}', 'zasadowosc_typu_p',
$zasadowosc_typu_p_b, datap.id";
$SQL .= " FROM datap";
$SQL .= " WHERE datap.id = (SELECT max(datap.id) from datap))";
$ResultSQL = mysql_query($SQL);
$SQL = "INSERT INTO pomiary (obiekt, nazwa_pomiaru, wartosc, id_datap)";
$SQL .= " (SELECT '{$_SESSION['obiekt_b']}', 'twardosc_ogolna_w',
$twardosc_ogolna_w_b, datap.id";
$SQL .= " FROM datap";
$SQL .= " WHERE datap.id = (SELECT max(datap.id) from datap))";
$ResultSQL = mysql_query($SQL);
--php--
Feb 4 '06 #1
1 2497

Dominik Szczurek wrote:
Hello to anyone who is tring to help me :-)

As I was writed in the topic I have problem when somone input 0 value in the
form.
PHP is losting this value when it try to write it to mySQL.
I have php version 4.3.11 mysql 4.1.14 and apache 2.0.53

Please help because I don't know what is wrong.

The column type in database is float. When I try to add some record thru the
phpmyadmin for exapmle, everything is all right.
It is also right when the value is 0.0 but mysql save it as 0

Below is code from php (first the form in html, second sql statement in php)

--html--
<tr class=wiersz_2 valign="center" align="center" >
<td align="right">Zasadowo¶ć typu p :</td>
<td>
<input maxlength="6" size="6" name="zasadowosc_typu_p" tabindex="3">
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
--html--

--php--
if(!empty($_POST['zasadowosc_typu_p'])) $zasadowosc_typu_p_b =
(double)$_POST['zasadowosc_typu_p'];
else
|
$zasadowosc_typu_p_b = -1; (I even try to change
temporary type of this variable)
if(!empty($_POST['twardosc_ogolna_w'])) $twardosc_ogolna_w_b =
$_POST['twardosc_ogolna_w'];
else
$twardosc_ogolna_w_b = -1;
.
.
.
$SQL = "INSERT INTO pomiary (obiekt, nazwa_pomiaru, wartosc, id_datap)";
$SQL .= " (SELECT '{$_SESSION['obiekt_b']}', 'zasadowosc_typu_p',
$zasadowosc_typu_p_b, datap.id";
$SQL .= " FROM datap";
$SQL .= " WHERE datap.id = (SELECT max(datap.id) from datap))";
$ResultSQL = mysql_query($SQL);
$SQL = "INSERT INTO pomiary (obiekt, nazwa_pomiaru, wartosc, id_datap)";
$SQL .= " (SELECT '{$_SESSION['obiekt_b']}', 'twardosc_ogolna_w',
$twardosc_ogolna_w_b, datap.id";
$SQL .= " FROM datap";
$SQL .= " WHERE datap.id = (SELECT max(datap.id) from datap))";
$ResultSQL = mysql_query($SQL);
--php--


empty() doesn't behave exactly as you'd expect. You can read up on it
here:

<http://www.php.net/empty>

The short of the matter is that 1) all input coming from a form (i.e.
through $_POST) will be a string; 2) empty() returns true for false, 0,
"0" (the string 0), "" (the empty string), and null. So, if the user
inputs 0 into the form, your !empty() test fails and you get -1.

An easy fix that will give you the desired behavior (-1 if they put in
nothing or something other than a number) would be to switch your
!empty() calls to is_numeric(). This will return true for any numeric
string ("0", "0.0", "42.2", etc.) and false for anything else
(including the empty string).

Feb 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3200
by: PinkBishop | last post by:
Hello All, Hope you can help. Below is the code I use to send data from form to database. Problem is if an apostrophe is entered in cQuestion field or any field for that matter the form...
3
5434
by: Matias Silva | last post by:
Hi Everyone, I wrote a for loop to build several select statements that are combined with a UNION. When I execute one of the queries separately, it works, but when I execute the query with a UNION...
16
11814
by: David Lauberts | last post by:
Hi Wonder if someone has some words of wisdom. I have a access 2002 form that contains 2 graph objects that overlay each other and would like to export them as a JPEG to use in a presentation....
15
12088
by: Lauren Wilson | last post by:
Access 2K dim MyStr as string What is the maximum amount of text or bytes that this variable can store? Does anyone know?
6
8339
by: Vyoma | last post by:
This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I have been lurking around at several forums with regard to login and user authentication scripts and...
2
5239
by: Boujii | last post by:
Greetings, I have been attempting to make a drop down menu of countries. From this menu I wish to create a variable in order to INPUT into mysql database. I have no trouble making the drop down menu,...
5
2009
by: deaconj999 | last post by:
Hi, I have nearly finished my database and I would like to add a query that uses a combo box to get the results, not the usual paramater style input. I suppose it would need a form and a query...
1
4257
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on...
4
1724
by: Cigar2011 | last post by:
I will try to be short and to the point.(good Luck) I have a form written in HTML. I have a Mysql database. I am using a linux server and I would like to use php to write the following code: ...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.