N
Neon2y ago
plain-purple

not able to fetch and mutate the data

Hi all, I am trying to use this code
export default async function Page(formData: FormData) {
try {
const sql = postgres(process.env.DATABASE_URL ?? "", { ssl: 'require' });
await sql`CREATE TABLE IF NOT EXISTS comments (comment TEXT)`;
const comment = String(formData.get("data")); // Convert comment to a string
await sql`INSERT INTO comments (comment) VALUES (${comment})`;
console.log("Comment added")}
catch (error) {
console.log(error)}}
export default async function Page(formData: FormData) {
try {
const sql = postgres(process.env.DATABASE_URL ?? "", { ssl: 'require' });
await sql`CREATE TABLE IF NOT EXISTS comments (comment TEXT)`;
const comment = String(formData.get("data")); // Convert comment to a string
await sql`INSERT INTO comments (comment) VALUES (${comment})`;
console.log("Comment added")}
catch (error) {
console.log(error)}}
which is given in the official docs but I can't see any entry or any console-logged data in my terminal. https://github.com/Boby900/yogurt any help would be highly appreciated
GitHub
GitHub - Boby900/yogurt
Contribute to Boby900/yogurt development by creating an account on GitHub.
No description
No description
6 Replies
equal-jade
equal-jade2y ago
Hmm, then tis means that your server action isn't being called. What does your <Submit/> component look like? oh wait what happens when the <Submit/> component is defined outside of the <ProfileForm/> component
rival-black
rival-black2y ago
Hey @Boby, I'd recommend going through https://neon.tech/guides/next-server-actions on how to use Neon with Next.js server actions.
plain-purple
plain-purpleOP2y ago
<Submit /> button is working fine, I guess, I was able to submit the form using this component. I have found this below code and I am able to post the data, and form is working fine.
plain-purple
plain-purpleOP2y ago
No description
No description
plain-purple
plain-purpleOP2y ago
thanks for helping me @Mahmoud @Rishi Raj Jain
rival-black
rival-black2y ago
Glad it's working!

Did you find this page helpful?