Silly INSERT and UPDATE problem in HTML/php code

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Silly INSERT and UPDATE problem in HTML/php code

Postby bangnoai » 03. August 2006 14:36

Hi there,

I am working on (I think) the latest XAMPP version with an Apache/2.2.2 (Win 32) and a Php/4.4.2 version. Have to use Php 4.4.2 to develop HTML/Php code, as the final host hasn't upgraded to Php 5 yet.

Plus I took care to double-check I have register_globals set to "off" in my C:\Program Files\xampp\apache\bin\php.ini.

Now, the silly problem I face currently is on my local installation, every manoeuver I try in my code to either INSERT or UPDATE a row in a perfectly regular table fails without delivering any error message whatsoever. All fields to be filled up are varchar, no fancy stuff about that.

I use the regular pair :

mysql_query($sql,$connect);
if(mysql_affected_rows()){
$r = $_POST['name_first']." ".$_POST['name_nick']." ". $_POST['name_last'];
$r = "Record ".$r." has been added";}
else{
die('SQL Error !'.$sql.'mysql_error());}

in each INSERT or UPDATE case. The end result is it goes smoothly through the instructions, yet the code won't achieve what it is prescribed to do. AND I don't get the table modified.

I leafed through any *.ini and *.conf file I could think of, starting from \xampp downward without success up to now.

Anybody got any bright idea 'bout where to search a solution?

Thanks in advance.
bangnoai
 
Posts: 4
Joined: 03. August 2006 12:43

Postby Wiedmann » 03. August 2006 14:59

I can't see any INSERT or UPDATE statement in your sample code?

BTW:
You should add a "or die(mysql_error());" to mysql_query().
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Postby bangnoai » 03. August 2006 17:28

Thanks for replying. I didn't put INSERT and UPDATE before for the sake of brevity. It reads :

if($_POST['type']=="addn"){
$sql = "INSERT INTO $tabl VALUES ('',
'{$_POST['city']}',
'{$_POST['precision']}',
'{$_POST['state']}',
.
.
.
'{$_POST['date_modif']}');";

then the lines I've put in before:

mysql_query($sql,$connect);
if(mysql_affected_rows()){
$r = $_POST['name_first']." ".$_POST['name_nick']." ". $_POST['name_last'];
$r = "Record ".$r." has been added";}
else{
die('SQL Error !'.$sql.'mysql_error());}

and
elseif ($_POST['type']=="edit"){
$sql = "UPDATE $tabl
city = '{$_POST['field_town']}',
precision = '{$_POST['field_prec']}',
state = '{$_POST['field_cant']}';";

then again what I've put in before:

mysql_query($sql,$connect);
if(mysql_affected_rows()){
$r = $_POST['name_first']." ".$_POST['name_nick']." ". $_POST['name_last'];
$r = "Record ".$r." has been added";}
else{
die('SQL Error !'.$sql.'mysql_error());}

Still can't figure out where the source of the problem lies. I know my code works fine, because it's been tested on the remote ISP's localhost and it goes seamlessly there.
bangnoai
 
Posts: 4
Joined: 03. August 2006 12:43

Postby Wiedmann » 05. August 2006 19:03

$sql = "INSERT INTO $tabl VALUES ('',

Where did you define the value of "$tabl"?

mysql_query($sql,$connect);

Where did you define the value of "$connect"?

mysql_query($sql,$connect);

Rewrite this line to:
Code: Select all
mysql_query($sql,$connect) or die(mysql_error());


Add:
Code: Select all
error_reporting(E_ALL);

at the top of your script.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Silly questions lead to sound answers

Postby bangnoai » 06. August 2006 15:36

Hi,

Nailed down the problem eventually. I had the unfortunate idea to give my second field the name 'precision'. I could find nowhere in the doc that it was most probably a reserved name, not to be used in a table. At least, that's what I guessed after having changed this name and seen the damn thing working at last with my own eyes :lol:

Thanks anyway for your help.
bangnoai
 
Posts: 4
Joined: 03. August 2006 12:43

Postby Wiedmann » 06. August 2006 15:48

Nailed down the problem eventually.

Right. "or die(mysql_error());" is really a "must have" ;-)

I could find nowhere in the doc that it was most probably a reserved name

Now I'm your personal manual reader...:
http://dev.mysql.com/doc/refman/5.0/en/ ... words.html

I had the unfortunate idea to give my second field the name 'precision'. ... , not to be used in a table.

You should also read:
http://dev.mysql.com/doc/refman/5.0/en/legal-names.html
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Many thanks

Postby bangnoai » 06. August 2006 15:56

I usually make a point of reading docs carefully. I suppose I was so much engrossed in finding a solution that I missed this one for 2 days.

Anyway, you're a great reader! Thanks

:D
bangnoai
 
Posts: 4
Joined: 03. August 2006 12:43


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 121 guests