not inserting

Codes here !

Moderators: macek, egami, gesf

User avatar
xlordt
New php-forum User
New php-forum User
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ
Contact:

not inserting

Postby xlordt » Sun Jan 19, 2003 6:53 am

im tring to code my self my own memo script.. but.. i have a problem.. the script wont inster the input in the the table.. can anyone please tell me why.. i cant find the error
here is my code

Code: Select all

 
if(!$_USER['uid'] >= 2){
    echo'<CENTER><FONT SIZE="4"><Br><Br>You must first login to use this feature
         </FONT>';
     exit;
}
 
 
  if($submit){
 
  echo $_USER['username'] . " Your memo is being sent to $to";
  $A = "INSERT INTO gl_memo(from,msg) VALUES ('$_USER[username]','$HTTP_POST_VARS[msg]')";
  $result = DB_query($A);
 
}else{

 
?>   
     <TABLE WIDTH=55% ALIGN="center"><TR ALIGN="left"><TD ALIGN="left">
     <FORM METHOD="post" ACTION="<?PHP echo $PHP_SELF ?>">
    <br><Br>
     Send Memo To:<Br>
     <INPUT TYPE="text" NAME="to"><Br>
     <TEXTAREA cols="55" rows="15" NAME="msg">
     </TEXTAREA><br>
     <INPUT TYPE="submit" NAME="submit" value="submit memo">
    </TD></TR></FORM></TABLE>

<?php
}   
?>


then i get this..

xlordt Your memo is being sent to grayman1064: You have an error in your SQL syntax near 'from,msg) VALUES ('xlordt','')' at line 1

User avatar
xlordt
New php-forum User
New php-forum User
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ
Contact:

Postby xlordt » Sun Jan 19, 2003 8:21 am

nm i fixed it.. err but i will still post the fix here so that just in case it is needed in time...

my error before was that is was not inserting in to db..
heres the bad code

Code: Select all


if(!$_USER['uid'] >= 2){
    echo'<CENTER><FONT SIZE="4"><Br><Br>You must first login to use this feature
         </FONT>';
     exit;
}
 
 
  if($_POST['submit']){
 
  echo $_USER['username'] . " Your memo is being sent to $to";
  $A = "INSERT INTO gl_memo(from, msg) VALUES ('$_USER[username]','$_POST[msg]')";
  $result = @mysql_query($A);
   
 
}else{

 
?>   
     <TABLE WIDTH=55% ALIGN="center"><TR ALIGN="left"><TD ALIGN="left">
     <FORM METHOD="post" ACTION="<?PHP echo $PHP_SELF ?>">
    <br><Br>
     Send Memo To:<Br>
     <INPUT TYPE="text" NAME="to"><Br>
     <TEXTAREA cols=55 rows=15 COLSPAN=2 NAME="msg" WRAP=virtual>
     </TEXTAREA><br>
     <INPUT TYPE="submit" NAME="submit" value="submit memo">
    </TD></TR></FORM></TABLE>

<?php
}   
?>


now the way i fixed it was by removing (from, msg)
and whooalah =) workz ..

Code: Select all


if(!$_USER['uid'] >= 2){
    echo'<CENTER><FONT SIZE="4"><Br><Br>You must first login to use this feature
         </FONT>';
     exit;
}
 
 
  if($_POST['submit']){
 
  echo $_USER['username'] . " Your memo is being sent to $to";
  $A = "INSERT INTO gl_memo VALUES ('$_USER[username]','$_POST[msg]')";
  $result = @mysql_query($A);
   
 
}else{

 
?>   
     <TABLE WIDTH=55% ALIGN="center"><TR ALIGN="left"><TD ALIGN="left">
     <FORM METHOD="post" ACTION="<?PHP echo $PHP_SELF ?>">
    <br><Br>
     Send Memo To:<Br>
     <INPUT TYPE="text" NAME="to"><Br>
     <TEXTAREA cols=55 rows=15 COLSPAN=2 NAME="msg" WRAP=virtual>
     </TEXTAREA><br>
     <INPUT TYPE="submit" NAME="submit" value="submit memo">
    </TD></TR></FORM></TABLE>

<?php
}   
?>

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

Postby Joan Garnet » Sun Jan 19, 2003 9:33 am

ThanX for sharing ;)


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Google [Bot] and 2 guests