Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-31-2007, 03:07 PM
lucky-girl's Avatar   
lucky-girl lucky-girl is offline
Newbie
 
Join Date: Dec 2007
Age: 23
Posts: 27
Rep Power: 4
lucky-girl is on a distinguished road
Default help on simple guestbook script

hi everyone

as a begginer i'm trying to apply a simple guest book tutorial but a problem

everything was fine before starting with mysql

i created 3 files:

guest.php
add.php
view.php

in the add.php file, an error in the query

is it right?

PHP Code:

$sql
"INSERT INTO $tbl_guest(id, guestname, gender, palce, email, title, comment)VALUES ('$id','$guestname', '$gender', '$place', '$email' ,'$title', '$comment')"// the error is here 

$result=mysql_query($sql);

if(
$result){
echo 
"Successful";
echo 
"<BR>";
echo 
"<a href='view.php'>View guestbook</a>"guestbook page
}

else {
echo 
"ERROR";


and an error on view.php file

PHP Code:
 $result=mysql_query($sql);

while (
$rows mysql_fetch_array($result)) // the error is here 


PHP Code:

$result=mysql_query($sql);

while ($rows = mysql_fetch_array($result)) // the error is here 

{
?>

    <table border="1" width="50%" id="table1" height="145" align="center">
    
        <tr>
            <td rowspan="4">
            <p align="left" dir="ltr">Comment Title:
            <? echo $rows['title']; ?>
         
        ?>
              </p>
            <p align="left" dir="ltr">Comment: <br>
        <? echo $rows['comment']; ?>
        
        </p>
            <p align="left" dir="ltr">&nbsp;</p>
            <p align="left" dir="ltr">&nbsp;&nbsp; </td>
            <td width="165">
            <p align="center">
            <font color="#FF0000" size="5" face="Berlin Sans FB Demi">guest name</font>
            </p>
            <p align="center">
            <? echo $rows['guestname']; ?>
            </td>
        </tr>
        <tr>
            <td width="165" align="left">
            <p dir="ltr"> <font color ="red"> my place: </font></p>
            <? echo $rows['place']; ?>
            </td>
        </tr>
        <tr>
            <td width="165" align="left">
            <p dir="ltr">gender : </p>
            <? echo $rows['gender']; ?>
            </td>
        </tr>
        <tr>
        <td width="165" align="left">
            <p dir="ltr">email: </p>
            
  <? echo $rows['email']; ?>

        </td>
        </tr>
    </table>
    
    <?
}
mysql_close(); 
?>
i think i'm writing the code in a wrong way
__________________
begginer programmer needs the help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 12-31-2007, 03:35 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

In add.php change
PHP Code:
$result=mysql_query($sql); 
To
PHP Code:
$result=mysql_query($sql) or die(mysql_error()); 
That will give you more information regarding your error.


As for view.php:
PHP Code:
while ($rows mysql_fetch_array($result)) 
appears to be fine, as does the rest of your code below that. What does the exact error say? What does your query in view.php look like? Try adding the
PHP Code:
or die(mysql_error()); 
after that query too.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 12-31-2007, 03:46 PM
penkomitev penkomitev is offline
Learning Programmer
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 30
Rep Power: 4
penkomitev is on a distinguished road
Send a message via ICQ to penkomitev Send a message via Skype™ to penkomitev
Default

On first look, I see ' ', with a field of type INT. So change this:
VALUES ('$id') with this VALUES ($id).
When you have value of type INT, you should not use ''. After that, if there are still problems, make what Sidewinder said. Happy new year .
__________________
You can visit something interesting HERE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-31-2007, 04:18 PM
lucky-girl's Avatar   
lucky-girl lucky-girl is offline
Newbie
 
Join Date: Dec 2007
Age: 23
Posts: 27
Rep Power: 4
lucky-girl is on a distinguished road
Default

thank u Sidewinder & penkomitev for your quick answer

i applyed what u said Sidewinder,

everythig ok with add.php file

but the error still there with view.php file

it says

PHP Code:
  WarningSupplied argument is not a valid MySQL result resource in c:apachehtdocsguest_bookview.php on line 29 
and this is line 29

PHP Code:
  while ($rows mysql_fetch_array($result)) 
__________________
begginer programmer needs the help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-31-2007, 04:22 PM
lucky-girl's Avatar   
lucky-girl lucky-girl is offline
Newbie
 
Join Date: Dec 2007
Age: 23
Posts: 27
Rep Power: 4
lucky-girl is on a distinguished road
Default

Quote:
Originally Posted by penkomitev View Post
On first look, I see ' ', with a field of type INT. So change this:
VALUES ('$id') with this VALUES ($id).
When you have value of type INT, you should not use ''. After that, if there are still problems, make what Sidewinder said. Happy new year .
hi penkomitev,

when i remove the ' ', its appear an error but when i keep it like that its fine, is it important to remove it from INT type?
__________________
begginer programmer needs the help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 12-31-2007, 05:22 PM
penkomitev penkomitev is offline
Learning Programmer
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 30
Rep Power: 4
penkomitev is on a distinguished road
Send a message via ICQ to penkomitev Send a message via Skype™ to penkomitev
Default

Well, it is not used with INT. But are you sure your field is INT?(Well it may be silly question, but let me to ask everything) From the error you receive, I understand your query is bad. So make: print $sql and try to execute the query trough phpMyAdmin or the one you are using. Look at the error, phpMyAdmin return and you will understand what the problem is. Remebmer from me:

Code:
Warning: Supplied argument is not a valid MySQL result resource in c:apachehtdocsguest_bookview.php on line N
in most of cases means bad query.

Happy new year to all of you, who are GMT+1 or higher. For the others, have a little bit more patience .
__________________
You can visit something interesting HERE

Last edited by penkomitev; 12-31-2007 at 06:38 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 12-31-2007, 05:40 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Quote:
Originally Posted by lucky-girl View Post
thank u Sidewinder & penkomitev for your quick answer

i applyed what u said Sidewinder,

everythig ok with add.php file

but the error still there with view.php file

it says

PHP Code:
  WarningSupplied argument is not a valid MySQL result resource in c:apachehtdocsguest_bookview.php on line 29 
and this is line 29

PHP Code:
  while ($rows mysql_fetch_array($result)) 
Just because thats where the error is thrown, doesn't mean thats where the error originates. $result is the return value of a mysql query. Do you have a query? I'm almost certain thats where the error is...
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-01-2008, 03:48 PM
lucky-girl's Avatar   
lucky-girl lucky-girl is offline
Newbie
 
Join Date: Dec 2007
Age: 23
Posts: 27
Rep Power: 4
lucky-girl is on a distinguished road
Default

hi penkomitev , Sidewinder & happy new year

this is the sql query

PHP Code:
  SELECT FROM `tbl_guestWHERE 1 LIMIT 030 
i execute the query trough phpMyAdmin and everything is ok

it show the form data from guest.php file

still the problem with the query ?
__________________
begginer programmer needs the help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-01-2008, 04:21 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

Quote:
Originally Posted by lucky-girl View Post
still the problem with the query ?
Yes, your WHERE clause makes no sense. A WHERE clause is used as a conditional, meaning you need to use an operator so the SELECT statement can evaluate its 'truth.' Have a look here for more information on the SQL WHERE Clause
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall

Last edited by John; 01-01-2008 at 04:24 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-01-2008, 04:22 PM
penkomitev penkomitev is offline
Learning Programmer
 
Join Date: Dec 2007
Location: Plovdiv, Bulgaria
Age: 16
Posts: 30
Rep Power: 4
penkomitev is on a distinguished road
Send a message via ICQ to penkomitev Send a message via Skype™ to penkomitev
Default

Both with Sidewinder were talking about printing
Code:
$sql= "INSERT INTO $tbl_guest(id, guestname, gender, palce, email, title, comment)VALUES ('$id','$guestname', '$gender', '$place', '$email' ,'$title', '$comment')"; // the error is here
When you execute this one, you will see if it works and what data it returns, and the further idea what to do will come suddenly .
__________________
You can visit something interesting HERE

Last edited by penkomitev; 01-01-2008 at 04:36 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump