How to get useful error messages in mysql query in php? The Next CEO of Stack OverflowI cant understand why none of the data is getting inserted into the databasePHP / MySQL: Cannot retrieve any data from databasePHP does not insert data into a tableHow can I prevent SQL injection in PHP?How to get useful error messages in PHP?How do I get PHP errors to display?How do I get a YouTube video thumbnail from the YouTube API?How to get the client IP address in PHPHow Do You Parse and Process HTML/XML in PHP?Get the full URL in PHPHow to fix “Headers already sent” error in PHPHow does PHP 'foreach' actually work?Reference - What does this error mean in PHP?

How do I fit a non linear curve?

how one can write a nice vector parser, something that does pgfvecparseA=B-C; D=E x F;

Man transported from Alternate World into ours by a Neutrino Detector

Why do we say 'Un seul M' and not 'Une seule M' even though M is a "consonne"

Is it professional to write unrelated content in an almost-empty email?

The Ultimate Number Sequence Puzzle

How to use ReplaceAll on an expression that contains a rule

Is it convenient to ask the journal's editor for two additional days to complete a review?

TikZ: How to fill area with a special pattern?

Reshaping json / reparing json inside shell script (remove trailing comma)

Towers in the ocean; How deep can they be built?

What is the process for purifying your home if you believe it may have been previously used for pagan worship?

Where do students learn to solve polynomial equations these days?

From jafe to El-Guest

Can this note be analyzed as a non-chord tone?

Ising model simulation

How do you define an element with an ID attribute using LWC?

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Does the Idaho Potato Commission associate potato skins with healthy eating?

What difference does it make using sed with/without whitespaces?

Aggressive Under-Indexing and no data for missing index

Can you teleport closer to a creature you are Frightened of?

Do scriptures give a method to recognize a truly self-realized person/jivanmukta?

Could a dragon use its wings to swim?



How to get useful error messages in mysql query in php?



The Next CEO of Stack OverflowI cant understand why none of the data is getting inserted into the databasePHP / MySQL: Cannot retrieve any data from databasePHP does not insert data into a tableHow can I prevent SQL injection in PHP?How to get useful error messages in PHP?How do I get PHP errors to display?How do I get a YouTube video thumbnail from the YouTube API?How to get the client IP address in PHPHow Do You Parse and Process HTML/XML in PHP?Get the full URL in PHPHow to fix “Headers already sent” error in PHPHow does PHP 'foreach' actually work?Reference - What does this error mean in PHP?










0















HTML code



<form class="col s6 " method="post" enctype="multipart/form-data">
<div class="input-field col s12">
<input id="last_name" type="text" name="name" class="validate">
<label for="last_name">Certificate Name</label>
</div>
<button type="submit" id="btnSubmit" name="btnSubmit" class="btn btn-default" style="margin-top:20px;">ADD</button>
</form>


PHP code



<?php
include('footer.php');

include('conn.php');
if(isset($_POST['btnSubmit']))

$name = mysqli_real_escape_string($conn,$_POST["name"]);

$sql = "INSERT INTO `isodetail`(`title`) VALUES ('$name')";

$run = mysqli_query($conn, $sql);

if($run)

echo "<script>alert('Certi Added Successfully')</script>";
echo "<script>window.open('isocerti.php','_self')</script>";

else

echo "<script>alert('Something Error!..please try Again..')</script>";



?>


This shows an alert message saying Something Error!..please try Again..
so is it mysqli_query that has a mistake?










share|improve this question
























  • Use the mysqli_error function: php.net/manual/en/mysqli.error.php Example: echo mysqli_error($conn);

    – Steven
    Jan 16 '18 at 6:36












  • it doesnt show any errors

    – Archi Patel
    Jan 16 '18 at 6:50











  • @Sandra read about variable parsing in strings. That code is correct as it is now.

    – axiac
    Jan 16 '18 at 7:05
















0















HTML code



<form class="col s6 " method="post" enctype="multipart/form-data">
<div class="input-field col s12">
<input id="last_name" type="text" name="name" class="validate">
<label for="last_name">Certificate Name</label>
</div>
<button type="submit" id="btnSubmit" name="btnSubmit" class="btn btn-default" style="margin-top:20px;">ADD</button>
</form>


PHP code



<?php
include('footer.php');

include('conn.php');
if(isset($_POST['btnSubmit']))

$name = mysqli_real_escape_string($conn,$_POST["name"]);

$sql = "INSERT INTO `isodetail`(`title`) VALUES ('$name')";

$run = mysqli_query($conn, $sql);

if($run)

echo "<script>alert('Certi Added Successfully')</script>";
echo "<script>window.open('isocerti.php','_self')</script>";

else

echo "<script>alert('Something Error!..please try Again..')</script>";



?>


This shows an alert message saying Something Error!..please try Again..
so is it mysqli_query that has a mistake?










share|improve this question
























  • Use the mysqli_error function: php.net/manual/en/mysqli.error.php Example: echo mysqli_error($conn);

    – Steven
    Jan 16 '18 at 6:36












  • it doesnt show any errors

    – Archi Patel
    Jan 16 '18 at 6:50











  • @Sandra read about variable parsing in strings. That code is correct as it is now.

    – axiac
    Jan 16 '18 at 7:05














