SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 33
Thread: php error plz help
-
Jan 4, 2005, 09:05 #1
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
php error plz help
hey im working on a registration page and for some rison it doesnt work , plz help .
Code:<?php include "notice.html"; include "connection.php"; if (!isset($_POST["insert_button"])) { ?> <FORM action="<?= $_SERVER["notice.php"]; ?>" method="POST"> <TABLE border=0 cellpadding=7 cellspacing=7> <TR> <br><br><br><br> <TD><font color="#ffbc8c83">account:</font></TD> <TD><INPUT type="TEXT" name="account" size=20 maxlength=20 value="<?= $_POST["account"]; ?>"></TD> </TR> <TR> <TD><font color="#ffbc8c83">password:</font></TD> <TD><INPUT type="password" name="password" size=20 maxlength=20 value="<?= $_POST["password"]; ?>"></TD> </TR> <TR> <TD><font color="#ffbc8c83">e-mail:</font></TD> <TD><INPUT type="TEXT" name="e-mail" size=30 maxlength=50 value="<?= $_POST["e-mail"]; ?>"></TD> </TR> <TR> <TD><font color="#ffbc8c83">age:</font></TD> <TD><INPUT type="TEXT" name="age" size=2 maxlength=2 value="<?= $_POST["age"]; ?>"></TD> </TR> <TR> <TD align="right"><INPUT type="SUBMIT" name="insert_button" value="register"></TD> <TD align="left"><INPUT type="RESET" value="reset"></TD> </TR> </TABLE> </FORM> <? } if (isset($_POST["insert_button"])) { $account=$_POST["account"]; $password=$_POST["password"]; $e_mail=$_POST["e-mail"]; $age=$_POST["age"]; $grade_insert_errors=""; if ($account=="") $grade_insert_errors.="<br>account name isnt good.<BR>"; if ($password=="") $grade_insert_errors.="password just isnt right.<BR>"; if ($e_mail=="") $grade_insert_errors.="type a working e-mail plz.<BR>"; if ($age=="") $grade_insert_errors.="age isnt good.<BR>"; if ($grade_insert_errors=="") { $account=$account; $password=$password; $e_mail=$e_mail; $age=$age; $grade_insert_query="INSERT INTO ".$reg." (account".(($account!="")?",account":"")."".(($password!="")?",pass":"")."".(($e_mail!="")?",E-mail":"")."".(($age!="")?",age":"").") VALUES ("; $insert_query.=($account!="")?",'$account'":""; $insert_query.=($password!="")?",'$password'":""; $insert_query.=($e_mail!="")?",'$e-mail'":""; $insert_query.=($age!="")?",'$age'":""; $insert_query.=")"; $result=@mysql_query ($grade_insert_query,$grade_con); if (mysql_affected_rows()==1) { echo "<BR><B><font color=orange>account made sucsesfully</font></B><BR>"; } else { echo "<BR><br><B><font color=orange>account could not be made</font></B><BR>"; unset($_POST["insert_button"]); } } else { echo "<BR><br><FONT color=\"#ffbc8c83\">".$grade_insert_errors."</FONT><BR>"; unset($_POST["insert_button"]); } } ?>
Code:$grade_insert_query="INSERT INTO ".$reg." (account".(($account!="")?",account":"")."".(($password!="")?",pass":"")."".(($e_mail!="")?",E-mail":"")."".(($age!="")?",age":"").") VALUES (";
Code:$result=@mysql_query ($grade_insert_query,$grade_con); if (mysql_affected_rows()==1)
-
Jan 4, 2005, 09:17 #2
From a quick look, it seems that you haven't defined $reg - which should be the name of the table you want to insert your values into.
Also, I would test the value of $result, if false, then display the results of mysql_error(), and echo the value of $grade_insert_query before you run the query.
-
Jan 4, 2005, 09:24 #3
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
is this ok ?:
Code:$grade_insert_query="INSERT INTO ".$grade_reg_table." (account".(($account!="")?",account":"")."".(($password!="")?",pass":"")."".(($e_mail!="")?",E-mail":"")."".(($age!="")?",age":"").") VALUES ("; $insert_query.=($account!="")?",'$account'":""; $insert_query.=($password!="")?",'$password'":""; $insert_query.=($e_mail!="")?",'$e-mail'":""; $insert_query.=($age!="")?",'$age'":""; $insert_query.=")"; $result=@mysql_query ($grade_insert_query,$grade_con);
-
Jan 4, 2005, 09:30 #4
Try it and see
But once again, have you defined $grade_reg_table anywhere?
Also, try my suggestions about echo the SQL command before executing it - makes it easier to spot errors and also check the $result variable.
-
Jan 4, 2005, 09:37 #5
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok sorry im a noob :/ i have no idia how to define the reg table ... and i've done the part of posting the stuff it sandes to the table ...
-
Jan 4, 2005, 09:40 #6
We were all noobs once upon a time
What is the name of the table that you want to insert that data into? Whatever that name is, that is what you shoule set $grade_reg_table to, or just hard-code the table name into the query string.
e.g
PHP Code:$grade_reg_table = 'GradeTable';
-
Jan 4, 2005, 09:42 #7
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok here is what he posted me when i told him to post what he is going to send :
Code:INSERT INTO reg (reg,Admin,yoman,frerez@hotmail.com,15) VALUES (
and reg is the name of the table
the rest is exacly the info i entered ....
and this is the code :
Code:if ($grade_insert_errors=="") { $account=$account; $password=$password; $e_mail=$e_mail; $age=$age; $grade_reg_table='reg'; $grade_insert_query="INSERT INTO ".$grade_reg_table." (reg".(($account!="")?",$account":"")."".(($password!="")?",$password":"")."".(($e_mail!="")?",$e_mail":"")."".(($age!="")?",$age":"").") VALUES ("; $insert_query.=($account!="")?",'$account'":""; $insert_query.=($password!="")?",'$password'":""; $insert_query.=($e_mail!="")?",'$e-mail'":""; $insert_query.=($age!="")?",'$age'":""; $insert_query.=")"; $result=@mysql_query ($grade_insert_query,$grade_con); if (mysql_affected_rows()==1) { echo "<BR><B><font color=orange>account made sucsesfully</font></B><BR>"; } else { echo "<BR><br><B><font color=orange>account could not be made</font></B><BR>"; unset($_POST["insert_button"]); echo "<BR><br><FONT color=\"#ffbc8c83\">".$grade_insert_query."</FONT><BR>"; echo "<BR><br><FONT color=\"#ffbc8c83\">".$grade_con."</FONT><BR>"; }
-
Jan 4, 2005, 09:50 #8
Ok - the syntax for an INSERT SQL statement is
INSERT INTO table_name (col1, ...) VALUES (val1, ...)
where
table_name is the name of the table you want to store the values
col1 ... are the names of the columns where you want the values stored
val1... are the values to be stored
so in your case, guessing at the column names, you want something that looks like
INSERT INTO GradeTable (AccountID, Password, EMail, Age) VALUES ('account', 'Admin', 'frerez@hotmail.com', 15);
Note very carfully which values are surrounded by single quotes.
Hope this helps
-
Jan 4, 2005, 10:04 #9
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
sound cool but is the result
Code:$result=@mysql_query ($grade_insert_query,$grade_con);
its nothing ... and i got an error on this line:
Code:$grade_insert_query=INSERT INTO reg (account,password,e-mail,age) VALUES ($account,$password,$e_mail,$age);
-
Jan 4, 2005, 10:17 #10
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
made some changes ... didnt help thought ... still error in the first line here :
Code:$grade_insert_query= INSERT INTO reg (account,password,e-mail,age) VALUES ('$account','$password','$e_mail',$age); $insert_query.=($account!="")?",'$account'":""; $insert_query.=($password!="")?",'$password'":""; $insert_query.=($e-mail!="")?",'$e_mail'":""; $insert_query.=($age!="")?",'$age'":""; $insert_query.=")"; $result=@mysql_query ($grade_insert_query,$grade_con);
Code:?> <FORM action="<?= $_SERVER["notice.php"]; ?>" method="POST"> <TABLE border=0 cellpadding=7 cellspacing=7> <TR> <br><br><br><br> <TD><font color="#ffbc8c83">account:</font></TD> <TD><INPUT type="TEXT" name="account" size=20 maxlength=20 value="<?= $_POST["account"]; ?>"></TD> </TR> <TR> <TD><font color="#ffbc8c83">password:</font></TD> <TD><INPUT type="password" name="password" size=20 maxlength=20 value="<?= $_POST["password"]; ?>"></TD> </TR> <TR> <TD><font color="#ffbc8c83">e-mail:</font></TD> <TD><INPUT type="TEXT" name="e-mail" size=30 maxlength=50 value="<?= $_POST["e-mail"]; ?>"></TD> </TR> <TR> <TD><font color="#ffbc8c83">age:</font></TD> <TD><INPUT type="TEXT" name="age" size=2 maxlength=2 value="<?= $_POST["age"]; ?>"></TD> </TR> <TR> <TD align="right"><INPUT type="SUBMIT" name="insert_button" value="register"></TD> <TD align="left"><INPUT type="RESET" value="reset"></TD> </TR> </TABLE> </FORM> <?
-
Jan 4, 2005, 10:20 #11
try this code
PHP Code:if ('' == $grade_insert_errors)
{
// make sure strings are quoted and escaped
$account = '\''. mysql_real_escape_string($account) . '\'';
$password = '\''. mysql_real_escape_string($password) . '\'';
$e_mail = '\''. mysql_real_escape_string($e_mail) . '\'';
$age = $age;
$grade_reg_table = 'reg';
$grade_insert_query = 'INSERT INTO '
. $grade_reg_table
. ' (account, password, email, age)'
. ' VALUES ('
. $account
. ', ' . $password
. ', ' . $email
. ', ' . $age
. ')'
;
// START DIAGNOSTIC - REMOVE WHEN WORKING
echo 'Executing ' . $grade_insert_query . '<br />';
// END DIAGNOSTIC - REMOVE WHEN WORKING
$result = @mysql_query ($grade_insert_query,$grade_con);
if (false == $result)
{
echo ' Failed to execute ' . $grade_insert_query . ' due to ' . mysql_error() . '<br />';
}
else
{
echo 'Account created <br />';
}
-
Jan 4, 2005, 10:30 #12
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i got this msg :
Code:Executing INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15) Failed to execute INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15) due to
-
Jan 4, 2005, 10:42 #13
ok - change these 2 lines
PHP Code:$result = @mysql_query ($grade_insert_query,$grade_con);
if (false == $result)
PHP Code:$result = mysql_query ($grade_insert_query,$grade_con);
// START OF DIAGNOSTIC - REMOVE WHEN WORKING
echo 'Result = ' . $result . '<br />';
// END OF DIAGNOSTIC - REMOVE WHEN WORKING
if (false === $result)
-
Jan 4, 2005, 10:46 #14
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok now this is wierd:
Code:Executing INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15) Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/www/somatnt.superihost.com/notice.php on line 90 Result = Account created
-
Jan 4, 2005, 10:52 #15
Ah I think I see what the problem might be
$grade_con
Where is the connection defined / set-up?
Also, you should change the line
PHP Code:if (false === $result)
PHP Code:if (false == $result)
-
Jan 4, 2005, 10:54 #16
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
u mean the file that tells me wich host and db to connect to ?
-
Jan 4, 2005, 10:55 #17
Yes
-
Jan 4, 2005, 10:56 #18
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
this ?:
Code:<?php $db_host = "superihost.com"; $username = "somatnt_yosoma"; $password = "******"; $DB_name = "somatnt_yosoma"; echo "<HTML><BODY>"; $chan = mysql_connect ($db_host, $username, $password); mysql_select_db ($DB_name, $chan); ?>
u can see in my first post i've added it (connection.php)
-
Jan 4, 2005, 11:00 #19
No - I'm glad you **** out the password.
As you can see from that code, the MySQL link identifier is called $chan, so this is what you shuold use in the mysql_query function call.
Try it and post the results
-
Jan 4, 2005, 11:04 #20
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
here is the resolt ... (long):
Code:Executing INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15) Result = Failed to execute INSERT INTO reg (account, password, e-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com', 15) due to You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '-mail, age) VALUES ('Admin', 'yoman', 'frerez@hotmail.com',
-
Jan 4, 2005, 11:10 #21
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
btw ... the fields in my table are :
account , password , e-mail , age
-
Jan 4, 2005, 11:19 #22
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
should i change the field name "e-mail" to somthing else?
-
Jan 4, 2005, 11:20 #23
Ah - ok
change this line
PHP Code:. ' (account, password, email, age)'
PHP Code:. ' (account, password, `e-mail`, age)'
-
Jan 4, 2005, 11:22 #24
- Join Date
- Jan 2005
- Location
- israel
- Posts
- 37
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
cant be done ... made an error on that line ...
-
Jan 4, 2005, 11:24 #25
What was the error? It worked ok for me
Also is it possible to change the name of the e-mail field by removing the '-'?
Bookmarks