View Full Version : need help with an error. (already fixed)
aleminio
07-04-2006, 05:26 PM
for some reason the following thing isn't working.
i removed all the if statements and stuff, the problem is something simple but i can't see what. it says there is a variable problem 3 lines before the end.
<?php
include("config/db_config.php");
$conn = mysql_connect ($db_host, $db_user, $db_password);
$db_select = mysql_select_db("$db_name",$conn);
if (!$db_select){
die ("Could not select the database: <br />". mysql_error());
}
?>
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>">
<table border="0" cellpadding="0">
<tr>
<td><p class="text">ClanName:</p></td>
<td><input type="Text" name="name" style="border: 1 solid" class="text" > [6 characters max]
</td>
</tr>
<tr>
<td><p class="text">Password:</p></td>
<td><input type="password" name="passworddb" class="text" style="border:1 solid" > [10 characters max]
</td>
</tr>
<tr>
<td><p class="text">Mail:</p></td>
<td><input type="Text" name="mail" style="border: 1 solid" class="text"></td>
</tr>
</table>
<p class="text"><input type="Submit" name="submit" value="Finish." style="border: 1 solid" class="text">
</form>
<?php
echo "register a clan: <br><br>"
$sql = "INSERT INTO $playerstable (name, password, mail) VALUES ("$name, $passworddb, $mail")";
mysql_query($sql, $conn);
?>
lavinpj1
07-04-2006, 05:31 PM
echo "register a clan: <br><br>" should be echo "register a clan: <br><br>";
~Phil~
aleminio
07-04-2006, 05:34 PM
God shoot me how don't i notice that.
thanks dude.
edit:I am getting the same error after i took thise line out.
edit2: blah, ok, i fixed it, but now i can't understand why isn't it inserting the data into the tables. i mean it does create a new row but the mail,pass and name are blank. i guess something is wrong with the forms.
<?php
include("config/db_config.php");
$conn = mysql_connect ($db_host, $db_user, $db_password);
$db_select = mysql_select_db("$db_name",$conn);
if (!$db_select){
die ("Could not select the database: <br />". mysql_error());
}
?>
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>">
<table border="0" cellpadding="0">
<tr>
<td><p class="text">ClanName:</p></td>
<td><input type="Text" name="name" style="border: 1 solid" class="text" > [6 characters max]
</td>
</tr>
<tr>
<td><p class="text">Password:</p></td>
<td><input type="password" name="passworddb" class="text" style="border:1 solid" > [10 characters max]
</td>
</tr>
<tr>
<td><p class="text">Mail:</p></td>
<td><input type="Text" name="mail" style="border: 1 solid" class="text"></td>
</tr>
</table>
<p class="text"><input type="Submit" name="submit" value="Finish." style="border: 1 solid" class="text">
</form>
<?php
if ($submit) {
$name = strip_tags($name);
$name = trim($name);
$password = strip_tags($password);
$password = trim($password);
$mail = strip_tags($mail);
$mail = trim($mail);
if ($password == "")
{
die ("please enter password");
}
else {
if ($name == "")
{
die ("please enter clanname");
}
else{
$sql = "INSERT INTO $playerstable (name, password, mail) VALUES ('$name', '$passworddb', '$mail')";
mysql_query($sql, $conn);
}}}
?>
Lordrea
07-04-2006, 06:48 PM
Try putting the query as:
$sql = "INSERT INTO $playerstable (name, password, mail) VALUES ('$name', '$passworddb', '$mail')";
Taylor_1978
07-04-2006, 06:49 PM
<?php
include("config/db_config.php");
$conn = mysql_connect ($db_host, $db_user, $db_password);
$db_select = mysql_select_db("$db_name",$conn);
if (!$db_select){
die ("Could not select the database: <br />". mysql_error());
}
?>
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>">
<table border="0" cellpadding="0">
<tr>
<td><p class="text">ClanName:</p></td>
<td><input type="Text" name="name" style="border: 1 solid" class="text" > [6 characters max]
</td>
</tr>
<tr>
<td><p class="text">Password:</p></td>
<td><input type="password" name="passworddb" class="text" style="border:1 solid" > [10 characters max]
</td>
</tr>
<tr>
<td><p class="text">Mail:</p></td>
<td><input type="Text" name="mail" style="border: 1 solid" class="text"></td>
</tr>
</table>
<p class="text"><input type="Submit" name="submit" value="Finish." style="border: 1 solid" class="text">
</form>
<?php
if ($_POST['submit']) {
$name = strip_tags($_POST['name']);
$name = trim($name);
$password = strip_tags($_POST['password']);
$password = trim($password);
$mail = strip_tags($_POST['mail']);
$mail = trim($mail);
if ($password == "")
{
die ("please enter password");
}
else {
if ($name == "")
{
die ("please enter clanname");
}
else{
$sql = "INSERT INTO $playerstable (name, password, mail) VALUES ('$name', '$password', '$mail')";
mysql_query($sql, $conn);
}
}
}
?>
aleminio
07-04-2006, 07:04 PM
Taylor_1978, it looks good but it always says "please enter password"
like i didn't enter a password at all.
Taylor_1978
07-04-2006, 07:11 PM
OOPS! Try this:
<?php
include("config/db_config.php");
$conn = mysql_connect ($db_host, $db_user, $db_password);
$db_select = mysql_select_db("$db_name",$conn);
if (!$db_select){
die ("Could not select the database: <br />". mysql_error());
}
?>
<form method="post" action="<?php echo $_SERVER[PHP_SELF];?>">
<table border="0" cellpadding="0">
<tr>
<td><p class="text">ClanName:</p></td>
<td><input type="Text" name="name" style="border: 1 solid" class="text" > [6 characters max]
</td>
</tr>
<tr>
<td><p class="text">Password:</p></td>
<td><input type="password" name="passworddb" class="text" style="border:1 solid" > [10 characters max]
</td>
</tr>
<tr>
<td><p class="text">Mail:</p></td>
<td><input type="Text" name="mail" style="border: 1 solid" class="text"></td>
</tr>
</table>
<p class="text"><input type="Submit" name="submit" value="Finish." style="border: 1 solid" class="text">
</form>
<?php
if ($_POST['submit']) {
$name = strip_tags($_POST['name']);
$name = trim($name);
$password = strip_tags($_POST['passworddb']);
$password = trim($password);
$mail = strip_tags($_POST['mail']);
$mail = trim($mail);
if (!$password)
{
die ("please enter password");
}
else {
if (!$name)
{
die ("please enter clanname");
}
else{
$sql = "INSERT INTO $playerstable (name, password, mail) VALUES ('$name', '$password', '$mail')";
mysql_query($sql, $conn);
}
}
}
?>
And note I've changed if($password=="") to if(!$password) as you are asking if the variable is empty.
aleminio
07-04-2006, 07:14 PM
oh, it works perfectly now.
but i can't understand why if($password=="") isn't working.
doesn't == "" means empty?
Taylor_1978
07-04-2006, 07:26 PM
Your original script did not work because you had called the form variable "$passworddb" and then were stripping and trimming "$password" - then trying to enter it into the database as $passworddb again.
So I corrected all this.
The if($password == "") actually had nothing to do with this. I only changed it because if(!$password) is a better way to write if($password == "").
aleminio
07-04-2006, 07:36 PM
ok, thanks.
i was sure i changed it as needed :|
well, a beginner mistake i guess, just started using php a couple of days ago.
thx again..
Spookster
07-04-2006, 09:36 PM
In the future, please use a more descriptive subject when posting a question. See posting guidelines. (http://www.codingforums.com/postguide.htm)
aleminio
07-04-2006, 10:24 PM
In the future, please use a more descriptive subject when posting a question. See posting guidelines. (http://www.codingforums.com/postguide.htm)
yah, sorry about that, after posting i wanted to edit but it's impossible
to edit the subject.
Taylor_1978
07-04-2006, 10:41 PM
yah, sorry about that, after posting i wanted to edit but it's impossible
to edit the subject.
Yes you can.. when you click EDIT.. then select Go Advanced from the buttons under the edit area.. here you can change the subject :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.