944,181 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1412
  • PHP RSS
Apr 13th, 2006
0

Submit info to database error

Expand Post »
[PHP]<html>
<head>
<title>Participants</title>
</head>
<table align="center">
<tr>
<td>
<a href="http://www.officalhalo.com">Home</a>

<a href="/tournament/FFA.htm">FFA</a> |

<a href="/tournament/signup.htm">Sign Up</a> |

<a href="/tournament/results.htm">Results</a>
</td>
</tr>
</table>
<body>
<h3 align="center">Participants</h3>
<?php
$gamertag=$_POST['gamertag'];
$eaddress=$POST['eaddress'];

if (!$gamertag || !$eaddress)
{
echo 'You have not entered all of the required information.<br />'
.'Please go back and try again.';
exit;
}
if (!get_magic_quotes_gpc())
{
$gamertag = addslashes($gamertag);
$eaddress = addslashes($eaddress);
}

@ $db = new mysqli('localhost', 'username', 'password', 'chilllax_participants');

if (mysqli_connect_error())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

$query = "insert into participants values
('$gamertag', '$eaddress'}";
$result = $db->query($query);
if ($result)
echo $db->affected_rows.' participant added.

$db->close();
?>
</body>
</html>[/PHP]


Theres the code in my page. I have the database set up and also the correct number of tables. My problem is whenever I try and run this script this error comes up parse error, unexpected $. Why is this. Also I am going by a php book thats infront of me and I dont really understand the bit of code that actually inserts the data into the database. This

[PHP]$query = "insert into participants values
('$gamertag', '$eaddress'}";[/PHP]

Thanks for any help. I hope that made sense.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chilllax is offline Offline
11 posts
since Apr 2006
Apr 13th, 2006
0

Re: Submit info to database error

Look at the spot where you are declaring the value of $eaddress

you have written $POST
it needs to be $_POST



keep in mind while debugging the line number is usually close depending on the error. Bad varriables like that are usually DEAD on. Also the simplest mistakes the ones you never think you'd make are often the cause. First rule of programming, if you can't mess it up, that probably what you messed up.
Reputation Points: 10
Solved Threads: 3
Light Poster
DGStudios is offline Offline
31 posts
since Mar 2006
Apr 13th, 2006
0

Re: Submit info to database error

thanks but it still says error unexpected variable on line 53 which is </html> its not even a variable or related to php? I dont think this code is correct

$query = "insert into participants values
('$gamertag', '$eaddress'}";

How does that bit of code know which table to put the variable info into, the table and variable names are the same but can if recognize that?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chilllax is offline Offline
11 posts
since Apr 2006
Apr 14th, 2006
0

Re: Submit info to database error

First. You open a ( and close with a Curly bracket }

Also are those the ONLY TWO colomns in the table. It defaults to the order in which they are listed as the order they show up in the table.

if the table has three colomns and you're only inputing 2 then you need to change the query to tell it thats the only thing your inputting as so.

Insert into tablename (colomn1, colomn3) Values (value1, value2);

Naturally that means you can pick the individual colomns to place data in.

However, it is most likely the curly bracket closing Parenthesis that is causing the problem there if the tables are the same.


also I'm not sure about PHP 5 but I know in four the !$var1 would turn true only if the value = NULL. A 0 length string is not a NULL string.

I'm not sure so it might still work but you might want to consider for easier reading and debugging or just making sure it works. using: strlen($var1) <1
That will return true if the value isn't there. This is the code I've used a few times.
Reputation Points: 10
Solved Threads: 3
Light Poster
DGStudios is offline Offline
31 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: SQL search query
Next Thread in PHP Forum Timeline: How To Print Directly to Printer





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC