[PHP:OOP]Pagina met (werkend) form en class is blanco

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Ik heb een classje geschreven voor wat basisquerys uit te voeren en dat zit samen met een html form dat ik getest heb en blijkt te werken. Als ik die pagina echter bezoek is die blanco. Hier is de class. What's wrong?

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
if($submit){

class sql{
 var $statement
 var $result
 var $query
 var $server

$this->server = mysql_connect("localhost", "", "");
mysql_select_db("", $server);

function query($statement){
 $this->query = mysql_query($statement);
}
function fetch_row($statement){
 $this->query = mysql_query($statement);
 $this->result = mysql_fetch_row($query);
}
}

if($type = "2"){

$query->fetch_row("SELECT fid from forums where category_id = $category_id");
$query->query(Update forums set fid = fid+1  and category_id=category_id +1 where fid > $result['1'])
$query->query(INSERT INTO forums (fid, category_id, name, description, lastpost, lpuser, lptime) Values(NULL, '$name', '$description', '','','',''));
}

if($type = "1"){

//category_id is the id of the forum parent that the admin selects
$query_forum = new sql("SELECT fid from forums where category_id = $category_id +1")
$result = $query_forum->fetch_row();

//if there is a category after the parent category of the forum we are going to add set the forum ids of that category all + 1 so tehre is room to fint a forum in
if($result['1']){
$query->query(Update forums set fid = fid + 1 where fid > ($result['1'] - 1));
}

$query->query(INSERT INTO forums (fid, name, description, lastpost, lpuser, lptime) Values(NULL, '$name', '$description', '','','',''));

}
}

Acties:
  • 0 Henk 'm!

  • Glimi
  • Registratie: Augustus 2000
  • Niet online

Glimi

Designer Drugs

(overleden)
PHP:
1
2
3
4
query->query(Update forums set fid = fid+1  and category_id=category_id +1 where fid > $result['1']) 
$query->query(INSERT INTO forums (fid, category_id, name, description, lastpost, lpuser, lptime) Values(NULL, '$name', '$description', '','','',''));
$query->query(Update forums set fid = fid + 1 where fid > ($result['1'] - 1)); 
$query->query(INSERT INTO forums (fid, name, description, lastpost, lpuser, lptime) Values(NULL, '$name', '$description', '','','',''));

Hier zit in ieder geval een fout in. Wat denk je zelf, als je met syntaxhighlighting er naar kijkt

tip: Strings worden rood weergegeven..

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Ja weet ik maar ik denk niet dat het daar aan ligt, ik heb ze tussen ""'jes gezet en de pagina is nog steeds blanco.

Acties:
  • 0 Henk 'm!

  • Glimi
  • Registratie: Augustus 2000
  • Niet online

Glimi

Designer Drugs

(overleden)
Waar in de code staat iets dat op het scherm gaat komen dan :?

Acties:
  • 0 Henk 'm!

  • Ericston
  • Registratie: Maart 2001
  • Laatst online: 23-06 23:17
• Je class wordt pas gedeclareerd als $submit true is.
edit:
Dat is het natuurlijk niet.

• Ik zie nergens print of echo staan. (zoals Glimi zei)
edit:
Hm, misschien heb je het ook wel weggelaten, net als het instantiëren (is dat een woord?) van $query. :)

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
ja, der staat nog een heel form voor, maar dat werkt normaal, dus normaal zou je dat form moeten zien omdat het een html form is maar het verschijnt ook niet.

Acties:
  • 0 Henk 'm!

  • Daspeed
  • Registratie: Maart 2001
  • Laatst online: 16:42
if($type = "2")
moet dat niet met dubbel == zijn?

Acties:
  • 0 Henk 'm!

Verwijderd

==