0












0








0


0






HTML code



<form class="col s6 " method="post" enctype="multipart/form-data">
<div class="input-field col s12">
<input id="last_name" type="text" name="name" class="validate">
<label for="last_name">Certificate Name</label>
</div>
<button type="submit" id="btnSubmit" name="btnSubmit" class="btn btn-default" style="margin-top:20px;">ADD</button>
</form>


PHP code



<?php
include('footer.php');

include('conn.php');
if(isset($_POST['btnSubmit']))

$name = mysqli_real_escape_string($conn,$_POST["name"]);

$sql = "INSERT INTO `isodetail`(`title`) VALUES ('$name')";

$run = mysqli_query($conn, $sql);

if($run)

echo "<script>alert('Certi Added Successfully')</script>";
echo "<script>window.open('isocerti.php','_self')</script>";

else

echo "<script>alert('Something Error!..please try Again..')</script>";



?>


This shows an alert message saying Something Error!..please try Again..
so is it mysqli_query that has a mistake?










share|improve this question
















HTML code



<form class="col s6 " method="post" enctype="multipart/form-data">
<div class="input-field col s12">
<input id="last_name" type="text" name="name" class="validate">
<label for="last_name">Certificate Name</label>
</div>
<button type="submit" id="btnSubmit" name="btnSubmit" class="btn btn-default" style="margin-top:20px;">ADD</button>
</form>


PHP code



<?php
include('footer.php');

include('conn.php');
if(isset($_POST['btnSubmit']))

$name = mysqli_real_escape_string($conn,$_POST["name"]);

$sql = "INSERT INTO `isodetail`(`title`) VALUES ('$name')";

$run = mysqli_query($conn, $sql);

if($run)

echo "<script>alert('Certi Added Successfully')</script>";
echo "<script>window.open('isocerti.php','_self')</script>";

else

echo "<script>alert('Something Error!..please try Again..')</script>";



?>


This shows an alert message saying Something Error!..please try Again..
so is it mysqli_query that has a mistake?







php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 16 '18 at 6:54









Jeff

9,68952450




9,68952450










asked Jan 16 '18 at 6:25









Archi PatelArchi Patel

4111




4111












  • Use the mysqli_error function: php.net/manual/en/mysqli.error.php Example: echo mysqli_error($conn);

    – Steven
    Jan 16 '18 at 6:36












  • it doesnt show any errors

    – Archi Patel
    Jan 16 '18 at 6:50











  • @Sandra read about variable parsing in strings. That code is correct as it is now.

    – axiac
    Jan 16 '18 at 7:05


















  • Use the mysqli_error function: php.net/manual/en/mysqli.error.php Example: echo mysqli_error($conn);

    – Steven
    Jan 16 '18 at 6:36












  • it doesnt show any errors

    – Archi Patel
    Jan 16 '18 at 6:50











  • @Sandra read about variable parsing in strings. That code is correct as it is now.

    – axiac
    Jan 16 '18 at 7:05

















Use the mysqli_error function: php.net/manual/en/mysqli.error.php Example: echo mysqli_error($conn);

– Steven
Jan 16 '18 at 6:36






Use the mysqli_error function: php.net/manual/en/mysqli.error.php Example: echo mysqli_error($conn);

– Steven
Jan 16 '18 at 6:36














it doesnt show any errors

– Archi Patel
Jan 16 '18 at 6:50





it doesnt show any errors

– Archi Patel
Jan 16 '18 at 6:50













@Sandra read about variable parsing in strings. That code is correct as it is now.

– axiac
Jan 16 '18 at 7:05






@Sandra read about variable parsing in strings. That code is correct as it is now.

– axiac
Jan 16 '18 at 7:05













1 Answer
1






active

oldest

votes


















1














In the else-block you can see, how you can catch up MySQL-errors and display them in an alert.



if(isset($_POST['btnSubmit'])) 
$name = mysqli_real_escape_string($conn,$_POST["name"]);
$sql = "INSERT INTO isodetail(title) VALUES ('$name')";
$run = mysqli_query($conn, $sql);

if($run)
echo "<script>alert('Certi Added Successfully');window.open('isocerti.php','_self');</script>";
else
$error = addslashes(mysqli_error($conn));
echo "<script>alert('An Error occur: $error');</script>";




References:
MySQLi-Error: http://php.net/manual/en/mysqli.error.php

Escape special characters: http://php.net/manual/en/function.addslashes.php (it does the job for this example)






share|improve this answer























  • @ArchiPatel So you have your correct error, now you can start debug it. My first idea will be: INSERT isodetail(title, name) VALUES ('$name', '') but that's just a guess without knowledge about your database structure.

    – Steven
    Jan 16 '18 at 7:29












  • yes i got this ...Thank you so much.

    – Archi Patel
    Jan 16 '18 at 7:36











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48275205%2fhow-to-get-useful-error-messages-in-mysql-query-in-php%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In the else-block you can see, how you can catch up MySQL-errors and display them in an alert.



