adam1612 Posted May 26, 2007 Share Posted May 26, 2007 hello everyone im having an error, whenether i use this php script it will not add it to the table in the database = <?php $error=""; $badports=array(80,21,23,8080); if(isset($_POST["frmsent"])){ if($_POST["email"]==""){ $error="Please enter your email. <br>"; }elseif(!eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$", stripslashes(trim($_POST['email'])))){ $error.="Please enter a valid email address.<br>"; } if($_POST["pass"]==""){ $error.="Please enter your password. <br>"; }elseif(strlen($_POST["pass"])<5){ $error.="Your password is too short.<br>"; } if($_POST["name"]==""){ $error.="Please enter your server's name.<br>"; } if($_POST["ip"]==""){ $error.="Please enter your server's IP.<br>"; } if($_POST["port"]==""){ $error.="Please enter your server's port.<br>"; }elseif(in_array($_POST["port"],$badports)){ $error.="This port number is not allowed.<br>"; } if($_POST["owner"]==""){ $error.="Please enter the server owner's name.<br>"; } if($error == ""){ $server=@fsockopen($_POST["ip"], $_POST["port"], $num, $error, 5);//true = server online if(!$server){ $error.="Server offline. Please turn on.<br>"; }else{ include("config.php"); $connection = @mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $connection) or die(mysql_error()); $email=$_POST["email"]; $pass=md5($_POST["pass"]); $imgurl=$_POST["imgurl"]; $name=$_POST["name"]; $ip=$_POST["ip"]; $port=$_POST["port"]; $owner=$_POST["owner"]; $site=$_POST["site"]; $features=$_POST["features"]; $q="INSERT INTO `ratings` (`email`,`pass`,`imgurl`,`name`,`ip`,`port`,`owner`,`site`,`features`,`uptime`,`num_ping`,`online`) VALUES ('$email','$pass','$imgur','$name','$ip','$port','$owner','$site','$features','100','1','1')"; if (!get_magic_quotes_gpc()) { $q =mysql_real_escape_string($q); } $result=mysql_query($q,$connection); $sucess=true; unset($_POST); } } } ?> <div id="list"> <form action="add.php" method="POST"> <table width="75%" border=1> <thead> <tr> <th align="center" colspan="2"><b>Add Server</b></th> </tr> </thead> <tfoot> <tr> <td align="center" colspan="2"><b><a href="status.php">Back</a></b></td> </tr> </tfoot> <tbody> <?php if($error != ""){ echo "<tr>" ."<th align=\"center\" colspan=\"2\"><b><font color=\"red\">".$error."</font></b></th>" ."</tr>"; }elseif($sucess){ echo "<tr>" ."<th align=\"center\" colspan=\"2\"><b><font color=\"green\">Server added sucessfully.</font></b></th>" ."</tr>"; } ?> <tr> <td width="25%"><b>E-mail</b></td> <td width="75%"><input type="text" name="email" value="<?=$_POST["email"];?>" size="50" maxlength="30"> <small> Enter your email. Max characters 30 </small></td> </tr> <tr> <td width="25%"><b>Password</b></td> <td width="75%"><input type="password" name="pass" size="50" maxlength="15"> <small> Enter your password.. Max characters 15, Minimum 5 </small></td> </tr> <tr> <td width="25%"><b>Server Banner</b></td> <td width="75%"><input name="imgurl" type="text" value="<?=$_POST["imgurl"];?>" size="50"> <small> Enter the URL to the png, jpg or gif image here.</small></td> </tr> <tr> <td width="25%"><b>Server Name</b></td> <td width="75%"><input type="text" name="name" value="<?=$_POST["name"];?>" size="50" maxlength="15"> <small> Enter the name of your server here. Max characters 15</small></td> </tr> <tr> <td width="25%"><b>Server IP</b></td> <td width="75%"><input type="text" name="ip" value="<?=$_POST["ip"];?>" size="50" maxlength="20"> <small> Enter the IP of your server here. Max characters 20</small></td> </tr> <tr> <td width="25%"><b>Server Port</b></td> <td width="75%"><input type="text" name="port" value="<?=$_POST["port"];?>" size="50" maxlength="5"> <small> Enter the port of your server here. Max characters 5</small></td> </tr> <tr> <td width="25%"><b>Server Owner</b></td> <td width="75%"><input type="text" name="owner" value="<?=$_POST["owner"];?>" size="50" maxlength="15"> <small> Enter your online name here. Max characters 15</small></td> </tr> <tr> <td width="25%"><b>Server Website</b></td> <td width="75%"><input type="text" name="site" value="<?=$_POST["site"];?>"s size="50" maxlength="20"> <small> Enter the URL of your server website here. Max characters 20</small></td> </tr> <tr> <td width="25%"><b>Server Features</b></td> <td width="75%"><textarea name="features" wrap="physical" rows="3" cols="90"><?=$_POST["features"];?></textarea> </td> </tr> <tr> <td colspan="2" align="center"> <input name="frmsent" type="checkbox" style="visibility:hidden" checked="CHECKED" value="checked"/> <input type="submit" value="Submit"> <INPUT TYPE="reset"></td> </tr> </tbody> </table> </form> </div> Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/ Share on other sites More sharing options...
Caesar Posted May 26, 2007 Share Posted May 26, 2007 <?php $q="INSERT INTO ratings ($fields) VALUES ($values)"; ?> "ratings" does not need to be enclosed in quotes or ticks....for starters. Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261866 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 thanks for that info and it still doesnt add Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261871 Share on other sites More sharing options...
Caesar Posted May 26, 2007 Share Posted May 26, 2007 Have you done any debugging? It's lat in the day and Im too lazy to look through that. Your code looks more complex than it should be. Lazy approach...Before the insert, do a print_r($_POST);exit;...see if it craps out before the actual INSERT...or if it outputs the contents of the $_POST array. Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261874 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 sorry but im dum at php could you tell me where about it prints out? also this may help easyier = <?php $error=""; $badports=array(80,21,23,8080); if(isset($_POST["frmsent"])){ if($_POST["email"]==""){ $error="Please enter your email. <br>"; }elseif(!eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$", stripslashes(trim($_POST['email'])))){ $error.="Please enter a valid email address.<br>"; } if($_POST["pass"]==""){ $error.="Please enter your password. <br>"; }elseif(strlen($_POST["pass"])<5){ $error.="Your password is too short.<br>"; } if($_POST["name"]==""){ $error.="Please enter your server's name.<br>"; } if($_POST["ip"]==""){ $error.="Please enter your server's IP.<br>"; } if($_POST["port"]==""){ $error.="Please enter your server's port.<br>"; }elseif(in_array($_POST["port"],$badports)){ $error.="This port number is not allowed.<br>"; } if($_POST["owner"]==""){ $error.="Please enter the server owner's name.<br>"; } if($error == ""){ $server=@fsockopen($_POST["ip"], $_POST["port"], $num, $error, 5);//true = server online if(!$server){ $error.="Server offline. Please turn on.<br>"; }else{ include("config.php"); $connection = @mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $connection) or die(mysql_error()); $email=$_POST["email"]; $pass=md5($_POST["pass"]); $imgurl=$_POST["imgurl"]; $name=$_POST["name"]; $ip=$_POST["ip"]; $port=$_POST["port"]; $owner=$_POST["owner"]; $site=$_POST["site"]; $features=$_POST["features"]; $q="INSERT INTO `ratings` (`email`,`pass`,`imgurl`,`name`,`ip`,`port`,`owner`,`site`,`features`,`uptime`,`num_ping`,`online`) VALUES ('$email','$pass','$imgur','$name','$ip','$port','$owner','$site','$features','100','1','1')"; if (!get_magic_quotes_gpc()) { $q =mysql_real_escape_string($q); } $result=mysql_query($q,$connection); $sucess=true; unset($_POST); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261876 Share on other sites More sharing options...
per1os Posted May 26, 2007 Share Posted May 26, 2007 <?php $error=""; $badports=array(80,21,23,8080); if(isset($_POST["frmsent"])){ if($_POST["email"]==""){ $error="Please enter your email. <br>"; }elseif(!eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,6}$", stripslashes(trim($_POST['email'])))){ $error.="Please enter a valid email address.<br>"; } if($_POST["pass"]==""){ $error.="Please enter your password. <br>"; }elseif(strlen($_POST["pass"])<5){ $error.="Your password is too short.<br>"; } if($_POST["name"]==""){ $error.="Please enter your server's name.<br>"; } if($_POST["ip"]==""){ $error.="Please enter your server's IP.<br>"; } if($_POST["port"]==""){ $error.="Please enter your server's port.<br>"; }elseif(in_array($_POST["port"],$badports)){ $error.="This port number is not allowed.<br>"; } if($_POST["owner"]==""){ $error.="Please enter the server owner's name.<br>"; } if($error == ""){ $server=@fsockopen($_POST["ip"], $_POST["port"], $num, $error, 5);//true = server online if(!$server){ $error.="Server offline. Please turn on.<br>"; }else{ include("config.php"); $connection = @mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $connection) or die(mysql_error()); // better tactic for mysql_real_escape foreach ($_POST as $key => $val) { if (get_magic_quotes_gpc()) { $val = stripslashes($val); } $_POST[$key] = mysql_real_escape_string($val); } $email=$_POST["email"]; $pass=md5($_POST["pass"]); $imgurl=$_POST["imgurl"]; $name=$_POST["name"]; $ip=$_POST["ip"]; $port=$_POST["port"]; $owner=$_POST["owner"]; $site=$_POST["site"]; $features=$_POST["features"]; $q="INSERT INTO `ratings` (`email`,`pass`,`imgurl`,`name`,`ip`,`port`,`owner`,`site`,`features`,`uptime`,`num_ping`,`online`) VALUES ('$email','$pass','$imgurl','$name','$ip','$port','$owner','$site','$features','100','1','1')"; /* If this ever runs it will screw your query, see above for a better tactic if (!get_magic_quotes_gpc()) { $q =mysql_real_escape_string($q); }*/ $result=mysql_query($q,$connection) OR DIE(mysql_error()); // add for debugging report the error $sucess=true; unset($_POST); } } } ?> <div id="list"> <form action="add.php" method="POST"> <table width="75%" border=1> <thead> <tr> <th align="center" colspan="2"><b>Add Server</b></th> </tr> </thead> <tfoot> <tr> <td align="center" colspan="2"><b><a href="status.php">Back</a></b></td> </tr> </tfoot> <tbody> <?php if($error != ""){ echo "<tr>" ."<th align=\"center\" colspan=\"2\"><b><font color=\"red\">".$error."</font></b></th>" ."</tr>"; }elseif($sucess){ echo "<tr>" ."<th align=\"center\" colspan=\"2\"><b><font color=\"green\">Server added sucessfully.</font></b></th>" ."</tr>"; } ?> <tr> <td width="25%"><b>E-mail</b></td> <td width="75%"><input type="text" name="email" value="<?=$_POST["email"];?>" size="50" maxlength="30"> <small> Enter your email. Max characters 30 </small></td> </tr> <tr> <td width="25%"><b>Password</b></td> <td width="75%"><input type="password" name="pass" size="50" maxlength="15"> <small> Enter your password.. Max characters 15, Minimum 5 </small></td> </tr> <tr> <td width="25%"><b>Server Banner</b></td> <td width="75%"><input name="imgurl" type="text" value="<?=$_POST["imgurl"];?>" size="50"> <small> Enter the URL to the png, jpg or gif image here.</small></td> </tr> <tr> <td width="25%"><b>Server Name</b></td> <td width="75%"><input type="text" name="name" value="<?=$_POST["name"];?>" size="50" maxlength="15"> <small> Enter the name of your server here. Max characters 15</small></td> </tr> <tr> <td width="25%"><b>Server IP</b></td> <td width="75%"><input type="text" name="ip" value="<?=$_POST["ip"];?>" size="50" maxlength="20"> <small> Enter the IP of your server here. Max characters 20</small></td> </tr> <tr> <td width="25%"><b>Server Port</b></td> <td width="75%"><input type="text" name="port" value="<?=$_POST["port"];?>" size="50" maxlength="5"> <small> Enter the port of your server here. Max characters 5</small></td> </tr> <tr> <td width="25%"><b>Server Owner</b></td> <td width="75%"><input type="text" name="owner" value="<?=$_POST["owner"];?>" size="50" maxlength="15"> <small> Enter your online name here. Max characters 15</small></td> </tr> <tr> <td width="25%"><b>Server Website</b></td> <td width="75%"><input type="text" name="site" value="<?=$_POST["site"];?>"s size="50" maxlength="20"> <small> Enter the URL of your server website here. Max characters 20</small></td> </tr> <tr> <td width="25%"><b>Server Features</b></td> <td width="75%"><textarea name="features" wrap="physical" rows="3" cols="90"><?=$_POST["features"];?></textarea> </td> </tr> <tr> <td colspan="2" align="center"> <input name="frmsent" type="checkbox" style="visibility:hidden" checked="CHECKED" value="checked"/> <input type="submit" value="Submit"> <INPUT TYPE="reset"></td> </tr> </tbody> </table> </form> </div> See the comments in code. Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261877 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 im sorry for askin 2 many questions or so but what is the tactic to it? lol Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261878 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 i've tried $key but when i run it again it comes up with Query was empty Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261884 Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 Your original query is fine...it is perfectly acceptable to have backtics around table and column names. Having single or double quotes around them will cause an error... Anyway, I haven't seen anyone ask what the error is, and I don't see it posted... Change: $result=mysql_query($q,$connection); to $result=mysql_query($q,$connection) or die(mysql_error($connection); And post what the error you're getting is. Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261886 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 now i've got this error Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\server\add.php on line 56 Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261888 Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 You're killing me...use some basic debugging skills here...there's a missing closing parenthesis on the end of the statement... $result=mysql_query($q,$connection) or die(mysql_error($connection)); Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261890 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 man this is like a puzzle! now i get Unknown column 'email' in 'field list' Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261891 Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 Does your database have a column named "email" in it? Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261892 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 yes it does Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261893 Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 according to the error, it doesn't... Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261894 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 the table does exist and everything is its just an error Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261895 Share on other sites More sharing options...
hitman6003 Posted May 26, 2007 Share Posted May 26, 2007 The table existing doesn't mean that the column exists inside of the table. "just an error" is still an error that prevents your script from executing properly. Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261902 Share on other sites More sharing options...
adam1612 Posted May 26, 2007 Author Share Posted May 26, 2007 thanks for your help i figured out the problem with the table i made it select the wrong table.. lol sorry Quote Link to comment https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/#findComment-261904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.