Jump to content

Insert data to a table, I can't see why it doesn't work


MrMagooba

Recommended Posts

I just can't figure out why it isn't sending the data to the table, I've check the names over and over, all the info is parsed correctly, but it falls flat at: $result = mysql_query($sql);

 

Can anyone help please?  You can see it not working here if you want, code is attached to this post.

 

Any help is greatly appreciated.

 

[attachment deleted by admin]

Link to comment
Share on other sites

change

$sql = "INSERT INTO topicstarter ('posttitle', 'postdate', 'poster', 'message')
VALUES ('$posttitle','$postdate','$poster','$message')";

to

$sql = "INSERT INTO topicstarter (posttitle, postdate, poster, message)
VALUES ('$posttitle','$postdate','$poster','$message')";

or

$sql = "INSERT INTO topicstarter (`posttitle`, `postdate`, `poster`, `message`)
VALUES ('$posttitle','$postdate','$poster','$message')";

Link to comment
Share on other sites

Thanks for your help peeps.  Adding die (mysql_error()) changed the error code to brought up the following error:

 

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'prefix'>th Jun 2007: 12:00','Your name...','Type away...

 

Turns out it was part of the form that was bottoming it out.  If I remove the ''s from:

<input type="hidden" name="postdate" value="<?php echo date('j') ."<span class='prefix'>" .date('S') ."</span> " .date('M Y') .": " .date('H:i');?>">

it works fine.

 

I don't see why that would cause a problem though, I mean it looks like this when parsed:

<input type="hidden" name="postdate" value="17<span class='prefix'>th</span> Jun 2007: 11:58">

Unless I have forgotten something, or being dumb, so if someone could enlighten me I would be very grateful.

 

I have just remembered to put \ infront of the ' (ie class=\'prefix\') before posting, which also works, but I forget why  :-[  I remember the awnser but not the reasoning, please help me understand again.

 

Thanks again

 

 

Link to comment
Share on other sites

value="17<span class='prefix'>th</span> Jun 2007: 11:58"

 

The value you're passing is everything between the consecutive double quotes.  A more rational approach would be to pass the date time as yyyy-mm-dd h:ia and then prettify it when you retrieve and display it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.