Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
if($sql){
echo "alert('New record successfully added!');";
echo "document.location='insert.php';";
}else{
echo "alert('Something Went Wrong!!!!');";
}

WHATS WRONG WITH THIS CODE PLEASE HELP ME .

IN MY LOCALHOST I INPUT DATA AND WHEN I CLICK SUBMIT IT SAYS "SOMETHING WENT WRONG " WHICH IS THE ELSE STATEMENT. i DONT KNOW ABOUT THIS .PLEASE HELP

What I have tried:

i TRIED EVERYTHING ,AND I FAILED ! i AM SEEKING HELP FROM SOMEONE WHO HAVE HIGHER KNOWLEDGE ABOUT MY PROBLEM.tHANK YOU FOR HELPING ME IN ADVANCE
Posted
Updated 25-Oct-21 9:31am
Comments
Richard Deeming 25-Oct-21 11:27am    
Start by fixing your CAPS LOCK key - PHP is at least partially case-sensitive, so trying to write PHP code with a keyboard which is obviously broken isn't going to work.

Unless your keyboard actually isn't broken, and you were just rudely yelling at us?
Working Student Ph 27-Oct-21 4:03am    
ohh caps Lock ,Sorry guise .

It means that ... something went wrong.

Most often, these kind of problems stem from bad SQL: bad syntax, bad table and / or column names, or using string concatenation to pass values instead of using parameterised queries.

So start with your code to generate the SQL command, and use the debugger (or inline logging / display statements) to examine exactly what it generates.
Once you have that, you can start lookinG for why it's failed - but until then you are just guessing - and so would we be!
 
Share this answer
 
The main problem is that your error message is worse than useless. Obviously if $sql is false then something went wrong, but what do you expect your users to do when they see that message? You need to analyse exactly what went wrong and post a message that contains some useful information. As a first step add some log messages to your application so you can see what is happening.
 
Share this answer
 
Comments
Working Student Ph 27-Oct-21 4:09am    
Thank you everyone for giving me suggestion. This will help me improve on the future.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900