Submit info to database error

Reply

Join Date: Apr 2006
Posts: 11
Reputation: chilllax is an unknown quantity at this point 
Solved Threads: 0
chilllax chilllax is offline Offline
Newbie Poster

Submit info to database error

 
0
  #1
Apr 13th, 2006
[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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 31
Reputation: DGStudios is an unknown quantity at this point 
Solved Threads: 3
DGStudios DGStudios is offline Offline
Light Poster

Re: Submit info to database error

 
0
  #2
Apr 13th, 2006
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.
http://img.photobucket.com/albums/v6.../dgstudios.jpg
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 11
Reputation: chilllax is an unknown quantity at this point 
Solved Threads: 0
chilllax chilllax is offline Offline
Newbie Poster

Re: Submit info to database error

 
0
  #3
Apr 13th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 31
Reputation: DGStudios is an unknown quantity at this point 
Solved Threads: 3
DGStudios DGStudios is offline Offline
Light Poster

Re: Submit info to database error

 
0
  #4
Apr 14th, 2006
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.
http://img.photobucket.com/albums/v6.../dgstudios.jpg
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC