Matthew Rotherham Posted April 23, 2006 Share Posted April 23, 2006 When I submit the form, I get... Array(['query']) has been recorded!When I check the database, nothing has been recorded.The code is...<form method="POST" action="index.php"><input type="text name="query"><input type="submit" value="Submit" name="submit"></form><?$query = "$_POST(['query'])";include("connect.php");$sql = "INSERT INTO `User` (`name`) VALUES ('$query')";mysql_query($sql);mysql_close();echo "$query has been recorded!";?>What is the problem, please? Link to comment https://forums.phpfreaks.com/topic/8192-arrayquery/ Share on other sites More sharing options...
Yesideez Posted April 23, 2006 Share Posted April 23, 2006 Try this...[code]<?if ($_POST['submit']) { $query = $_POST(['query']); include("connect.php"); $sql = "INSERT INTO `User` (`name`) VALUES ('$query')"; mysql_query($sql); mysql_close(); echo "$query has been recorded!";}?><form method="POST" action="index.php"><input type="text" name="query"><input type="submit" value="Submit" name="submit"></form>[/code]AllI did was move the PHP to the start of the file, add a quote into your HTML section and remove the quotes around the $_POST bit. Then I surrounded the lot with an if() statement to only run the code if the submit button was pressed. Link to comment https://forums.phpfreaks.com/topic/8192-arrayquery/#findComment-29890 Share on other sites More sharing options...
Matthew Rotherham Posted April 23, 2006 Author Share Posted April 23, 2006 [!--quoteo(post=367763:date=Apr 23 2006, 02:56 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 23 2006, 02:56 PM) [snapback]367763[/snapback][/div][div class=\'quotemain\'][!--quotec--]Try this...[code]<?if ($_POST['submit']) { $query = $_POST(['query']); include("connect.php"); $sql = "INSERT INTO `User` (`name`) VALUES ('$query')"; mysql_query($sql); mysql_close(); echo "$query has been recorded!";}?><form method="POST" action="index.php"><input type="text" name="query"><input type="submit" value="Submit" name="submit"></form>[/code]AllI did was move the PHP to the start of the file, add a quote into your HTML section and remove the quotes around the $_POST bit. Then I surrounded the lot with an if() statement to only run the code if the submit button was pressed.[/quote]I did as exactly as you said, and I got this...Parse error: parse error, unexpected '[', expecting ')' in /home/www/shaolinwars.awardspace.com/index.php on line 3 Link to comment https://forums.phpfreaks.com/topic/8192-arrayquery/#findComment-29893 Share on other sites More sharing options...
Yesideez Posted April 23, 2006 Share Posted April 23, 2006 Slight oversight - change this line:$query = $_POST(['query']);to this:$query = $_POST['query']; Link to comment https://forums.phpfreaks.com/topic/8192-arrayquery/#findComment-29895 Share on other sites More sharing options...
Matthew Rotherham Posted April 23, 2006 Author Share Posted April 23, 2006 [!--quoteo(post=367768:date=Apr 23 2006, 03:10 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 23 2006, 03:10 PM) [snapback]367768[/snapback][/div][div class=\'quotemain\'][!--quotec--]Slight oversight - change this line:$query = $_POST(['query']);to this:$query = $_POST['query'];[/quote]Works like a charm! Thanks. Link to comment https://forums.phpfreaks.com/topic/8192-arrayquery/#findComment-29914 Share on other sites More sharing options...
Yesideez Posted April 23, 2006 Share Posted April 23, 2006 [code]<?if ($_POST['submit']) { if ($_POST['query']) { $query = $_POST(['query']); include("connect.php"); $sql = "INSERT INTO `User` (`name`) VALUES ('$query')"; mysql_query($sql); mysql_close(); echo "$query has been recorded!"; } else {echo "You need to enter some text";}}[/code]Use that to stop empty fields being entered. Link to comment https://forums.phpfreaks.com/topic/8192-arrayquery/#findComment-29915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.