Jump to content


Photo

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link reso


  • Please log in to reply
7 replies to this topic

#1 dingus

dingus
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 03 July 2006 - 06:07 AM

hello this is my second post in 24 hours but i am only new to php so please bare with me

i am trying to do a simple page to enter data in to a database

i cant find an error but i keep getting the message

"Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\norrisbak\test\admin.php on line 101"

i copy of my code is as follows if some one coukld please help me find a sulution it would be greatly appriceated

<?
/*
this section is setting the veriables as they where typed above
*/
$Sub_Category = $_POST['Sub_Category'];
$Business_name = $_POST['Business_name'];
$Description = $_POST['Description'];
$Ph = $_POST['Ph'];
$Fax = $_POST['Fax'];
$Email = $_POST['Email'];
$Category = $_POST['Category'];
/*
print "$Sub_Category, $Business_name, $Description, $Ph, $Fax ,$Email  , $Category ";
*/

/*
this following section should load the data in to the table
*/

	$query =
		"INSERT INTO table1 
		VALUES ('$Category', '$Sub_Category', '$Business_name',
				'$Description', '$Ph', '$Fax', '$Email')";

				
				

	$result = mysql_query($query);


	// Determine the number of enterys
	$number =  mysql_affected_rows ($result); // <<<<<<<this is line 101
	/*
	if ($number == 0) {
 	  print "Sorry, there were no records matching those criteria";
	} else {
	   // Print the employee names
	   for($i=0; $i<$number; $i++){
 	   $Code = mysql_result($result,$i,"Code");
	   $Error_Message = mysql_result($result,$i, "Error_Message");
	        print "$Code $Error_Message";
  		 }
	}
*/
?>

Best Mobile Store i ever used.

#2 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 03 July 2006 - 06:32 AM