Blanco pagina is in mijn (zeer beperkte) ervaring ofwel = / == , "", () of {}...
En == is al fout, zie hierboven

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
de class is nu:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class sql{
 var $statement;
 var $result;
 var $query;
 var $server;

$this->server = mysql_connect("localhost", "", "");
mysql_select_db("", $server);

function query($statement){
 $this->query = mysql_query($statement);
}
function fetch_row($statement){
 $this->query = mysql_query($statement);
 $this->result = mysql_fetch_row($query);
}
}
en werkt nog steeds niet, btw dit is rest van pagina:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
$query = new sql;
<html>
<head>
<title>Test for adding forums.</title>
</head>
<body>
 <form action="AddForum.php" method="post" enctype="multipart/form-data">
   <input type="hidden" name="submit" value="yes">
<div align="center">
  <center>
  <table border="0" cellspacing="0" width="812" height="1">
    <tr>
      <td width="808" colspan="2" height="21" bgcolor="#FF6600" style="border: 1 solid #000000">
        <p align="center"><b>&nbsp;--{Submit a forum}--</b></td>
    </tr>
    <tr>
      <td width="404" align="right" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000">
   Forum name:&nbsp;</td>
      <td width="404" valign="top" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000; border-right: 1 solid #000000"> <input type="text" name="name"></td>
    </tr>
<tr>
      <td width="404" align="right" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000">
   Forum description:&nbsp;</td>
      <td width="404" valign="top" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000; border-right: 1 solid #000000"> <input type="text" name="description"></td>
    </tr>
   <tr>
      <td width="404" align="right" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000">
Car medal:&nbsp;</td>
      <td width="404" valign="top" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000; border-right: 1 solid #000000"><select name="type">
<option value="1"> Forum </option>
<option value="2"> Category </option>
</select></td>
    </tr>
<tr>
      <td width="404" align="right" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000">
Select parent:&nbsp;</td>
      <td width="404" valign="top" height="23" bgcolor="#FF9933" style="border-left: 1 solid #000000; border-right: 1 solid #000000">

<select name="category_id">
<?
     while ($record = $query->fetch_row("SELECT * FROM forums")) { 
      $fid = $record["fid"];      
      $name = $record["name"]; 
echo"<option value=$fid>$name </option>"; }
 ?>
</select>
</td>
    </tr>
    
    <tr>
    <td width="808" colspan="2" height="21" bgcolor="#FF6600" style="border: 1 solid #000000">
      <p align="center">
   <input type="submit" name="submit" value="submit">
    </td>
  </tr>
  <tr>
    <td width="808" colspan="2" height="21">
      <p align="center"><font size="2">Powered by PHPLive Scripts</font></td>
  </tr>
  </table>
</div>
</form>
</body>
</html>

<?
if($submit){

if($type == "2"){

$query->fetch_row("SELECT fid from forums where category_id = $category_id");
$query->query("Update forums set fid = fid+1  and category_id=category_id +1 where fid > $result['1']");
$query->query("INSERT INTO forums (fid, category_id, name, description, lastpost, lpuser, lptime) Values(NULL, '$name', '$description', '','','','')");
}

if($type == "1"){

//category_id is the id of the forum parent that the admin selects
$query_forum = new sql("SELECT fid from forums where category_id = $category_id +1");
$result = $query_forum->fetch_row();
//if there is a category after the parent category of the forum we are going to add set the forum ids of that category all + 1 so tehre is room to fint a forum in

if($result['1']){
$query->query("Update forums set fid = fid + 1 where fid > ($result['1'] - 1)");
}

$query->query("INSERT INTO forums (fid, name, description, lastpost, lpuser, lptime) Values(NULL, '$name', '$description', '','','','')");

}
}

Acties:
  • 0 Henk 'm!

  • LuCarD
  • Registratie: Januari 2000
  • Niet online

LuCarD

Certified BUFH

Je class is niet goed gedefineerd.

Je mist de constructor ( http://www.php.net/manual/nl/language.oop.php )
Je mist start tag van PHP bij $query = new sql;
en je hebt de Quickstart FAQ gemist

hth

Programmer - an organism that turns coffee into software.

Pagina: 1