| | |
Submit info to database error
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2006
Posts: 11
Reputation:
Solved Threads: 0
[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.
<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.
•
•
Join Date: Mar 2006
Posts: 31
Reputation:
Solved Threads: 3
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.
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
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
•
•
Join Date: Apr 2006
Posts: 11
Reputation:
Solved Threads: 0
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?
$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?
•
•
Join Date: Mar 2006
Posts: 31
Reputation:
Solved Threads: 3
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.
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
When all that is becomes one. That is the anomoly. That is... Death's Gate Studios (c) 2005
![]() |
Similar Threads
- need help setting up a php/mysql search (PHP)
- submiting info into a database for retrieval! (PHP)
- Database error cord identify (Java)
- Doesn't check if username or email exits in database properly (ASP.NET)
- php wont submit data into the database (PHP)
Other Threads in the PHP Forum
- Previous Thread: SQL search query
- Next Thread: How To Print Directly to Printer
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube





