last day (15 days later) » 

9:53 PM
1
A: Create a new table row/user on click php, ajax, mysql

Igor CarmagnaIf you managed to add new records in your mysql database, but the problem is that you want the field "text_edit_id" to increment automatically... then the solution is very simple: In phpmyadmin define the "text_edit_id" as described: type integer autoincrement (flag the checkbox - this option ...

 
Hello, thanks for responding. I have it set to both integer and a.i.. What I'm trying to wrap my head around is having it increment when I click the create button. From what I've seen online so far, I would need another ajax function like I do for saveEdits(); and I've created a create_new.php I'm just lost in the actual php code to add to the text_edit_id. @IgorCarmagna
 
Is the text_edit_field marked as the primary key of that table? You can check this clicking on the table name. See this image: i454.photobucket.com/albums/qq270/gagawagabaga/1.png
 
yes it's the primary
 
Ok.. I think I've found the problem... wait a few seconds
It's just the query that is wrong.. it UPDATES the row with id = 1 and changes the text_title and the text_text with the new values. Do you want to generate a NEW row (leaving the one already present in the table unchanged) or do you want to always keep 1 row in the table and just update its content?
 
Okay, so here is the link so you can see: trevormsmith.com/textedit/index.php, what you see is id = 1, and I want to keep that. It would be the testing page where anyone can change the content. In the upper right there will be a button to create your own where only they would be able to edit the content, so from there it would increment up. Let me know if that makes sense.
 
9:53 PM
"a button to create your own (what?? missing word) where only they would be (able??) to edit...". Honestly it is not very clear, but at least I get what your page does now
Will the new button create a new box where the users can change the content and save it? I mean a second box, and then a third box etc
 
A button to create their own page, the exact same setup as index.php, only it would be id = 2 and so on.
 
Great.. now I get it. So what you need to do is change the query from and UPDATE query to and INSERT query like shown in the post (look up.. I updated it). Each new page will have its own record in the table (that means each page = one row).
I wrote the new code in the answer. Try it. If it works mark the answer as the righ one
Of course you will create an UPDATE button (which fires an UPDATE query) and a ADD NEW button (which fires an INSERT query).
 
Okay, I'm just having a hard time wrapping my head around this. So I add that line into the functions.php? And that would still keep the first id = 1 editable? Or do i need another separate function which is triggered when clicked, and have the INSERT line in there? Could you expand a little more or could we possibly go into chat?
okay so when you click it creates another row: imgur.com/w2vaqHu, awesome, so now I would just need to add a redirect when clicked going to a new page, and if you make an edit it will edit that id's content and not revert back to id = 1?
 
Are you in chat?
Anyway, you guessed right. You need 2 separate php functions
One is like the function you posted in your question --> that will be the UPDATE function
The other php function is similar to the first one but you change 1 line with the line I posted in my answer. Clear until now?
Let's make a step forward
In your site each editable block will have an UPDATE button. After a user changes the content of that block he clicks the update button
 
hello
yes I've made the other functions, if i click and create a new row, then make an edit it reverts back to id = 1
 
10:00 PM
Of course if you use that code
Wait.. Im writing the explanation
 
sorry im a super noob with this stuff
 
Don't worry... I have still 5 min
 
github.com/trevasco/texteditv2.git theres a repo if you wanna see it full
 
Just two things
1- The ADD NEW button (and function) are simple... you already learned them
2 - So the only difficult thing here is the update function
When you retrieve and display the page from the database you need to echo inside the button the text_edit_id of each specific block
like this
<button data-attribute="3" ....etc>Edit</button>
The "3" si the id
or "text_edit_id" as you named it
Then in your javascript function you add another parameter to those you will pass with ajax
That new parameter is the id
So with ajax you pass 3 values: 1) id of the record you want to update 2)text_title 3) text_text
In the php function you will use a WHERE clause matching the id like this
$stmt = $connection->prepare("UPDATE data SET text_title = ?, text_text = ? WHERE text_edit_id = ?");
$stmt->bind_param('ss', $text_title, $text_text, id);
$stmt = $connection->prepare("UPDATE data SET text_title = ?, text_text = ? WHERE text_edit_id = ?");
$stmt->bind_param('ssi', $text_title, $text_text, $id);
Sorry the last one is the right one
You get the logic?
 
Yes for the most part, it may take a while of messing with it
 
10:14 PM
the only missing part is the javascript code that gets the value of data-attribute when you click on the button.
It's only 1 line of code... very simple... but I don't remember it right now...just google it
I need to go... good luck... you will definetly get it right. P.s. where did you get the template of your site?
 
thanks for the help I will try my best. template for trevormsmith.com or /texteditv2/ ?
 
For the text_edit page you linked before?
 
its all from scratch
a little help with the AJAX but thats it
 
Are you a graphic designer?
Or are studying to be one?
 
yea in school right now for web and interactive media. focuses are interaction design and ux/ui.
 
10:23 PM
I like what you're doing in your home page.. good job
Anyway... bye bye and good luck
 
oh thanks, that one is really buggy/old. this is my current in progress trevormsmith.com/tms
cheers
 

  last day (15 days later) »