Jump to content

Value has question mark infront when I use echo


Go to solution Solved by requinix,

Recommended Posts

Hi. Don't know where to put this, but I am guessing that I have a problem with my sql table. 

 

I have a column who has the setup varchar(10), utf8_general_ci 

 

At one row I have the value 58.0326, when I do a query and echo the data it outputs exactly "58.0326".

But in another row I have the value 63.44528 but when I echo that it comes out "?63.44528" on the webpage. 

 

 

I have tried to search and google for an answer to this problem but havent been able to find anything. Hope one of you php freaks can help me. :)

I imported a csv file to the sql database, hence the varchars everywhere. Since I am quite unexperienced to sql and php I wanted to get my homepage up and running and then deal with trimming the database and dealing with validations and stuff like that. 

 

Would the VARCHAR crop the data? I suspect I should use float instead, but still... does it explain why some numbers come out right on the homepage and some dont with the same sql querys? 

 

The particular value has an exclamation mark (?) infront of it when I use a query and then echo the value to my homepage. When I look at the value in the database it looks fine. And with the same query most of the rows output just fine.

It would truncate the strings to 10 characters but that probably wouldn't pose a problem for you unless you're dealing with numbers in the millions. And yes, you should use either a float or a decimal type for that data (probably float).

 

There is something there, even if you can't see it "in the database". Have you looked for it in the CSV?

Yes. I checked the csv file and That particular field was blank when I imported the file. This value that ends up having the question mark infro t was added manually after the import. I did this through phpmyadmin.

 

I tried deleting the value and adding it again without any result. I also tried to export the current sql to a csv file to see if there was something infront of the value, but there wasnt anything there.

 

When I did the import I had another column with coordinates in degrees with the degree character. These values was corrupt after the import, only the first two digits was left... Could this have made the whole db corrupt in some way?

  • Solution

Then it might be a problem with whatever you're using to manually set those values. If it's just a one-time thing (it's not like the problem keeps popping up in places where it wasn't before) then I'd say just fix the values manually. I'm not sure what this "deleting the value and adding it again" means but try just issuing an UPDATE query (or maybe DELETE and INSERT?) with the right value. Typed manually so you're sure there's nothing else in there.

 

Could that be a degree character °? Yeah, but there's no way to "un-question mark it" to know. Would something have corrupted the entire database? No, but it didn't sound like there were widespread problems and that it was just this value (or maybe a couple others).

That is a good tip kicken. However I am not sure on how to do that correct. 

 

If I do a command in the sql command prompt like this: 

 

SELECT HEX(name of column) 
FROM `namn of database` 
WHERE relid LIKE 3 

// relid 3 is that particular row... 
 

 

Would that give me the correct output?

Then it might be a problem with whatever you're using to manually set those values. If it's just a one-time thing (it's not like the problem keeps popping up in places where it wasn't before) then I'd say just fix the values manually. I'm not sure what this "deleting the value and adding it again" means but try just issuing an UPDATE query (or maybe DELETE and INSERT?) with the right value. Typed manually so you're sure there's nothing else in there.

 

Could that be a degree character °? Yeah, but there's no way to "un-question mark it" to know. Would something have corrupted the entire database? No, but it didn't sound like there were widespread problems and that it was just this value (or maybe a couple others).

 

I used the GUI of phpmyadmin to erase and then input the data again. 

 

Now I tried both update query and delete and insert but I still get that pesky question mark... I entered the values manualy to be sure that there wasn't an issue with copy and paste. This has happened on a couple of other places in this particular column, say 50% of the values I enter after the import of the csv file has a ? infront of the values. 

Apparently when I replace the field with 'NULL' and then reenter it the mystic question mark is gone. Updating apparently just updates the value that I see in the GUI. I am guessing that this is due to that something went wrong with the import of the file since there are special characters and a charset with Swedish characters in it. Thanks for the help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.