Jump to content


Photo

Why wont this code work?????????


  • Please log in to reply
4 replies to this topic

#1 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 May 2006 - 05:48 PM

when you click submit it doesnt post anything to the database

<?PHP
session_start();
?>
<html>
<body bgcolor="#000000" text="#FF0000" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<form method="POST">
  <p>Message:<br>
  <textarea rows="5" name="Me" cols="26"></textarea></p>
  <p><input type="submit" value="Submit" name="submit"></p>
</form>
<?php
if(isset($_POST['submit'])){
$username="***";
$password="*****";
$database="******";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$me=$_POST['Me'];
$em=$_SESSION['email'];
$cat=$_GET['cid'];
$user=$_SESSION['user'];
$id=$_GET['id'];
$query2 = "SELECT * FROM messages WHERE id=$id";
$result2 = mysql_query($query2);
$row = mysql_fetch_row($result2);
$re="RE:";
$subj="$re $row[2]";
$mes="<i><font size='2'>Original Message By $row[1]</font><br><br>$row[3]</i><br>-----------------------------<br><br>$me<br>";
$me=$_POST['Me'];
$query = "INSERT INTO messages VALUES ('','$user','$subj','$mes','$em','$cat')";
mysql_query($query);
}
$cat=$_GET['cid'];
echo "<a href='board.php?cid=$cat'>Return to menu</a>";
?>

"Syntax error" .. WHERE THE **** IS IT?!

#2 cyberRobot

cyberRobot
  • Moderators
  • Much to Learn
  • 2,772 posts

Posted 22 May 2006 - 06:36 PM

In your form tag, don't you need the action attribute:
<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
...


#3 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 May 2006 - 08:08 PM

no, i dont think so....ive done many forms and left it out....
"Syntax error" .. WHERE THE **** IS IT?!

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 May 2006 - 08:18 PM

$query = "INSERT INTO messages VALUES ('','$user','$subj','$mes','$em','$cat')";
mysql_query($query) or die(mysql_error();

add that and post what it says. but also, you need to do like

insert into messages ('column','column','column') values ('blah','blah','blah')

the correct column for the variable. the only columns you can omit are the ones that a value is auto inserted upon insertion, like timestamps or auto_incremented primary keys
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 22 May 2006 - 08:26 PM

[!--quoteo(post=376130:date=May 22 2006, 03:18 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 22 2006, 03:18 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$query = "INSERT INTO messages VALUES ('','$user','$subj','$mes','$em','$cat')";
mysql_query($query) or die(mysql_error();

add that and post what it says. but also, you need to do like

insert into messages ('column','column','column') values ('blah','blah','blah')

the correct column for the variable. the only columns you can omit are the ones that a value is auto inserted upon insertion, like timestamps or auto_incremented primary keys
[/quote]
The field left blank in auto_increment

You have an error in your SQL syntax near '2'>Original Message By admin

Know you can change your own informat' at line 1

[!--quoteo(post=376138:date=May 22 2006, 03:24 PM:name=legohead6)--][div class=\'quotetop\']QUOTE(legohead6 @ May 22 2006, 03:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
The field left blank in auto_increment

You have an error in your SQL syntax near '2'>Original Message By admin

Know you can change your own informat' at line 1
[/quote]
o there we go! i fixed it! thats wierd! I though you could put singal quotes inside doubles...but it works without them!

Thanks
MAtt
"Syntax error" .. WHERE THE **** IS IT?!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users