Jump to content


Photo

Array(['query'])


  • Please log in to reply
5 replies to this topic

#1 Matthew Rotherham

Matthew Rotherham
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 April 2006 - 07:25 PM

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?

#2 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 23 April 2006 - 07:56 PM

Try this...
<?
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>
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.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#3 Matthew Rotherham

Matthew Rotherham
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 April 2006 - 08:03 PM

[!--quoteo(post=367763:date=Apr 23 2006, 02:56 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 23 2006, 02:56 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Try this...
<?
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>
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


#4 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 23 April 2006 - 08:10 PM

Slight oversight - change this line:

$query = $_POST(['query']);

to this:

$query = $_POST['query'];
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them

#5 Matthew Rotherham

Matthew Rotherham
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 23 April 2006 - 09:30 PM

[!--quoteo(post=367768:date=Apr 23 2006, 03:10 PM:name=Yesideez)--][div class=\'quotetop\']QUOTE(Yesideez @ Apr 23 2006, 03:10 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Slight oversight - change this line:

$query = $_POST(['query']);

to this:

$query = $_POST['query'];
[/quote]

Works like a charm! Thanks.

#6 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 23 April 2006 - 09:34 PM

<?
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";}
}
Use that to stop empty fields being entered.
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users