Unable to produce SQL query in PHP/HTML












0















I'm having some trouble generating output from an sql query via php. When I execute the query "SELECT * from projectdb WHERE name = 'Crys' or ID = 14142" on phpmyadmin it returns valid results, but attempting to do so by passing a post value yields an empty table. See code below:






<html>
<title>Search result</title>

<body>
<table border="1px">
<tr>
<td>name</td>
<td>ID</td>
<td>position</td>
<td>job scope</td>
<td>contact_no</td>
<td>days_off</td>
<td>wages</td>
</tr>


<?php
if (isset($_POST['value']))
{
$ID=$_POST['staff ID'];
$name=$_POST['staff name'];


$admincon =mysqli_connect("localhost","root","","projectdb");
/* Query I need to execute and print in table*/
$sqlsrch2 =mysqli_query($admincon, "select * from staff where name='".$name."' or ID='".$ID."'");
while($result=mysqli_fetch_assoc($sqlsrch2)){

?>
/* table where results needs to be printed */
<tr>
<td><?php echo $result['name'];?></td>
<td><?php echo $result['ID'];?></td>
<td><?php echo $result['position'];?></td>
<td><?php echo $result['job_scope'];?></td>
<td><?php echo $result['contact_no'];?></td>
<td><?php echo $result['days_off'];?></td>
<td><?php echo $result['wages'];?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>





A few points to note:




  1. I'm just a beginner in PHP and SQL; I'm just looking for a simple answer.

  2. Security is not at all a concern here; this is just a rough demo.
    If this is marked as duplicate, do help redirect me to a link where I can get the solution. Thanks!










share|improve this question

























  • If you ever have problems like this, try and display the SQL query that it's actually using in your PHP code. This shows the variables that are being used and their values.

    – Nigel Ren
    Nov 25 '18 at 8:01











  • Thanks for that Nigel. The SQL query I'm trying to display is something like this for example: SELECT * FROM staff WHERE name = "Crys" or ID =14142 "Crys" is a valid entry in the staff table of my database as is ID number 14142 that's how I know there's something I'm not doing right in my code, The name of the database is projectdb by the way.

    – Ada Ozy
    Nov 25 '18 at 8:31













  • About your notes: Security is ALWAYS an issue... as an beginner you have the great chance to learn it the right way - please do it!

    – Lars Stegelitz
    Nov 25 '18 at 9:05











  • I would try something like this, echo sqlsrch2; write this statment after the $sqlsrch2 =mysqli_query(... );statement. then see the output if that query has the post variable value. this is for testing whether your query has the intented values you pass as parameters.

    – Nadee
    Nov 25 '18 at 9:41













  • Thanks Nadee. I just did that and it seems that there is no value being passed to the query as parameters. What can I do to remedy this?

    – Ada Ozy
    Nov 25 '18 at 14:33
















0















I'm having some trouble generating output from an sql query via php. When I execute the query "SELECT * from projectdb WHERE name = 'Crys' or ID = 14142" on phpmyadmin it returns valid results, but attempting to do so by passing a post value yields an empty table. See code below:






<html>
<title>Search result</title>

<body>
<table border="1px">
<tr>
<td>name</td>
<td>ID</td>
<td>position</td>
<td>job scope</td>
<td>contact_no</td>
<td>days_off</td>
<td>wages</td>
</tr>


<?php
if (isset($_POST['value']))
{
$ID=$_POST['staff ID'];
$name=$_POST['staff name'];


$admincon =mysqli_connect("localhost","root","","projectdb");
/* Query I need to execute and print in table*/
$sqlsrch2 =mysqli_query($admincon, "select * from staff where name='".$name."' or ID='".$ID."'");
while($result=mysqli_fetch_assoc($sqlsrch2)){

?>
/* table where results needs to be printed */
<tr>
<td><?php echo $result['name'];?></td>
<td><?php echo $result['ID'];?></td>
<td><?php echo $result['position'];?></td>
<td><?php echo $result['job_scope'];?></td>
<td><?php echo $result['contact_no'];?></td>
<td><?php echo $result['days_off'];?></td>
<td><?php echo $result['wages'];?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>





A few points to note:




  1. I'm just a beginner in PHP and SQL; I'm just looking for a simple answer.

  2. Security is not at all a concern here; this is just a rough demo.
    If this is marked as duplicate, do help redirect me to a link where I can get the solution. Thanks!










share|improve this question

























  • If you ever have problems like this, try and display the SQL query that it's actually using in your PHP code. This shows the variables that are being used and their values.

    – Nigel Ren
    Nov 25 '18 at 8:01











  • Thanks for that Nigel. The SQL query I'm trying to display is something like this for example: SELECT * FROM staff WHERE name = "Crys" or ID =14142 "Crys" is a valid entry in the staff table of my database as is ID number 14142 that's how I know there's something I'm not doing right in my code, The name of the database is projectdb by the way.

    – Ada Ozy
    Nov 25 '18 at 8:31













  • About your notes: Security is ALWAYS an issue... as an beginner you have the great chance to learn it the right way - please do it!

    – Lars Stegelitz
    Nov 25 '18 at 9:05











  • I would try something like this, echo sqlsrch2; write this statment after the $sqlsrch2 =mysqli_query(... );statement. then see the output if that query has the post variable value. this is for testing whether your query has the intented values you pass as parameters.

    – Nadee
    Nov 25 '18 at 9:41













  • Thanks Nadee. I just did that and it seems that there is no value being passed to the query as parameters. What can I do to remedy this?

    – Ada Ozy
    Nov 25 '18 at 14:33














0












0








0








I'm having some trouble generating output from an sql query via php. When I execute the query "SELECT * from projectdb WHERE name = 'Crys' or ID = 14142" on phpmyadmin it returns valid results, but attempting to do so by passing a post value yields an empty table. See code below:






<html>
<title>Search result</title>

<body>
<table border="1px">
<tr>
<td>name</td>
<td>ID</td>
<td>position</td>
<td>job scope</td>
<td>contact_no</td>
<td>days_off</td>
<td>wages</td>
</tr>


<?php
if (isset($_POST['value']))
{
$ID=$_POST['staff ID'];
$name=$_POST['staff name'];


$admincon =mysqli_connect("localhost","root","","projectdb");
/* Query I need to execute and print in table*/
$sqlsrch2 =mysqli_query($admincon, "select * from staff where name='".$name."' or ID='".$ID."'");
while($result=mysqli_fetch_assoc($sqlsrch2)){

?>
/* table where results needs to be printed */
<tr>
<td><?php echo $result['name'];?></td>
<td><?php echo $result['ID'];?></td>
<td><?php echo $result['position'];?></td>
<td><?php echo $result['job_scope'];?></td>
<td><?php echo $result['contact_no'];?></td>
<td><?php echo $result['days_off'];?></td>
<td><?php echo $result['wages'];?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>





A few points to note:




  1. I'm just a beginner in PHP and SQL; I'm just looking for a simple answer.

  2. Security is not at all a concern here; this is just a rough demo.
    If this is marked as duplicate, do help redirect me to a link where I can get the solution. Thanks!










share|improve this question
















I'm having some trouble generating output from an sql query via php. When I execute the query "SELECT * from projectdb WHERE name = 'Crys' or ID = 14142" on phpmyadmin it returns valid results, but attempting to do so by passing a post value yields an empty table. See code below:






<html>
<title>Search result</title>

<body>
<table border="1px">
<tr>
<td>name</td>
<td>ID</td>
<td>position</td>
<td>job scope</td>
<td>contact_no</td>
<td>days_off</td>
<td>wages</td>
</tr>


<?php
if (isset($_POST['value']))
{
$ID=$_POST['staff ID'];
$name=$_POST['staff name'];


$admincon =mysqli_connect("localhost","root","","projectdb");
/* Query I need to execute and print in table*/
$sqlsrch2 =mysqli_query($admincon, "select * from staff where name='".$name."' or ID='".$ID."'");
while($result=mysqli_fetch_assoc($sqlsrch2)){

?>
/* table where results needs to be printed */
<tr>
<td><?php echo $result['name'];?></td>
<td><?php echo $result['ID'];?></td>
<td><?php echo $result['position'];?></td>
<td><?php echo $result['job_scope'];?></td>
<td><?php echo $result['contact_no'];?></td>
<td><?php echo $result['days_off'];?></td>
<td><?php echo $result['wages'];?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>





A few points to note:




  1. I'm just a beginner in PHP and SQL; I'm just looking for a simple answer.

  2. Security is not at all a concern here; this is just a rough demo.
    If this is marked as duplicate, do help redirect me to a link where I can get the solution. Thanks!






<html>
<title>Search result</title>

<body>
<table border="1px">
<tr>
<td>name</td>
<td>ID</td>
<td>position</td>
<td>job scope</td>
<td>contact_no</td>
<td>days_off</td>
<td>wages</td>
</tr>


<?php
if (isset($_POST['value']))
{
$ID=$_POST['staff ID'];
$name=$_POST['staff name'];


$admincon =mysqli_connect("localhost","root","","projectdb");
/* Query I need to execute and print in table*/
$sqlsrch2 =mysqli_query($admincon, "select * from staff where name='".$name."' or ID='".$ID."'");
while($result=mysqli_fetch_assoc($sqlsrch2)){

?>
/* table where results needs to be printed */
<tr>
<td><?php echo $result['name'];?></td>
<td><?php echo $result['ID'];?></td>
<td><?php echo $result['position'];?></td>
<td><?php echo $result['job_scope'];?></td>
<td><?php echo $result['contact_no'];?></td>
<td><?php echo $result['days_off'];?></td>
<td><?php echo $result['wages'];?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>





<html>
<title>Search result</title>

<body>
<table border="1px">
<tr>
<td>name</td>
<td>ID</td>
<td>position</td>
<td>job scope</td>
<td>contact_no</td>
<td>days_off</td>
<td>wages</td>
</tr>


<?php
if (isset($_POST['value']))
{
$ID=$_POST['staff ID'];
$name=$_POST['staff name'];


$admincon =mysqli_connect("localhost","root","","projectdb");
/* Query I need to execute and print in table*/
$sqlsrch2 =mysqli_query($admincon, "select * from staff where name='".$name."' or ID='".$ID."'");
while($result=mysqli_fetch_assoc($sqlsrch2)){

?>
/* table where results needs to be printed */
<tr>
<td><?php echo $result['name'];?></td>
<td><?php echo $result['ID'];?></td>
<td><?php echo $result['position'];?></td>
<td><?php echo $result['job_scope'];?></td>
<td><?php echo $result['contact_no'];?></td>
<td><?php echo $result['days_off'];?></td>
<td><?php echo $result['wages'];?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>






php html mysql forms http-post






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 15:00









Funk Forty Niner

1




1










asked Nov 25 '18 at 7:56









Ada OzyAda Ozy

1




1













  • If you ever have problems like this, try and display the SQL query that it's actually using in your PHP code. This shows the variables that are being used and their values.

    – Nigel Ren
    Nov 25 '18 at 8:01











  • Thanks for that Nigel. The SQL query I'm trying to display is something like this for example: SELECT * FROM staff WHERE name = "Crys" or ID =14142 "Crys" is a valid entry in the staff table of my database as is ID number 14142 that's how I know there's something I'm not doing right in my code, The name of the database is projectdb by the way.

    – Ada Ozy
    Nov 25 '18 at 8:31













  • About your notes: Security is ALWAYS an issue... as an beginner you have the great chance to learn it the right way - please do it!

    – Lars Stegelitz
    Nov 25 '18 at 9:05











  • I would try something like this, echo sqlsrch2; write this statment after the $sqlsrch2 =mysqli_query(... );statement. then see the output if that query has the post variable value. this is for testing whether your query has the intented values you pass as parameters.

    – Nadee
    Nov 25 '18 at 9:41













  • Thanks Nadee. I just did that and it seems that there is no value being passed to the query as parameters. What can I do to remedy this?

    – Ada Ozy
    Nov 25 '18 at 14:33



















  • If you ever have problems like this, try and display the SQL query that it's actually using in your PHP code. This shows the variables that are being used and their values.

    – Nigel Ren
    Nov 25 '18 at 8:01











  • Thanks for that Nigel. The SQL query I'm trying to display is something like this for example: SELECT * FROM staff WHERE name = "Crys" or ID =14142 "Crys" is a valid entry in the staff table of my database as is ID number 14142 that's how I know there's something I'm not doing right in my code, The name of the database is projectdb by the way.

    – Ada Ozy
    Nov 25 '18 at 8:31













  • About your notes: Security is ALWAYS an issue... as an beginner you have the great chance to learn it the right way - please do it!

    – Lars Stegelitz
    Nov 25 '18 at 9:05











  • I would try something like this, echo sqlsrch2; write this statment after the $sqlsrch2 =mysqli_query(... );statement. then see the output if that query has the post variable value. this is for testing whether your query has the intented values you pass as parameters.

    – Nadee
    Nov 25 '18 at 9:41













  • Thanks Nadee. I just did that and it seems that there is no value being passed to the query as parameters. What can I do to remedy this?

    – Ada Ozy
    Nov 25 '18 at 14:33

















If you ever have problems like this, try and display the SQL query that it's actually using in your PHP code. This shows the variables that are being used and their values.

– Nigel Ren
Nov 25 '18 at 8:01





If you ever have problems like this, try and display the SQL query that it's actually using in your PHP code. This shows the variables that are being used and their values.

– Nigel Ren
Nov 25 '18 at 8:01













Thanks for that Nigel. The SQL query I'm trying to display is something like this for example: SELECT * FROM staff WHERE name = "Crys" or ID =14142 "Crys" is a valid entry in the staff table of my database as is ID number 14142 that's how I know there's something I'm not doing right in my code, The name of the database is projectdb by the way.

– Ada Ozy
Nov 25 '18 at 8:31







Thanks for that Nigel. The SQL query I'm trying to display is something like this for example: SELECT * FROM staff WHERE name = "Crys" or ID =14142 "Crys" is a valid entry in the staff table of my database as is ID number 14142 that's how I know there's something I'm not doing right in my code, The name of the database is projectdb by the way.

– Ada Ozy
Nov 25 '18 at 8:31















About your notes: Security is ALWAYS an issue... as an beginner you have the great chance to learn it the right way - please do it!

– Lars Stegelitz
Nov 25 '18 at 9:05





About your notes: Security is ALWAYS an issue... as an beginner you have the great chance to learn it the right way - please do it!

– Lars Stegelitz
Nov 25 '18 at 9:05













I would try something like this, echo sqlsrch2; write this statment after the $sqlsrch2 =mysqli_query(... );statement. then see the output if that query has the post variable value. this is for testing whether your query has the intented values you pass as parameters.

– Nadee
Nov 25 '18 at 9:41







I would try something like this, echo sqlsrch2; write this statment after the $sqlsrch2 =mysqli_query(... );statement. then see the output if that query has the post variable value. this is for testing whether your query has the intented values you pass as parameters.

– Nadee
Nov 25 '18 at 9:41















Thanks Nadee. I just did that and it seems that there is no value being passed to the query as parameters. What can I do to remedy this?

– Ada Ozy
Nov 25 '18 at 14:33





Thanks Nadee. I just did that and it seems that there is no value being passed to the query as parameters. What can I do to remedy this?

– Ada Ozy
Nov 25 '18 at 14:33












0






active

oldest

votes











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%2f53465655%2funable-to-produce-sql-query-in-php-html%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f53465655%2funable-to-produce-sql-query-in-php-html%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

Wiesbaden

Marschland

Dieringhausen