PHP Form Still writes the same phone number to MySQL Database.

Hello everyone I am new to the Forum, so I hope I am posting in the right place.

I have a MySQL DB setup via PHPAdmin.

I have a PHP form that writes a phone number to the database.
No matter what phone number I place in the input box, the previous deleted phone number is written to the database.

So I deleted all data in the table cleared cache in the browser (for all History), and I still get the same number no matter what phone number I put in the input box.

So I copied the entire database, deleted the original and it still puts the same phone number in the phone column.

I tried to flush the table, but I cant seem to find the option to enable those priveleges.

It is not in the user priveleges.

Any assistance is appreciated.
 
Unfortunatley I cannot display the code for this project.

However I did create a unique index for the phone column
I also went to Opeations for the table and cleared data using Truncate.

I then cleared all cache for all history from the browser and entered a new phone number
I am now getting a duiplicate entry error:

[05-Aug-2024 10:40:12 America/Boise] PHP Fatal error: Uncaught mysqli_sql_exception: Duplicate entry '2147483647' for key 'uindxphone' in

I think I can conclude that somehow the phone number is coming from the form.
But if all history is cleared (for all time) I don’t see how the form is retaining that number.
I also ran ccleaner and cleared all cache entries for all browsers

Update:10:10 AM 8/5/2024 (PST) - I wrote in a var_dump on the php form to see what was intially being sent by the form it was ten numbers for the phone entry 1111111111 which is correct but when I checked the phone column in the DB it was 2147483647
incidently this was a number entry that was deleted 10hrs ago.
I am now getting PHP Warning: Undefined array key "phone" which is normally a syntax error above or below that line. I am checking....
 
This is not really a FreeBSD question, it seems far more likely you’ve got a bug in your code, and given that you can’t share that, it would be difficult to help.

Add more debug code to your PHP code to make sure everything is working exactly as you expect.
 
I doubt that (in the general case at least) any numeric datatype would be the right choice.
as long as you don't need to store any numbers with area codes higher than 214 in a signed 32bit INT field in mysql. Varchar would be best as suggested above.
 
as long as you don't need to store any numbers with area codes higher than 214 in a signed 32bit INT field in mysql. Varchar would be best as suggested above.
That's already quite a distance from the general case... Using varchar would definitely be a good start, but would still leave all sorts of normalising issues. Sadly, there just is no free lunch.
 
Guys

TY so much for your input.

I applied the unique index and caused another problem.

It was then I realize I conveyed my issue poorly.

I want a unique index to allow multiple entries for two columns incremented by ID
But no entry using that use only one of the values.


meaning two columns:

The DB would allow multiple entries of John Doe / 2222222222

But would generate an error for John Doe / 8675309 or Tim Johnson / 2222222222

I hope I am making sense
 
I can't see an obvious way that you're going to be able to do that simply using database indexes.
You'll likely need to run some select queries first to find any existing entries that will make the new one invalid.

1) get a count of any rows where the number is the same as input, but the name isn't
2) get a count of rows where the name is the same, but the number isn't

If either of these queries return a count above 0 then the new entry is not valid and an error should be shown to the user. Of course this raises further complications in that there could be variations in the formatting - space/no space in the number, caps/no caps in the name, etc, etc.
 
you can create a trigger before insert which will check for conditions
SQL:
DROP TRIGGER if exists checkxx;
DELIMITER $$
CREATE TRIGGER checkxx BEFORE INSERT on name_phone_table
FOR EACH ROW
BEGIN
  DECLARE juf int;
  DECLARE msg varchar(255);
  select if(NEW.phone = col_phone,1,0) + if(NEW.name = col_name,1,0) as val
  from name_phone_table
  where NEW.phone = col_phone or NEW.name = col_name limit 1 into juf;
  if juf = 1 then
  set msg = 'Name or phone but are not unique';
  SIGNAL SQLSTATE '45000' SET message_text = msg;
  end if;
END$$
DELIMITER ;
 
You can use XDebug and debug the php code at it's runtime. I use it remotely with NetBeans from the Windows machine to FreeBSD server.
 
This is very challenging:
It seems after several days the same behavior starts again
the values in the columns below was not there 12 hrs ago
and I am the only one who has access to the db


I also made sure no duplicate values were inserted.
The values for each of those columns were then verified after the form was submitted.
and the phone number in the column was deleted over 3 weeks ago
The phone numbers listed in columns 2 - 5 should be different.
I also started over and Truncated the entire table:
tempcvhrt.png

Using phpMyAdmin is there a quick way to clear the cache?
 
TY for that - I had forgot about that...
The datatype was set to varchar - but I caught that this morning and changed it to int as well as the paramater binding in the insert php file

In fact I think I will play it safe and switch to BIGINT
Also as an 20 yr vulaerability tester I will periodcially do the unexpected.
TY again
 
Phone numbers aren't really numbers, they are really just strings of text that just so happen to be limited to only be formed of the digits 0-9 and sometimes + and - if you need to support international formats or users who type 213-555-123456. Unless you are doing math operations on them, which I suspect is unlikely, a text data type like varchar is probably preferable over integers.
 
Back
Top