Jump to content

[SOLVED] Major posting problem... ???


kaimason1

Recommended Posts

This is the second of my two php problems. I am creating a post page in php and I am getting the following error message :

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource

 

Here is the script that gives me said error message:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> Populate Database </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
</HEAD>
<BODY>
  <H1>Add Contact</H1>
  <FORM METHOD="GET" action="post.php">
   <P>First Name</P><input type="text" name="first" size=20 maxlength=50>
   <P>Last Name</P><input type="text" name="last" size=20 maxlength=50>
   <P>Cell Phone</P><input type="text" name="cell" size=20 maxlength=50>
   <P>Email</P><input type="text" name="email" size=20 maxlength=50>
   <INPUT type="hidden"
   <P></P><INPUT type="submit" value="ADD CONTACT">
  </FORM>
</BODY>
</HTML>
<?
//Retrieve Variables//
$first=@$_GET['first'];
$last=@$_GET['last'];
$cell=@$_GET['cell'];
$email=@$_GET['email'];
//Make sure all variables submitted//
if($first==""){
die("Enter First Name... please?");
}else if($last==""){
die("Enter Last Name... please?");
}else if($cell==""){
die("Enter Cell Phone... please?");
}else if($email==""){
die("Enter Email... please?");
}else{
//Connect to database//
$username="mekam2_kai";
$password="753159";
$database="mekam2_kai1";
mysql_connect(localhost,$username,$password)or die("I couldnt connect, sir. By the way, am I being paid for acting like a personal butler?");
@mysql_select_db($database)or die("The database you are trying to access is currently unavailable. Curious...");
//Query statement//
$query="INSERT INTO TEST1_contacts VALUES(,$first,$last,$cell,$email)";
mysql_query($query);
$query="SELECT * FROM `TEST1_contacts` WHERE `First_Name`=$first";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num==0){
die("Could not insert data");
}else if($num>1){
$query="SELECT * FROM TEST1_contacts WHERE Last_Name=$last";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num==0){
	die("Could not insert data");
}else if($num>1){
	$query="SELECT * FROM TEST1_contacts WHERE Phone_Number=$cell";
	$result=mysql_query($query);
	$num=mysql_num_rows($result);
	if($num==0){
		die("Could not insert data");
	}else if($num>1){
	$query="SELECT * FROM TEST1_contacts WHERE Email=$email";
	$result=mysql_query($query);
	$num=mysql_num_rows($result);
	if($num==0){
		die("Could not insert data");
		}
	}
}
}
}
$i=0;
while($i<$num);
$first=mysql_result($result,$i,"First_Name");
$last=mysql_result($result,$i,"Last_Name");
$cell=mysql_result($result,$i,"Phone_Number");
$email=mysql_result($result,$i,"Email");
echo "Inserted $first $last Cell: $cell Email: $email";
?>

Link to comment
Share on other sites

O.K.... my posting page is error message central now... help? ??? ??? ???

 

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'censored'@'localhost' (using password: NO) in ... on line 24

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in ... on line 24

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'censored'@'localhost' (using password: NO) in ... on line 25

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in ... on line 25

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'censored'@'localhost' (using password: NO) in ... on line 26

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in ... on line 26

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'censored'@'localhost' (using password: NO) in ... on line 27

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in ... on line 27

Enter First Name... please?

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> Populate Database </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
</HEAD>
<BODY>
  <H1>Add Contact</H1>
  <FORM METHOD="GET" action="post.php">
   <P>First Name</P><input type="text" name="first" size=20 maxlength=50>
   <P>Last Name</P><input type="text" name="last" size=20 maxlength=50>
   <P>Cell Phone</P><input type="text" name="cell" size=20 maxlength=50>
   <P>Email</P><input type="text" name="email" size=20 maxlength=50>
   <INPUT type="hidden"
   <P></P><INPUT type="submit" value="ADD CONTACT">
  </FORM>
