Jump to content

Recommended Posts

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name='Query' action="Project4.php" method="post">
<center>Query Statement<input name='entry'>
<br>
<br>
<input type='submit' value='Submit' >
</form>
</body>
</html>
<?php
$mysqli=mysqli_connect('localhost','root','','Project4');
//Create databases
/*if (mysql_query("CREATE DATABASE Project4",$mysqli))
  {
  echo "Database created";
  }
else
  {
  echo "Error creating database: " . mysql_error();
  };
  //shows an error if PHP could not connect to the database
  if (!$mysqli)
  {
  die('Could not connect: ' . mysql_error());
  };*/
  //Grabs the SQL statement from text box named 'statement'
$sqli = $_POST['entry'];
$recordset=mysqli_Query($sqli,$mysqli);
//Handles query with many records, This part may have something wrong with it
while ($delements=mysqli_fetch_array($mysqli,MYSQLI_ASSOC)){
$slot= $recordset;
};
echo $sqli; //This echoes $sql, we just need to echo back the SQL statement that he puts in, wont be hard to fix
mysqli_query($mysqli,$sqli) or die(mysql_error());
mysqli_free_result($recordset);
  mysqli_close($mysqli);
  ?>

 

From looking at the errors it seems to all correlate from the $_POST not grabbing an SQL statement from a text box and puting it into a variable ($sqli)

 

Thoughts?

Link to comment
https://forums.phpfreaks.com/topic/181020-_post-not-grabbing-from-text-box/
Share on other sites

the data from the form is going to pass to the php script as $_POST['Query'] and not 'entry' since you've named your form "Query".  That gets sent as an array if you have multiple items in that form.

 

If you and it will pass data across as

 

Array

(

    [entry] => whatever entered in form

)

 

some debugging you can add to your php script to see what one page passes to the next through the POST method is: 

 

<pre><?php
     print_r($_POST);
?>  </pre>

 

 

I'm kinda new to php and web dev. but hope this helps  8)

Upon closer inspection, where is your query?

 

Properly formed database queries look like:

 

$dbc = mysqli_connect('localhost','root','','Project4');

$data = $_POST['entry'];

$result = mysqli_query("SELECT * FROM tablename WHERE data = $data", $dbc);

while($row = mysqli_fetch_assoc($result))
{
  //do something with the fetched db row
}

 

You should brush up on your basic db interaction code, because most of what you have right now is gibberish.

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.