Current location: Hot Scripts Forums » Programming Languages » PHP » More inserting problems


More inserting problems

Reply
  #1 (permalink)  
Old 06-15-03, 01:33 PM
Psybadek Psybadek is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Florida
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
More inserting problems

Ok, heres my problem.

Im working on the commenting system now on my news script.

And it inserts the data.. but in the newsid feild it wont insert the right id for the particular news.

heres the db structure.

PHP Code:

CREATE TABLE al_comments (

  
id int(8NOT NULL auto_increment,
  
newsid int(8NOT NULL default '0',
  
author varchar(255NOT NULL default '',
  
date varchar(255NOT NULL default '',
  
comment text NOT NULL,
  
PRIMARY KEY  (id)
TYPE=MyISAM
comment.php
PHP Code:

<?

/*
news.php
ALbert.News
Version 1.0
Author: Jeremy Howard
*/
############ Includes #############
include 'config.php';
include 
'global.php';

############ News On/Off #############
$settings mysql_query("SELECT * FROM al_settings");
while (
$row mysql_fetch_array($settings)) {
    
$title $row['title'];
    
$onoff $row['onoff'];
    
$reason $row['reason'];
}

if (
$onoff != '1') {
    echo 
"<title>$title</title>";
echo 
"<font size=1 face=verdana> Reason: $reason </font><br><br>";

}else{

############ Show News #############
$news mysql_query("SELECT * FROM al_news WHERE id='$id'");
while (
$row mysql_fetch_array($news)) {
    
$id $row['id'];
    
$subject $row['subject'];
    
$author $row['author'];
    
$content $row['content'];
    
$source $row['source'];
    
$date $row['date'];
    
$image $row['image'];
    
?>
        
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<TD align=middle width="100%" bgColor=#387ca6><font face="Arial" color="#ffffff" size="1">

<b>Subject:</b> <? echo $subject ?> <b>Author:</b> <? echo $author ?><Br> <b>Date:</b> <? echo $date ?>
</td>
</tr>
<tr>
<TD bgcolor="e5e5e5" width="100%" height="34"><FONT face=Arial color=#595959 size=1>
<?
// Lets see if we can make is so it doesnt show a image if there isnt one
if ($image == '') {
    echo 
'';
}else{
?>
<img src="<? echo $image?>" width="50" height="50" align="right" border="0">
<?
}
?>
<? 
echo $content ?><br><br>
<?
/* If theres no source.. show NOTHING!! */
if ($source == '') {
    echo 
'';
}else{
?>
 | <b>Source:</b> <? echo $source ?>
<?
}
?>
</td>
</tr>
</table>

<br>
<?
}
?>

<hr color="#387ca6">
<?
############ Comment #############
$news mysql_query("SELECT * FROM al_comments WHERE newsid='$id'");
while (
$row mysql_fetch_array($news)) {
    
$id $row['id'];
    
$newsid $row['newsid'];
    
$author $row['author'];
    
$comment $row['comment'];
    
$date $row['date'];
    
?>
        
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<TD align=middle width="100%" bgColor=#387ca6><font face="Arial" color="#ffffff" size="1">

<b>Author:</b> <? echo $author ?><Br> <b>Date:</b> <? echo $date ?>
</td>
</tr>
<tr>
<TD bgcolor="e5e5e5" width="100%" height="34"><FONT face=Arial color=#595959 size=1>
<? echo $comment ?><br><br>
</td>
</tr>
</table>
<hr color="#387ca6">

<center>
<font size="1" face="verdana"><a href="archive.php">Archived News</a></font>
</center>
<br>

<form action="insert.php?s=add" method="post">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<TD align=middle width="100%" bgColor=#387ca6><font face="Arial" color="#ffffff" size="1">
Add a comment
</td>
</tr>
<tr>
<TD bgcolor="e5e5e5" width="100%" height="34"><FONT face=Arial color=#595959 size=1>
Author: <input type="text" name="author"><Br>
Date: <input type="text" name="date" value="<? print(date("F d, Y, h:i")); ?>"><br>
Comment: <textarea cols="30" rows="5" name="comment"></textarea><br>
<input type="hidden" name="id" value="<?php echo $newsid ?>"><br>
<input type="submit">
</td>
</tr>
</table>
</form>

<!-- login table: begin --><center>
<form action="login.php?action=login" method="post">
<table>
<tr>
<td bgcolor="#FFFFFF">
<table>
<tr>
<?php
$user 
mysql_query ("SELECT * FROM al_users WHERE username LIKE '$My_ID_Username' AND password LIKE '$My_ID_Password'");
$user_count mysql_numrows($user);
if (
$user_count == 0) {
    echo 
"<td width=\"100%\" bgcolor=\"$table_color4\" align=\"center\"><font size=1 face=verdana>Username:</font>&nbsp;<input type=\"text\" name=\"username_form\" style=\"font-family:Verdana;font-size:10px\"><Br><font size=1 face=verdana>Password:</font>&nbsp;<input type=\"password\" name=\"password_form\" style=\"font-family:Verdana;font-size:10px\"><br><input type=\"checkbox\" name=\"permanent_form\" checked><br>Always logged in.</font><br><input type=\"submit\" value=\"Login\" style=\"font-family:Verdana;font-size:10px\"></td>";
} else {
echo 
"<td width=\"100%\" bgcolor=\"$table_color4\" align=\"center\"><font size=1 face=verdana>You are currently logged in as $My_ID_Username. <a href=\"login.php?action=logout\">log out</a>? <br> (<a href=admincp.php?s=>Admin Center</a>)</font></td>";
}

?>
</tr>
</table>
</td>
</tr>
</table>
<!-- login table: end -->
</form>

<?
}}
footer()


?>
insert.php
PHP Code:

<?

        
if ($s == 'add') {

    include 
'config.php';
    
$news mysql_query("SELECT * FROM al_comments WHERE newsid='$id'");
while (
$row mysql_fetch_array($news)) {
    
$id $row['id'];
    
$newsid $row['newsid'];
    
$author $row['author'];
    
$comment $row['comment'];
    
$date $row['date'];
}
        
mysql_query ("INSERT INTO al_comments (author, date, comment) VALUES ('$author', '$date', '$comment',) WHERE newsid='$id'") or 
        die(
'Error executing query: ' MySQL_Error());
    print 
"Comment successfully added!!<br>";
    print 
"<a href=\"index.php\">Click Here</a> to return to the the site.";
}
?>
thanks in advance for the help.

and like i said.. the only thing going wrong it the wrong id for the newsid feild isnt right.

edit: i had my news.php mixed with my comment.php sorry

Last edited by Psybadek; 06-15-03 at 01:47 PM.
Reply With Quote
  #2 (permalink)  
Old 06-15-03, 11:53 PM
ridwank's Avatar
ridwank ridwank is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Indonesia
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
I think there's a syntax error on file insert.php
this command below is not valid MySQL Quaery syntaxx

mysql_query ("INSERT INTO al_comments (author, date, comment) VALUES ('$author', '$date', '$comment',) WHERE newsid='$id'") or
die('Error executing query: ' . MySQL_Error());


Try change to that query above with this query bellow :


mysql_query("insert into al_comments (newsid, author, date, comment) VALUES ('$id', '$author', '$date', '$comment')");

I think you send a variable call "id" which set for news id,
so it have to be store on field newsid on table al_comments,

And INSERT command con not be set with an condition such as "WHERE", it would only works on UPDATE command.

Just try... if it doesn't work, let me know.
__________________
-=ridwank=-

<b><a style='text-decoration:none' href="http://www.ridwank.com">CLICK : ridwank.com : PHP SCRIPT CENTER</a></b>
Reply With Quote
  #3 (permalink)  
Old 06-16-03, 12:36 AM
Psybadek Psybadek is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Florida
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

<?

/*
news.php
ALbert.News
Version 1.0
Author: Jeremy Howard
*/
if ($s == 'add') {
    include 
'config.php';
    
$news2 mysql_query("SELECT * FROM al_news WHERE id='$id'");
while (
$row mysql_fetch_array($news2)) {
    
$id $row['id'];
    
$subject $row['subject'];
    
$author $row['author'];
    
$content $row['content'];
    
$source $row['source'];
    
$date $row['date'];
    
$image $row['image'];
}
    
    
$news mysql_query("SELECT * FROM al_comments WHERE newsid='$commid'");
while (
$row mysql_fetch_array($news)) {
    
$commid $row['commid'];
    
$newsid $row['newsid'];
    
$author $row['author'];
    
$comment $row['comment'];
    
$date $row['date'];
}
    
mysql_query ("INSERT INTO al_comments (author, newsid, date, comment) VALUES ('$author', '$id', '$date', '$comment')") or 
        die(
'Error executing query: ' MySQL_Error());
    echo 
"Comment Successfully Added <br>";
    echo 
"Click <a href=index.php>here</a> to go home";
}else{
############ Includes #############
include 'config.php';
include 
'global.php';

############ News On/Off #############
$settings mysql_query("SELECT * FROM al_settings");
while (
$row mysql_fetch_array($settings)) {
    
$title $row['title'];
    
$onoff $row['onoff'];
    
$reason $row['reason'];
}

if (
$onoff != '1') {
    echo 
"<title>$title</title>";
echo 
"<font size=1 face=verdana> Reason: $reason </font><br><br>";

}else{
    
############ Title #############    
    
echo "<title>$title</title>";

############ Show News #############
$news mysql_query("SELECT * FROM al_news WHERE id='$id'");
while (
$row mysql_fetch_array($news)) {
    
$id $row['id'];
    
$subject $row['subject'];
    
$author $row['author'];
    
$content $row['content'];
    
$source $row['source'];
    
$date $row['date'];
    
$image $row['image'];
}
    
?>
        
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<TD align=middle width="100%" bgColor=#387ca6><font face="Arial" color="#ffffff" size="1">

<b>Subject:</b> <? echo $subject ?> <b>Author:</b> <? echo $author ?><Br> <b>Date:</b> <? echo $date ?>
</td>
</tr>
<tr>
<TD bgcolor="e5e5e5" width="100%" height="34"><FONT face=Arial color=#595959 size=1>
<?
// Lets see if we can make is so it doesnt show a image if there isnt one
if ($image == '') {
    echo 
'';
}else{
?>
<img src="<? echo $image?>" width="50" height="50" align="right" border="0">
<?
}
?>
<? 
echo $content ?><br><br>
Comments (0) [<a href="comment.php?id=<? echo $id ?>">View</a>]
<?
/* If theres no source.. show NOTHING!! */
if ($source == '') {
    echo 
'';
}else{
?>
 | <b>Source:</b> <? echo $source ?>
<?
}
?>
</td>
</tr>
</table>

<br>
<?
############ Show News #############
$news mysql_query("SELECT * FROM al_comments WHERE newsid='$commid'");
while (
$row mysql_fetch_array($news)) {
    
$commid $row['commid'];
    
$newsid $row['newsid'];
    
$author $row['author'];
    
$comment $row['comment'];
    
$date $row['date'];

    
?>
        
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<TD align=middle width="100%" bgColor=#387ca6><font face="Arial" color="#ffffff" size="1">

<b>Author:</b> <? echo $author ?><Br> <b>Date:</b> <? echo $date ?>
</td>
</tr>
<tr>
<TD bgcolor="e5e5e5" width="100%" height="34"><FONT face=Arial color=#595959 size=1>
<? echo $comment ?><br><br>

</td>
</tr>
</table>
<?
}
?>
<form action="comment.php?s=add" method="post">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<TD align=middle width="100%" bgColor=#387ca6><font face="Arial" color="#ffffff" size="1">

Add Comment
</td>
</tr>
<tr>
<TD bgcolor="e5e5e5" width="100%" height="34"><FONT face=Arial color=#595959 size=1>
Author: <input type='text' name='author'><Br>
Date: <input type='text' name='date'><Br>
Comment: <textarea cols='30' rows='5' name='comment'></textarea><Br>
<input type="hidden" name="commid" value="<? echo '$commid' ?>">
<input type="hidden" name="newsid" value="<? echo '$newsid' ?>">
<input type="submit">

</td>
</tr>
</table>
</form>
<center>
<font size="1" face="verdana"><a href="archive.php">Archived News</a></font>
</center>
<br>
<!-- login table: begin --><center>
<form action="login.php?action=login" method="post">
<table>
<tr>
<td bgcolor="#FFFFFF">
<table>
<tr>
<?php
$user 
mysql_query ("SELECT * FROM al_users WHERE username LIKE '$My_ID_Username' AND password LIKE '$My_ID_Password'");
$user_count mysql_numrows($user);
if (
$user_count == 0) {
    echo 
"<td width=\"100%\" bgcolor=\"$table_color4\" align=\"center\"><font size=1 face=verdana>Username:</font>&nbsp;<input type=\"text\" name=\"username_form\" style=\"font-family:Verdana;font-size:10px\"><Br><font size=1 face=verdana>Password:</font>&nbsp;<input type=\"password\" name=\"password_form\" style=\"font-family:Verdana;font-size:10px\"><br><input type=\"checkbox\" name=\"permanent_form\" checked><br>Always logged in.</font><br><input type=\"submit\" value=\"Login\" style=\"font-family:Verdana;font-size:10px\"></td>";
} else {
echo 
"<td width=\"100%\" bgcolor=\"$table_color4\" align=\"center\"><font size=1 face=verdana>You are currently logged in as $My_ID_Username. <a href=\"login.php?action=logout\">log out</a>? <br> (<a href=admincp.php?s=>Admin Center</a>)</font></td>";
}

?>
</tr>



</table>
</td>
</tr>
</table>
<!-- login table: end -->
</form>
<?
}}
footer()

?>
thats my newest comment.php file.

i still have the same problem. the comment page with the news looks like comment.php?commid=$id

and it just wont insert the $id into $newsid
Reply With Quote
  #4 (permalink)  
Old 06-16-03, 01:03 AM
ridwank's Avatar
ridwank ridwank is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Indonesia
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
I think you forgot about variable "S"
you have to put it on the form

<input type="hidden" name="s" value="add">

Because you have describe that
the insert command will only be execute
if $S="add"

Im sorry I can not try ur script, because u don't give the other pages that related to this "comment.php"

And I think I can not explain a lot in this forum, i u like ask more about it, you can chat me on Yahoo Messenger,
my Yahoo id = ridwank_yh
__________________
-=ridwank=-

<b><a style='text-decoration:none' href="http://www.ridwank.com">CLICK : ridwank.com : PHP SCRIPT CENTER</a></b>
Reply With Quote
  #5 (permalink)  
Old 06-16-03, 01:09 AM
Psybadek Psybadek is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Florida
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
i only have aim and msn messenger

but heres the most recent zip...

edit: i forgot to update the installer.. in the comments table..

change 'id' to 'commid'

edit2: attachement removed because this isnt a release

Last edited by Psybadek; 06-16-03 at 01:51 AM.
Reply With Quote
  #6 (permalink)  
Old 06-16-03, 03:41 AM
Fanoose's Avatar
Fanoose Fanoose is offline
Newbie Coder
 
Join Date: Jun 2003
Location: KSA
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Psybadek, i got to tell you man.. you got some weird way of
writing codes.

one of the mistakes is :
<input type="hidden" name="newsid" value="<? echo '$newsid' ?>">

it should be something like this :
<input type="hidden" name="newsid" value="<? echo $newsid ?>">

anyway i managed to fix your problem, and added a counter
for the comments in news.php & comment.php, now it shows
the news when you press (view). just take a look and see.

* advice : try to use blocks of functions insted of one big flat
of code, its easier to debug.
Attached Files
File Type: zip news-comment src.zip (4.2 KB, 225 views)
__________________
"The strong is not the one who overcomes the people by his strength, but the strong is the one who controls himself while in anger."
Reply With Quote
  #7 (permalink)  
Old 06-16-03, 12:26 PM
Psybadek Psybadek is offline
Wannabe Coder
 
Join Date: Jun 2003
Location: Florida
Posts: 188
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for your help..

and yea.. i do got weird coding ways
Reply With Quote
  #8 (permalink)  
Old 06-17-03, 04:39 AM
nd2 nd2 is offline
Wannabe Coder
 
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
<input type="hidden" name="newsid" value="<? echo $newsid ?>">

use long php tags
<?php

some servers have short tags disabled.
__________________
IonCMS (Coming Soon.)
http://ioncms.com
--
Ncaster (Free php/mysql cms)
http://ncaster.cjb.net
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
image submit button problems Pepe PHP 10 12-22-03 08:15 PM
diWEBlo problems steveash Perl 4 10-23-03 11:41 PM
getting -2147217900 error while inserting and updating skchakri ASP 3 09-20-03 10:34 AM
Scripting problems plz help darkcarnival PHP 2 09-02-03 03:51 PM
Login problems Mister B. ASP 11 08-24-03 06:37 PM


All times are GMT -5. The time now is 05:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.