GB_001 Posted September 2, 2008 Share Posted September 2, 2008 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'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/ Share on other sites More sharing options...
CMC Posted September 2, 2008 Share Posted September 2, 2008 mysql_query("UPDATE Ysers SET Comments='$CF $Commy' WHERE email='$Friend'"); That's because you're updating the columns instead of adding new ones. Is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/#findComment-631576 Share on other sites More sharing options...
GB_001 Posted September 2, 2008 Author Share Posted September 2, 2008 No, I mean that it just overwrites the column instead of keeping previous posts. Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/#findComment-631808 Share on other sites More sharing options...
Fadion Posted September 2, 2008 Share Posted September 2, 2008 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')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/#findComment-631811 Share on other sites More sharing options...
GB_001 Posted September 2, 2008 Author Share Posted September 2, 2008 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'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/#findComment-632317 Share on other sites More sharing options...
AndyB Posted September 3, 2008 Share Posted September 3, 2008 INSERT does not support WHERE. Insert adds to the table. If you properly trapped and displayed errors, you would have seen that. Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/#findComment-632349 Share on other sites More sharing options...
GB_001 Posted September 3, 2008 Author Share Posted September 3, 2008 So how can I fix my UPDATE problem then? Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/#findComment-632352 Share on other sites More sharing options...
Fadion Posted September 3, 2008 Share Posted September 3, 2008 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')"); Quote Link to comment https://forums.phpfreaks.com/topic/122309-post-script-not-stacking/#findComment-632548 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.