Jump to content

MYSQLI code to retrieve info


rubyarat2010
Go to solution Solved by GetFreaky,

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
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. 

Edited by GetFreaky
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

  • Solution

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>";

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.