View Full Version : Help please
blind--angel
02-20-2003, 03:20 AM
When i try to execute this php script i get an error
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\apache\htdocs\view.php on line 23
Any ideas???
<html>
<body>
</body>
</html>
<?
$host = "localhost";
$login_name = "user";
$password = "";
mysql_connect("$host","$login_name","$password");
mysql_select_db("test1") or die("Could not select database");
$query = "SELECT * FROM tablename";
$result = mysql_query($query);
While( $rows = mysql_fetch_array($result) ) {
$name = $rows['First_name'];
$email = $rows['Email'];
echo("You can email $name at $email <br>");
}
?>
tonto
02-20-2003, 03:27 AM
there is something wrong with ur sql statment.
check the tablename if its correct.
tonto
blind--angel
02-20-2003, 03:47 AM
lol... woops i don't even think i put in a table... tahnks for pointing that out.
transmothra
02-20-2003, 04:01 AM
yeah, check tablename, but also you might want to put that stuff in between the <body> (or at least the <html>) tags.
heh i also ave problems with that kinda stuff, so when i get a error, i alwaysadd this little piece of code, and it will be described more clearleh
... or die (mysql_error())
blind--angel
02-20-2003, 11:23 PM
thanks for the help...
New problem... slightly diffrenet script...
when i use this script...
<?
$host = "localhost";
$login_name = "user";
$password = "";
MySQL_connect("$host","$login_name","$password");
MySQL_select_db("test1") or die("Could not select database");
$name = $_POST['Name'];
$email = $_POST['Email'];
$comments = $_POST['Comments'];
?>
<html>
<body>
<form action="<? $PHP_SELF ?>" method="post">
<input type="hidden" name="confirm" value="yes">
<input type="hidden" type=test value="<? echo "$name" ?>" name="confirmedEmail" size="30">
<input type="hidden" type=test value="<? echo "$email" ?>" name="confirmedName" size="15">
<input type="hidden" type=test value="<? echo "$comments" ?>" name="confirmedComments" size="30">
Is this data correct?<br>
Name: <? echo "$name" ?><br>
Email: <? echo "$email" ?><br>
Comments: <? echo "$comments" ?><br>
<input type="submit" name="submit" value="submit">
</form>
<a href="view.php">view.php</a>
</body>
</html>
<?
if ( $_POST['confirm'] == "yes" ) {
$cname = $_POST['confirmedName'];
$cemail = $_POST['confirmedEmail'];
$ccomments = $_POST['confirmedComments'];
$sql = "INSERT INTO guestbook VALUES ('$cname','$cemail','$ccomments')";
$result = mysql_query($sql);
echo "Data has been entered";
MySQL_close();
}
else {}
?>
i always get an error...
Notice: Undefined index: confirm in c:\apache\htdocs\confirm.php on line 47
and i don't know why.
this is just a simple comformation book for a simple guestbook and i always have often have this problem with scripts i make. any ideas?
thanks in advance
jollyfactory
02-21-2003, 05:41 AM
I tested your code on my local machine and it executed perfectly.
Try again as I know there is no syntax problem with your code :)
scoutt
02-21-2003, 09:22 AM
Originally posted by blind--angel
i always get an error...
Notice: Undefined index: confirm in c:\apache\htdocs\confirm.php on line 47
and i don't know why.
This happens becasue in the php.ini file you have it set to error on warnings. you want to uncomment this line in the ini file
error_reporting = E_ALL & ~E_NOTICE
or if you don't have access to this file then you can set it in the code
error_reporting(E_ALL ^ E_NOTICE);
blind--angel
02-21-2003, 05:43 PM
what do u mean uncomment
scoutt
02-21-2003, 05:48 PM
a comment has a # in front of it.
just delete the # that is in front of it.
blind--angel
02-21-2003, 06:12 PM
hmmm... this was the closest thing i found in the php.ini file
;error_reporting=E_ALL & ~E_NOTICE
but there isn't a # in fron of it
scoutt
02-21-2003, 09:30 PM
hehe sorry, it is the ; that is the comment. jsu tdelete that instead. :P
blind--angel
02-21-2003, 09:46 PM
ok thanks.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.