Guneshj / Project-prac

2 stars 1 forks source link

Home page #2

Open Guneshj opened 1 month ago

Guneshj commented 1 month ago

Check Home page code I have created code to Create new Event & also i have created a new table in DB named as 'event'. After Submitting we have to go on event page and see all details about event & created event shows in DB

please check this @OmkarS08

OmkarS08 commented 1 month ago

In the Backend Make these changes or copy the code as it is

app.post('/create', (req, res) => { //const sqll = "SELECT * FROM event WHEREEvent_name= ? ANDdetails` = ?";

const sql = "INSERT INTO event (`Event_name`, `details`) VALUES (?)";
const values =[
    req.body.event_name,
    req.body.details
]
console.log(values);
db.query(sql, [values], (err, data) => {
  //  if(err) return res.json("Error");
    return res.json(data);
})

})`

mistakes - typos in 'creat' and Event_name where in the frontend we have initialised as event_name

### In the Frontend

function handleSubmit(event) { event.preventDefault(); axios.post('http://localhost:8081/create', {event_name, details}) .then(res => { console.log(res)}) .catch(err => console.log(err))}

image

remove useNavigate() it should not navigate to the other home page

After Making the changes check the table if the values or inserted properly And also send images of event_table