Any idea why my database inserts are playing up?

Status
Not open for further replies.

shopx102

New Member
Messages
7
Reaction score
0
Points
1
Hi,

I'm just wondering if anyone might have any idea what could be causing some odd behavior in my code? I've uploaded files that make a basic GUI, so basically just a CRUD system to manage news items. However, the system was working in development but it's behaving oddly now that it's uploaded to x10host.

I figured out that I'd set the file that connects to the database to connect to the wrong database, so I changed that and I managed to get the information that's stored in the database to be read, but for some reason I'm not able to write to the database. It looks like the code I have should write to the database but when I run a test it's just going right past all the code as though there's no errors in the code, but it doesn't actually write to the database.

I'm fairly sure I set the user to have all access to the database. I'm using two of my allowed two databases and I have 2.33MB of data stored in them. What's the limit for data storage? Is there something else that might be causing this?
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
Have you tried manually entering a database query into phpMyAdmin to see if the MySQL version used supports how the query is laid out? Is your 'host' set to something like 'localhost'? Have you enabled privileges for your database user such as INSERT?
 

shopx102

New Member
Messages
7
Reaction score
0
Points
1
I tried to manually insert and it worked, though I had to change the values from variables to strings. I AM using 'localhost'. Should it be something different?
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
No, "localhost" is right; the question was just phrased a little awkwardly. Next step, I suppose, would be to determine whether of not the variables contain what you think they contain in that block of code.
 

shopx102

New Member
Messages
7
Reaction score
0
Points
1
I'm fairly sure that the variables should contain what they're supposed to. I suspect that's it's probably not because of the new mysqli statements, as I'm connecting to the database using those. I changed the variables, but that doesn't seem to have fixed it either. I'm not sure if it's appropriate to post code here, but I'll post a little bit just to save time.

This is the old version of the variables:
if (isset($_POST['headline']))$headline = $_POST['headline'];

This is what I changed it to:
$headline = $_POST['headline'];

But neither of those work.
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
For debugging purposes, you can try the following during a POST request:
PHP:
echo var_dump($_POST);
That will show what is in that POST request along with the values and names.
 

shopx102

New Member
Messages
7
Reaction score
0
Points
1
Ok, so the var dump showed that the POST included the correct values for the strings, but there was no record of the file. There's a file upload as part of this insert and the name of the form input is not part of the var dump (obviously there would be no value recorded when the name is not present). However, I tested the delete part of the system I'm making and that didn't interact with the database either. In fact, I got the same thing. It runs all the code and redirects to the page it's supposed to, but the database interactions don't actually happen. I checked the way I'm connecting to the database and it seems correct. So, I don't know what's happening.
 

shopx102

New Member
Messages
7
Reaction score
0
Points
1
I found out something about this. The newer version of the MySQL statements (mysqli) don't make the interactions with the database. I changed my code to the old version (MySQL without the I) and the inserts are working now. But, I get an error message on the front end saying that the MySQL statements are deprecated and that I should change them.
 

caftpx10

Well-Known Member
Messages
1,534
Reaction score
114
Points
63
I have a feeling that the queries when it comes to MySQLi aren't being connected. What I would do is something like:
PHP:
$TheNameOfTheQuery = mysqli_query($ConnectionVarHere, "SELECT this,that,everything,want,all FROM my_table WHERE this='lemon' AND that='salt' AND want='true'");
if(!$TheNameOfTheQuery) echo mysqli_error($ConnectionVarHere);
Replace the variable names with their respective names and use your query instead of the one I've mocked.

If you really would prefer sticking with MySQL (not recommended) then you can hide the error using the following:
PHP:
error_reporting(E_ALL &~ E_DEPRECATED);
This would go on top of every file. Well, if you're including something like a connection file then you can just place it at the very top.
 
Last edited:

shopx102

New Member
Messages
7
Reaction score
0
Points
1
I understand that using MySQL is not ideal, but that's the version that's working for me right now. I'm going to keep working on this though. Thanks for your help. I couldn't have gotten this going without it.
 
Status
Not open for further replies.
Top