Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/53009-cannot-add-to-database/
Share on other sites

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.

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);
	}
}
}
?>

<?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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.