Edit: Misread it, sorry.
PHP is my friend (=

#3 dingus

dingus
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 03 July 2006 - 07:05 AM

after entering the new infomation i am still experenceing the same error

if there any other idears?

Best Mobile Store i ever used.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 July 2006 - 02:51 PM

Hava a read of the FAQ on this here:
http://www.phpfreaks...ic,95376.0.html

#5 dingus

dingus
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 05 July 2006 - 04:13 AM

i know it probably looks realy silly posting again but i still cant get it right i am realy new to php ( only been codeing php for about 3 days now

the page i am working on is located here

http://149.135.37.22.../test/admin.php

and a copy of the php code can be found here

http://149.135.37.22.../test/admin.txt

if some one could please tell me what i am doing wrong it would be realy good because i kinda need to fix it realy soon thanks again for helping
Best Mobile Store i ever used.

#6 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 05 July 2006 - 04:44 AM

Please post your code here. The URL you gave results in a 404 - page not found.

Ken

#7 dingus

dingus
  • Members
  • PipPipPip
  • Advanced Member
  • 148 posts

Posted 05 July 2006 - 08:18 AM

ok im sorry about that i wasnt aware a compleate copy of the code sance the database password is below

<!-- all this stuff generating the admin boxes -->
<form NAME="search" action="admin.php" method="post">

Sub_Category (Eg. new dealers, second hand dealers, etc.) <input type="text" name="Sub_Category"><br>
Business_name <input type="text" name="Business_name"><br>
Description <input type="text" name="Description"><br>
Phone Number <input type="text" name="Ph"><br>
Fax <input type="text" name="Fax"><br>
E-mail <input type="text" name="Email"><br>
<!--in short this section allows you to set the aria you want the data to be added under-->
<select name="Category">
<option value="Featured Listings">Featured Listings</option>
<option value="Home Repairs">Home Repairs</option>
<option value="Pets and Animals">Pets and Animals</option>
<option value="Medical Professionals">Medical Professionals</option>
<option value="Legal professionals">Legal professionals</option>
<option value="Tax and Accounting">Tax and Accounting</option>
<option value="Restaurants and Eateries">Restaurants and Eateries</option>
<option value="Computing">Computing</option>
<option value="Professional Drivers">Professional Drivers</option>
<option value="Adult Services">Adult Services</option>
<option value="Real Estate">Real Estate</option>
<option value="Hair and Beauty">Hair and Beauty</option>
<option value="Telecommunications">Telecommunications</option>
<option value="Car Sales">Car Sales</option>
<option value="General Retail">General Retail</option>
<option value="Car repair">Car repair</option>
<option value="Entertainment">Entertainment</option>
<option value="Accommodation">Accommodation</option>
<option value="Pubs and Clubs">Pubs and Clubs</option>
</select>
<input type="submit" value="submit" name="submit">
</form><p>


<?
// database infomationg
// this section setst daatbase veriables
$hostName = "127.0.0.1";
$userName = "root";
$password = "";
$dbName = "xsydney";
$TableName = "table1";

// this section uses the code above to connect to the database
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");

mysql_select_db($dbName) or die("Unable to select database $dbName");

?>


<?
/*
this section is setting the veriables as they where typed above
*/
$Category = $_POST['Category'];
$Sub_Category = $_POST['Sub_Category'];
$Business_name = $_POST['Business_name'];
$Description = $_POST['Description'];
$Ph = $_POST['phone'];
$Fax = $_POST['Fax'];
$Email = $_POST['Email'];

print "$Sub_Category, $Business_name, $Description, $Ph, $Fax ,$Email  , $Category ";


/*
this following section should load the data in to the table
*/

$Link = mysql_connect ($hostName,$userName,$Password);

$Query = "insert into customer values ($Category, '$Sub_Category','$Business_name',$Ph, $Fax,'$email' )";


$result = mysql_db_query ($DBName, $Query, $Link) or die ("Insert failed");


print ("<h1>A customer has been added, Thankyou</h1>");



// Create a table


print ("<table border='1' width=\"50%\" cellspacing=2 cellpadding=2 align='center'>");
print ("<tr align=center valign=top>\n");
print ("<td align=center valign=top>cust_id</td>\n");
print ("<td align=center valign=top>cust_name</td>\n");
print ("<td align=center valign=top>cust_street</td>\n");
print ("<td align=center valign=top>cust_town</td>\n");
print ("<td align=center valign=top>cust_state</td>\n");
print ("<td align=center valign=top>phone</td>\n");
print ("<td align=center valign=top>email</td>\n");
print ("</tr>\n");

// Student details entered.


		print ("<tr align='center' valign='top'>\n");
		print ("<td align='center' valign='top'>[0]</td>\n");
		print ("<td align='center' valign='top'>[1]</td>\n");
		print ("<td align='center' valign='top'>[2]</td>\n");
		print ("<td align='center' valign='top'>[3]</td>\n");
		print ("<td align='center' valign='top'>[4]</td>\n");
		print ("<td align='center' valign='top'>[5]</td>\n");
		print ("<td align='center' valign='top'>[6]</td>\n");
		print ("</tr>\n");
	
mysql_close ($Link);
print ("</table>\n");
?>
<h1><a href="index.html">Home</a></h1>				
<?				
/*
	$result = mysql_query($query);


	// Determine the number of enterys
	
	
	if(mysql_affected_rows($result)) {
  $number =  mysql_affected_rows($result);
}
	/*
	if ($number == 0) {
 	  print "Sorry, there were no records matching those criteria";
	} else {
	   // Print the employee names
	   for($i=0; $i<$number; $i++){
 	   $Code = mysql_result($result,$i,"Code");
	   $Error_Message = mysql_result($result,$i, "Error_Message");
	        print "$Code $Error_Message";
  		 }
	}
*/
?>


<?
/*
}
  else
{
   print("Wrong password");
}
*/
?>

Best Mobile Store i ever used.

#8 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 05 July 2006 - 08:30 AM

insert into customer values ($Category, '$Sub_Category','$Business_name',$Ph, $Fax,'$email' )

if you use the word values in your query it expects a list of fields to put the "values" into.

simple answer...take out the word values

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users