</BODY>
</HTML>
<?
//Retrieve Variables//
$first=trim(mysql_real_escape_string($_GET['first']));
$last=trim(mysql_real_escape_string($_GET['last']));
$cell=trim(mysql_real_escape_string($_GET['cell']));
$email=trim(mysql_real_escape_string($_GET['email']));
//Make sure all variables submitted//
if($first==""){
die("Enter First Name... please?");
}else if($last==""){
die("Enter Last Name... please?");
}else if($cell==""){
die("Enter Cell Phone... please?");
}else if($email==""){
die("Enter Email... please?");
}else{
//Connect to database//
$username="";
$password="";
$database="";
mysql_connect(localhost,$username,$password)or die("I couldnt connect, sir. By the way, am I being paid for acting like a personal butler?");
mysql_select_db($database)or die("The database you are trying to access is currently unavailable. Curious...");
//Query statement//
$query="INSERT INTO TEST1_contacts VALUES(,$first,$last,$cell,$email)";
mysql_query($query);
$query="SELECT * FROM `TEST1_contacts` WHERE `First_Name`=$first";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num==0){
die("Could not insert data");
}else if($num>1){
$query="SELECT * FROM TEST1_contacts WHERE Last_Name=$last";
$result=mysql_query($query);
$num=mysql_num_rows($result);
if($num==0){
	die("Could not insert data");
}else if($num>1){
	$query="SELECT * FROM TEST1_contacts WHERE Phone_Number=$cell";
	$result=mysql_query($query);
	$num=mysql_num_rows($result);
	if($num==0){
		die("Could not insert data");
	}else if($num>1){
	$query="SELECT * FROM TEST1_contacts WHERE Email=$email";
	$result=mysql_query($query);
	$num=mysql_num_rows($result);
	if($num==0){
		die("Could not insert data");
		}
	}
}
}
}
$i=0;
while($i<$num);
$first=mysql_result($result,$i,"First_Name");
$last=mysql_result($result,$i,"Last_Name");
$cell=mysql_result($result,$i,"Phone_Number");
$email=mysql_result($result,$i,"Email");
echo "Inserted $first $last Cell: $cell Email: $email";
?>

Link to comment
Share on other sites

RRRRGGHHHH.... I'm getting zero... nothing... here's my script...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> Populate Database </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
</HEAD>
<BODY>
  <H1>Add Contact</H1>
  <FORM METHOD="GET" action="post.php">
   <P>First Name</P><input type="text" name="first" size=20 maxlength=50>
   <P>Last Name</P><input type="text" name="last" size=20 maxlength=50>
   <P>Cell Phone</P><input type="text" name="cell" size=20 maxlength=50>
   <P>Email</P><input type="text" name="email" size=20 maxlength=50>
   <INPUT type="hidden"
   <P></P><INPUT type="submit" value="ADD CONTACT">
  </FORM>
