Jump to content

MYSQLI code to retrieve info


rubyarat2010

Recommended Posts

This code is meant to retrieve a row in a form but it returns nothing, I have tried it many different times even with HTML in it it returns nothing at all.

<?php
$conn = new mysqli("****", "***", "****");
$conn->select_db('mynotesdatabase');
$result = mysqli_query($conn, "SELECT * FROM" . $_GET['Folder'] . "WHERE Name='" . $_GET['Name'] . "'") or die(mysql_error());
	

while($row = mysqli_fetch_array($result) or die(mysql_error()))
  {
   echo "<br>";
  echo $row['Main'];
  echo "<br>";
  }
		
echo "<br/> <a href='javascript:history.back(-1);'>Back</a>";

?>

Link to comment
https://forums.phpfreaks.com/topic/285191-mysqli-code-to-retrieve-info/
Share on other sites

Some issues at first glance, there is no spaces here

FROM" . $_GET['Folder'] . "WHERE

try

<?php
$conn = new mysqli("****", "***", "****");
$conn->select_db('mynotesdatabase');
$result = $conn->("SELECT * FROM " . $_GET['Folder'] . " WHERE Name='" . $_GET['Name'] . "'") or die(mysql_error());
	

while($row = mysqli_fetch_array($result) or die(mysql_error()))
  {
   echo "<br>";
  echo $row['Main'];
  echo "<br>";
  }
		
echo "<br/> <a href='javascript:history.back(-1);'>Back</a>";

?>

Any reason why your table name is from a HTTP var?

 

Also your query is susceptible to unwanted injection. 

It is a little "program" I am making to help me with somthign else.  I know it is not that safe of a method but only I will be using it.  I tried what you put but it kind of gives me the same error you said

( ! ) Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '{' or '$' in C:\wamp\www\NotesWebsite\ViewNote.php on line 4

 

Thank you for the quick reply!

It is a little "program" I am making to help me with somthign else.  I know it is not that safe of a method but only I will be using it.  I tried what you put but it kind of gives me the same error you said

( ! ) Parse error: syntax error, unexpected '(', expecting T_STRING or T_VARIABLE or '{' or '$' in C:\wamp\www\NotesWebsite\ViewNote.php on line 4

 

Thank you for the quick reply!

 

sorry I forgot to add the $conn->query

 

try

<?php
$conn = new mysqli("****", "***", "****");
$conn->select_db('mynotesdatabase');
$result = $conn->query("SELECT * FROM " . $_GET['Folder'] . " WHERE Name='" . $_GET['Name'] . "'") or die(mysql_error());
    

while($row = mysqli_fetch_array($result) or die(mysql_error()))
{
echo "<br>";
echo $row['Main'];
echo "<br>";
}
        
echo "<br/> <a href='javascript:history.back(-1);'>Back</a>";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.