Jump to content

Post script not stacking.


GB_001

Recommended Posts

Hello for some reason my post script is not updating the database properly,

it doesn't stack it just overwrites.

 

 

<?php
session_start();
include('Connect.php');

$User=$_SESSION['email'];
$Friend=$_GET['F'];
$Comment=$_GET['C'];
$getN=mysql_query("SELECT * FROM Ysers WHERE email='$User'");
$row2 = mysql_fetch_array($getN);
$Name=$row2['Name'];
$PIC=$row2['Picture'];
$PIC="Images/$PIC"; 
list($width, $height, $type, $atrib) = getimagesize($PIC);
if($width>150||$height>200)
{
    $P=$width/100;
    $PH=$height/100;
    
    $MW=$width/$P;
    $MH=$height/$PH;
}

$pww=(360-$MW)-15;
$Time=date('Y-m-d');
$CF="<br><table valign=bottom height=40px width=360px style=\'color:white; background: black; border: 1px solid white; position:relative; left:80px;\'>
     <tr>
     <td COLSPAN=2 style=\'border-bottom: 1px solid white;\'>$Name -$Time</td>
     </tr>
     <tr>
     <td><img src=$PIC height=$MH width=$MW/></td><td width=150px valign=top style=\'padding: 15px;\'><p>$Comment</p></td>
     </tr>
     </table><gbbreaklinezero>";
     
$Cmenty=mysql_query("SELECT * FROM Ysers WHERE email='$Friend'");
$row = mysql_fetch_array($Cmenty);
$Commy=$row['Comments'];
mysql_query("UPDATE Ysers SET Comments='$CF $Commy' WHERE email='$Friend'");
?>

Link to comment
https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/
Share on other sites

Hello for some reason my post script is not updating the database properly,

it doesn't stack it just overwrites.

 

I mean that it just overwrites the column instead of keeping previous posts.

 

All these point in the direction that you should use INSERT instead of UPDATE. INSERT [as the name proposes] adds new records to the database, while UPDATE edits existing ones.

 

<?php
mysql_query("UPDATE table (col1, col2) VALUES ('value1', 'value2')");
?>

 

For some reason it still doesn't work.

 

<?php
session_start();
include('Connect.php');

$User=$_SESSION['email'];
$Friend=$_GET['F'];
$Comment=$_GET['C'];
$getN=mysql_query("SELECT * FROM Ysers WHERE email='$User'");
$row2 = mysql_fetch_array($getN);
$Name=$row2['Name'];
$PIC=$row2['Picture'];
$PIC="Images/$PIC"; 
list($width, $height, $type, $atrib) = getimagesize($PIC);
if($width>150||$height>200)
{
    $P=$width/100;
    $PH=$height/100;
    
    $MW=$width/$P;
    $MH=$height/$PH;
}

$pww=(360-$MW)-15;
$Time=date('Y-m-d');
$CF="<br><table valign=bottom height=40px width=360px style=\'color:white; background: black; border: 1px solid white; position:relative; left:80px;\'>
     <tr>
     <td COLSPAN=2 style=\'border-bottom: 1px solid white;\'>$Name -$Time</td>
     </tr>
     <tr>
     <td><img src=$PIC height=$MH width=$MW/></td><td width=150px valign=top style=\'padding: 15px;\'><p>$Comment</p></td>
     </tr>
     </table><gbbreaklinezero>";
     
$Cmenty=mysql_query("SELECT * FROM Ysers WHERE email='$Friend'");
$row = mysql_fetch_array($Cmenty);
$Commy=$row['Comments'];
mysql_query("INSERT INTO Ysers (Comments) VALUE ($CF) WHERE email='$Friend'");
?>

I just realized that i made a stupid mistake in my previous post, used UPDATE instead of INSERT  :-\

 

<?php
mysql_query("INSERT table (col1, col2) VALUES ('value1', 'value2')");
?>

 

Just insert the row, it will be automatically added. Your query may be something like, instead of the WHERE part:

mysql_query("INSERT INTO Ysers (Comments, email) VALUES ('$CF', '$Friend')");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.