if(isset($_POST['btnSubmit'])) 
$name = mysqli_real_escape_string($conn,$_POST["name"]);
$sql = "INSERT INTO isodetail(title) VALUES ('$name')";
$run = mysqli_query($conn, $sql);

if($run)
echo "<script>alert('Certi Added Successfully');window.open('isocerti.php','_self');</script>";
else
$error = addslashes(mysqli_error($conn));
echo "<script>alert('An Error occur: $error');</script>";




References:
MySQLi-Error: http://php.net/manual/en/mysqli.error.php

Escape special characters: http://php.net/manual/en/function.addslashes.php (it does the job for this example)






share|improve this answer























  • @ArchiPatel So you have your correct error, now you can start debug it. My first idea will be: INSERT isodetail(title, name) VALUES ('$name', '') but that's just a guess without knowledge about your database structure.

    – Steven
    Jan 16 '18 at 7:29












  • yes i got this ...Thank you so much.

    – Archi Patel
    Jan 16 '18 at 7:36















1














In the else-block you can see, how you can catch up MySQL-errors and display them in an alert.



if(isset($_POST['btnSubmit'])) 
$name = mysqli_real_escape_string($conn,$_POST["name"]);
$sql = "INSERT INTO isodetail(title) VALUES ('$name')";
$run = mysqli_query($conn, $sql);

if($run)
echo "<script>alert('Certi Added Successfully');window.open('isocerti.php','_self');</script>";
else
$error = addslashes(mysqli_error($conn));
echo "<script>alert('An Error occur: $error');</script>";




References:
MySQLi-Error: http://php.net/manual/en/mysqli.error.php

Escape special characters: http://php.net/manual/en/function.addslashes.php (it does the job for this example)






share|improve this answer























  • @ArchiPatel So you have your correct error, now you can start debug it. My first idea will be: INSERT isodetail(title, name) VALUES ('$name', '') but that's just a guess without knowledge about your database structure.

    – Steven
    Jan 16 '18 at 7:29












  • yes i got this ...Thank you so much.

    – Archi Patel
    Jan 16 '18 at 7:36













1












1








1







In the else-block you can see, how you can catch up MySQL-errors and display them in an alert.



if(isset($_POST['btnSubmit'])) 
$name = mysqli_real_escape_string($conn,$_POST["name"]);
$sql = "INSERT INTO isodetail(title) VALUES ('$name')";
$run = mysqli_query($conn, $sql);

if($run)
echo "<script>alert('Certi Added Successfully');window.open('isocerti.php','_self');</script>";
else
$error = addslashes(mysqli_error($conn));
echo "<script>alert('An Error occur: $error');</script>";




References:
MySQLi-Error: http://php.net/manual/en/mysqli.error.php

Escape special characters: http://php.net/manual/en/function.addslashes.php (it does the job for this example)






share|improve this answer













In the else-block you can see, how you can catch up MySQL-errors and display them in an alert.



if(isset($_POST['btnSubmit'])) 
$name = mysqli_real_escape_string($conn,$_POST["name"]);
$sql = "INSERT INTO isodetail(title) VALUES ('$name')";
$run = mysqli_query($conn, $sql);

if($run)
echo "<script>alert('Certi Added Successfully');window.open('isocerti.php','_self');</script>";
else
$error = addslashes(mysqli_error($conn));
echo "<script>alert('An Error occur: $error');</script>";




References:
MySQLi-Error: http://php.net/manual/en/mysqli.error.php

Escape special characters: http://php.net/manual/en/function.addslashes.php (it does the job for this example)







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 16 '18 at 7:01









StevenSteven

383210




383210












  • @ArchiPatel So you have your correct error, now you can start debug it. My first idea will be: INSERT isodetail(title, name) VALUES ('$name', '') but that's just a guess without knowledge about your database structure.

    – Steven
    Jan 16 '18 at 7:29












  • yes i got this ...Thank you so much.

    – Archi Patel
    Jan 16 '18 at 7:36

















  • @ArchiPatel So you have your correct error, now you can start debug it. My first idea will be: INSERT isodetail(title, name) VALUES ('$name', '') but that's just a guess without knowledge about your database structure.

    – Steven
    Jan 16 '18 at 7:29












  • yes i got this ...Thank you so much.

    – Archi Patel
    Jan 16 '18 at 7:36
















@ArchiPatel So you have your correct error, now you can start debug it. My first idea will be: INSERT isodetail(title, name) VALUES ('$name', '') but that's just a guess without knowledge about your database structure.

– Steven
Jan 16 '18 at 7:29






@ArchiPatel So you have your correct error, now you can start debug it. My first idea will be: INSERT isodetail(title, name) VALUES ('$name', '') but that's just a guess without knowledge about your database structure.

– Steven
Jan 16 '18 at 7:29














yes i got this ...Thank you so much.

– Archi Patel
Jan 16 '18 at 7:36





yes i got this ...Thank you so much.

– Archi Patel
Jan 16 '18 at 7:36



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48275205%2fhow-to-get-useful-error-messages-in-mysql-query-in-php%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현