</BODY>
</HTML>
<?
//Connect to database//
$username="mekam2_kai";
$password="753159";
$database="mekam2_kai1";
mysql_connect(localhost,$username,$password)or die("I couldnt connect, sir. By the way, am I being paid for acting like a personal butler?");
mysql_select_db($database)or die("The database you are trying to access is currently unavailable. Curious...");
//Retrieve Variables//
$first=trim(mysql_real_escape_string($_GET['first']));
$last=trim(mysql_real_escape_string($_GET['last']));
$cell=trim(mysql_real_escape_string($_GET['cell']));
$email=trim(mysql_real_escape_string($_GET['email']));
//Make sure all variables submitted//
if($first == "") {
die("Enter First Name... please?");
} else if($last == "") {
die("Enter Last Name... please?");
} else if($cell == "") {
die("Enter Cell Phone... please?");
} else if($email == "") {
die("Enter Email... please?");
}else{
//Query statement//
$query="INSERT INTO TEST1_contacts VALUES(,$first,$last,$cell,$email)";
mysql_query($query);
$query="SELECT * FROM TEST1_contacts WHERE First_Name LIKE '$first'";
$result=mysql_query($query);
$num=mysql_num_rows($result) OR die(mysql_error());
if($num==0) {
die("Could not insert data");
} else if($num>1) {
$query="SELECT * FROM TEST1_contacts WHERE Last_Name LIKE '$last'";
$result=mysql_query($query);
$num=mysql_num_rows($result) OR die(mysql_error());
if($num==0) {
	die("Could not insert data");
} else if($num>1) {
	$query="SELECT * FROM TEST1_contacts WHERE Phone_Number LIKE '$cell'";
	$result=mysql_query($query);
	$num=mysql_num_rows($result) OR die(mysql_error());
	if($num==0) {
		die("Could not insert data");
	} else if($num>1) {
		$query="SELECT * FROM TEST1_contacts WHERE Email LIKE '$email'";
		$result=mysql_query($query);
		$num=mysql_num_rows($result) OR die(mysql_error());
		if($num==0) {
			die("Could not insert data");
		}
	}
}
}
}
$i=0;
while($i<$num){
$firstname=mysql_result($result,$i,"First_Name");
$lastname=mysql_result($result,$i,"Last_Name");
$cellphone=mysql_result($result,$i,"Phone_Number");
$emailaddress=mysql_result($result,$i,"Email");
echo "Inserted $firstname $lastname Cell: $cellphone Email: $emailaddress";
++$i;
}
?>

 

 

Link to comment
Share on other sites

try this

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> Populate Database </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
</HEAD>
<BODY>
  <H1>Add Contact</H1>
  <FORM METHOD="GET" action="post.php">
   <P>First Name</P><input type="text" name="first" size=20 maxlength=50>
   <P>Last Name</P><input type="text" name="last" size=20 maxlength=50>
   <P>Cell Phone</P><input type="text" name="cell" size=20 maxlength=50>
   <P>Email</P><input type="text" name="email" size=20 maxlength=50>
   <INPUT type="hidden"
   <P></P><INPUT type="submit" value="ADD CONTACT">
  </FORM>
</BODY>
</HTML>
<?
//Connect to database//
$username="mekam2_kai";
$password="753159";
$database="mekam2_kai1";
mysql_connect(localhost,$username,$password)or die("I couldnt connect, sir. By the way, am I being paid for acting like a personal butler?");
mysql_select_db($database)or die("The database you are trying to access is currently unavailable. Curious...");
//Retrieve Variables//
$first=trim(mysql_real_escape_string($_GET['first']));
$last=trim(mysql_real_escape_string($_GET['last']));
$cell=trim(mysql_real_escape_string($_GET['cell']));
$email=trim(mysql_real_escape_string($_GET['email']));
//Make sure all variables submitted//
if($first == "") {
   die("Enter First Name... please?");
} else if($last == "") {
   die("Enter Last Name... please?");
} else if($cell == "") {
   die("Enter Cell Phone... please?");
} else if($email == "") {
   die("Enter Email... please?");
}else{
//Query statement//
$query="INSERT INTO TEST1_contacts VALUES('$first','$last','$cell','$email')";
mysql_query($query);
$query="SELECT * FROM TEST1_contacts WHERE First_Name = '$first'";
$result=mysql_query($query);
$num=mysql_num_rows($result) OR die(mysql_error());
if($num==0) {
   die("Could not insert data");
} else if($num>1) {
   $query="SELECT * FROM TEST1_contacts WHERE Last_Name = '$last'";
   $result=mysql_query($query);
   $num=mysql_num_rows($result) OR die(mysql_error());
   if($num==0) {
      die("Could not insert data");
   } else if($num>1) {
      $query="SELECT * FROM TEST1_contacts WHERE Phone_Number = '$cell'";
      $result=mysql_query($query);
      $num=mysql_num_rows($result) OR die(mysql_error());
      if($num==0) {
         die("Could not insert data");
      } else if($num>1) {
         $query="SELECT * FROM TEST1_contacts WHERE Email = '$email'";
         $result=mysql_query($query);
         $num=mysql_num_rows($result) OR die(mysql_error());
         if($num==0) {
            die("Could not insert data");
         }
      }
   }
}
}
$i=0;
while($i<$num){
$firstname=mysql_result($result,$i,"First_Name");
$lastname=mysql_result($result,$i,"Last_Name");
$cellphone=mysql_result($result,$i,"Phone_Number");
$emailaddress=mysql_result($result,$i,"Email");
echo "Inserted $firstname $lastname Cell: $cellphone Email: $emailaddress";
++$i;
}
?>

