Cboyd13 Posted November 10, 2009 Share Posted November 10, 2009 <!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? Quote Link to comment https://forums.phpfreaks.com/topic/181020-_post-not-grabbing-from-text-box/ Share on other sites More sharing options...
KevinM1 Posted November 10, 2009 Share Posted November 10, 2009 Form processing should be done before you display the form itself. <?php if(isset($_POST['submt'])) { //process data } ?> <!-- show form --> Quote Link to comment https://forums.phpfreaks.com/topic/181020-_post-not-grabbing-from-text-box/#findComment-955070 Share on other sites More sharing options...
blakestock Posted November 10, 2009 Share Posted November 10, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/181020-_post-not-grabbing-from-text-box/#findComment-955071 Share on other sites More sharing options...
KevinM1 Posted November 10, 2009 Share Posted November 10, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/181020-_post-not-grabbing-from-text-box/#findComment-955078 Share on other sites More sharing options...
Cboyd13 Posted November 10, 2009 Author Share Posted November 10, 2009 I need to grab an SQL statement from a text box, im using the $_POST method to grab it from the box and plug it in. Quote Link to comment https://forums.phpfreaks.com/topic/181020-_post-not-grabbing-from-text-box/#findComment-955124 Share on other sites More sharing options...
KevinM1 Posted November 10, 2009 Share Posted November 10, 2009 I need to grab an SQL statement from a text box, im using the $_POST method to grab it from the box and plug it in. That's a really bad idea. Queries shouldn't be provided by the user. Quote Link to comment https://forums.phpfreaks.com/topic/181020-_post-not-grabbing-from-text-box/#findComment-955134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.