Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

I am getting rruors in code given belwo:pls help

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

I am getting rruors in code given belwo:pls help

Postby vikaspa » Tue Aug 06, 2002 6:43 pm

I am getting following errors when i run subtopic.php

YEs I am trying to get output on same form once user clicks on Submit button !!

No doubt several valuable ways were suggested by you ..still I have problem

I am giving complete code for this.

"$select" is a variable passed by another program.

Can anyone help me...

Connected to database
select * from forum where main_id=Resource id #1
Warning: Supplied argument is not a valid MySQL result resource in c:\program files\nusphere\apache\nsdocs\vikas\subtopic.php on line 26

Warning: Supplied argument is not a valid MySQL result resource in c:\program files\nusphere\apache\nsdocs\vikas\subtopic.php on line 27

Warning: Supplied argument is not a valid MySQL result resource in c:\program files\nusphere\apache\nsdocs\vikas\subtopic.php on line 29

Warning: Supplied argument is not a valid MySQL result resource in c:\program files\nusphere\apache\nsdocs\vikas\subtopic.php on line 37


<?php

$datahost = "localhost";
global $datauser;
$datauser = "vikas";
global $datadb ;
$datadb = "vikas";
global $datapass;
$datapass = "vpass";
global $sql_link;
global $serialno;
$sql_link=mysql_connect($datahost, $datauser, $datapass) ;
if ($sql_link == true)
{
print "Connected to database <br>";
}
else
{
print "Connection Failed <br>";
}
$link=mysql_select_db($datadb, $sql_link);
$query="select * from forum where main_id=$select";
print $query;
print $sql_link;
$result=mysql_query($query, $sql_link);
$fields=mysql_num_fields($result);
$fnooftopics=mysql_num_rows($result);
// print "\n $fnooftopics";
while ($rows=mysql_fetch_array($result))
{
$fmainid= $rows["main_id"];
$ftopic= $rows["topic"];
}
$querysubtopic="select * from forum where main_id=$select and sub_id <> 0";
// print $querysubtopic;
$resultsubtopic=mysql_query($querysubtopic, $sql_link);
$fnoofresponses = mysql_num_rows($resultsubtopic);
ob_start();
?>
<?php
function adddetail()
{
print "this is adddetail";
print "<tr><td align=center><font face=verdana size=2 color=red>Buyers details accepted succesfully</font></td></tr>";
Header("Location:subtopic.php");
exit;
ob_flush();
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">

<?php

?>
<?
if (isset($Submit))
{
$messgae="fsdfsdfsdfsdf";
}
?>
<script language="JavaScript">

function set(obj,mess) {
alert(mess);
// obj.select();
// obj.focus();
}

function empty(x) { if (x.length > 0) return false; else return true; }

function stripSpaces(x) {

while (x.substring(0,1) == ' ')
x = x.substring(1);
return x;
}

function validateform(obj)
{
if (empty(stripSpaces(obj.fuser.value)))
{
set(obj.name,"Please Enter User name...You cannot leave it blank");
return false;
}
if (empty(stripSpaces(obj.ftitle.value)))
{
set(obj.fuser,"Please Enter Title for this .....You cannot leave it blank");
return false;
}
if (empty(stripSpaces(obj.fdetail.value)))
{
set(obj.fuser,"Please Enter your comments on this topic .....You cannot leave it blank");
return false;
}
}
</script>
<form name="subtopicform" method="post" action="<?echo basename($PHP_SELF)?>" onSubmit="return validateform(subtopicform);">

<table width="780" border="0" cellpadding="0" cellspacing="0" align="center" bordercolor="#00FFFF">
<tr>
<td width="167" height="30" valign="middle" align="center">
<div align="right"><b><font color="#000099" face="Verdana, Arial, Helvetica, sans-serif">Topic
: </font></b></div>
</td>
<td valign="middle" width="406" bgcolor="#CCCCCC" align="left" >
<div align="left"><font color="#000099" face="Verdana, Arial, Helvetica, sans-serif">
<?php print $ftopic ?>
</font></div>
</td>
<td valign="top" colspan="2">No.of Responses
<?php print $fnoofresponses ?>
</td>
<td width="6"></td>
<td width="13"></td>
</tr>
<tr>
<td height="29" valign="middle" align="right" nowrap>
<div align="right"><font color="#000099" face="Verdana, Arial, Helvetica, sans-serif"><b>User
Name :</b></font></div>
</td>
<td valign="middle" align="left" bgcolor="#FFFFFF">
<input type="text" name="fuser" size="50" maxlength="40">
</td>
<td width="123"></td>
<td width="65"></td>
<td></td>
<td></td>
</tr>
<tr>
<td valign="middle" height="39" align="right"><font color="#000099" face="Verdana, Arial, Helvetica, sans-serif"><b>Title
: </b></font></td>
<td valign="middle" bgcolor="#ECFBF7" align="left" bordercolor="#CCCCCC">
<input type="text" name="ftitle" size="70" maxlength="65">
</td>
<td background=" #000099"></td>
<td background=" #000099"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="25" valign="bottom" align="right" nowrap>
<div align="right"><font color="#000099" face="Verdana, Arial, Helvetica, sans-serif"><b>Enter
Details :</b></font></div>
</td>
<td colspan="2" rowspan="2" valign="bottom">
<textarea name="fdetail" cols="70" rows="12"></textarea>
</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="198"></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="33"></td>
<td valign="middle" align="center">
<input type="submit" name="Submit" value="Submit" >
</td>
<td colspan="3" valign="top"><?php print $message ?></td>
<td></td>
</tr>
</table>
</form>

</body>
</html>
------------------------------------------------------------------------

The table Lay out :
Field Type Attributes Null Default Extra
main_id int(6) Yes
sub_id int(6) Yes
topic varchar(50) Yes
detail mediumtext No
user varchar(50) Yes
email varchar(25) Yes
dt datetime No 0000-00-00 00:00:00
:cry:
vikaspa
New php-forum User
New php-forum User
 
Posts: 21
Joined: Wed Jun 19, 2002 10:03 pm

Postby Jay » Tue Aug 06, 2002 7:19 pm

Are you experiencing any particular problem? You can use variables on the same form quite simply by setting the form action to itself ($PHP_SELF), and using the variables as normal.

However, if the form hasn't been submitted then there would be no variables. In this case I personally use the '@' which hides any errors generated (for instance, the lack of a variable due to the form not being submitted).
Jay
 

Postby DoppyNL » Tue Aug 06, 2002 11:03 pm

the query you printed can't be executed correctly by mySQL because it has an error in it:
Code: Select all
select * from forum where main_id=Resource id #1

but main_id is NOT a string, its an integer.


when I submit the form to itself I usally do this little trick: (html)
Code: Select all
<form action="page.php" method="post" enctype="multipart/form-data" target="_top">
<input type="hidden" name="formsubmitted" value="1">


This way you can check very simple if the form is submitted or not.
just check it this way:
Code: Select all
if (isset($_POST['formsubmitted']))
{
    print('form is submitted');
}
else
    print('form is not submitted');

ofcourse you can also do this with you're submit button wich is usally called "submit"

note: in older versions of PHP "$_POST" must be "$HTTP_POST_VARS"

Greetz Daan
DoppyNL
 


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.