Link to comment
Share on other sites

Well, I've got your code re-written a bit, if it works happy days, if not it might give you a decent error, try this;

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE> Populate Database </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
</HEAD>
<BODY>
  <H1>Add Contact</H1>
  <FORM METHOD="GET" action="post.php">
   <P>First Name</P><input type="text" name="first" size=20 maxlength=50>
   <P>Last Name</P><input type="text" name="last" size=20 maxlength=50>
   <P>Cell Phone</P><input type="text" name="cell" size=20 maxlength=50>
   <P>Email</P><input type="text" name="email" size=20 maxlength=50>
   <INPUT type="hidden"
   <P></P><INPUT type="submit" value="ADD CONTACT">
  </FORM>
</BODY>
</HTML>
<?php
//Retrieve Variables//
$first = $_GET['first'];
$last = $_GET['last'];
$cell = $_GET['cell'];
$email = $_GET['email'];

//Make sure all variables submitted//
if(empty($first)) {
die("Enter First Name... please?");
} else if(empty($last)) {
die("Enter Last Name... please?");
} else if(empty($cell)) {
die("Enter Cell Phone... please?");
} else if(empty($email)) {
die("Enter Email... please?");
} else {

//Connect to database//
$username = "mekam2_kai";
$password = "753159";
$database = "mekam2_kai1";
mysql_connect('localhost',$username,$password)or die("I couldnt connect, sir. By the way, am I being paid for acting like a personal butler?");
mysql_select_db($database) or die("The database you are trying to access is currently unavailable. Curious...");

//Query statement//
$query = "INSERT INTO TEST1_contacts VALUES(NULL,'$first','$last','$cell','$email')";
mysql_query($query) or die(mysql_error());
$query = "SELECT * FROM `TEST1_contacts` WHERE `First_Name`='$first'";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
if(!$num) {
	die("Could not insert data");
} else if($num>=1) {
	$query = "SELECT * FROM TEST1_contacts WHERE Last_Name='$last'";
	$result = mysql_query($query) or die(mysql_error());
	$num = mysql_num_rows($result);
	if(!$num) {
		die("Could not insert data");
	} else if($num>=1) {
		$query = "SELECT * FROM TEST1_contacts WHERE Phone_Number='$cell'";
		$result = mysql_query($query) or die(mysql_error());
		$num = mysql_num_rows($result);
		if(!$num) {
			die("Could not insert data");
		} else if($num>=1) {
			$query = "SELECT * FROM TEST1_contacts WHERE Email='$email'";
			$result = mysql_query($query) or die(mysql_error());
			$num = mysql_num_rows($result);
			if(!$num){
				die("Could not insert data");
			} else {
				for($i=0;$i<$num;$i++) {
					$first = mysql_result($result,$i,"First_Name");
					$last = mysql_result($result,$i,"Last_Name");
					$cell = mysql_result($result,$i,"Phone_Number");
					$email = mysql_result($result,$i,"Email");
					echo "Inserted $first $last Cell: $cell Email: $email";
				}
			}
		}
	}
}
}
?>

Link to comment
Share on other sites

There were a few problems, localhost not wrapped in quotes, suppresing the select database error (so could run the script without a database selected), variables not wrapped with quotes in queries, setting id to NULL (I'm guessing it's id), checking the count is greater than one rather that greater than or equal and a very strange syntax for a while loop at the end!

Link to comment
Share on other sites

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.