Jump to content

[SOLVED] EASY Insert problem


srhino

Recommended Posts

Maybe I have been looking at this screen to long but I can't figure out what I am doing wrong.

 

I am simply trying to make a form that you can post some information on the website.

 

I have a form called newpractice.inc.php I have made it as simple as possible.

 

 

<form action="index.php" method="post">
POSTER: <input type="text" name="poster">
PRACTICE INFORMATION: <input type="text" name="desc">
<input type="submit" value="Submit">
<input type="hidden"   name="content" value="addpractice">

</form>

 

And here is the insert php code called addpractice.inc.php

<?php

$poster = $_POST['poster'];
$desc = htmlspecialchars($_POST['desc']);

if (trim($poster == ''))
{
    echo "<h2>Sorry, each Quote must have a Poster</h2>\n";
}else
{
  $con = mysql_connect("XXXX", "XXXX", "XXXX")
or die('Could not connect to database');
mysql_select_db("database_name", $con) or die('Sorry could not connect to the
database');

    $query = "INSERT INTO newpractice (eventid,poster,desc) " .
          " VALUES ('$eventid', '$poster', '$desc')";

    $result = mysql_query($query) or die('Sorry, we could not accept your information at this time');

    if ($result)
       echo "<a href=\"index.php\"><font color=\"#000000\"><h2>Comment Accepted</h2></font></a>\n";
    else
       echo "<h2>Sorry, there was a problem accepting your event</h2>\n";
}
?>

 

I cant figure out what I am doing wrong can some use a fresh set of eyes and tell me what I am doing wrong?

 

Thanks in Advance.

 

 

 

Link to comment
Share on other sites

$query = "INSERT INTO newpractice (eventid,poster,desc) " .
          " VALUES ('$eventid', '$poster', '$desc')";

 

Why are you adding a concatenation operator your query? That isn't required; nevertheless it isn't the problem. You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) so change your code like this:

 

$query = "INSERT INTO `newpractice` (`eventid`,`poster`,`desc`) " .
          " VALUES ('$eventid', '$poster', '$desc')";

 

...see if that works :).

Link to comment
Share on other sites

You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ...

 

Was there something in my post about reserved words that was so unclear you needed to reiterate the advice?

Link to comment
Share on other sites

You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ...

 

Was there something in my post about reserved words that was so unclear you needed to reiterate the advice?

 

I am allowed to post my side of the problem and I actually did not reiterate your post, sometimes SQL queries will not work without backticking them. Please do not post such remarks to me!

Link to comment
Share on other sites

You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ...

 

Was there something in my post about reserved words that was so unclear you needed to reiterate the advice?

 

I am allowed to post my side of the problem and I actually did not reiterate your post, sometimes SQL queries will not work without backticking them. Please do not post such remarks to me!

 

Time to set some things straight.

1) He said that they could be backticked in his post, so you were reiterating. ;)

2) The REASON for the backticks is because you're using a MySQL reserved word.

3) Backticks are a MySQL-ONLY operator.

4) Backticks should NEVER be used.

5) You should not create tables or columns with the same names as reserved words, in order to not have to use backticks.

 

Moral of the story: Don't use backticks and rename your tables.

Link to comment
Share on other sites

You could try backticking the table and fields as sometimes that causes the problem (it did cause me a problem once or twice) ...

 

Was there something in my post about reserved words that was so unclear you needed to reiterate the advice?

 

I am allowed to post my side of the problem and I actually did not reiterate your post, sometimes SQL queries will not work without backticking them. Please do not post such remarks to me!

 

Time to set some things straight.

1) He said that they could be backticked in his post, so you were reiterating. ;)

2) The REASON for the backticks is because you're using a MySQL reserved word.

3) Backticks are a MySQL-ONLY operator.

4) Backticks should NEVER be used.

5) You should not create tables or columns with the same names as reserved words, in order to not have to use backticks.

 

Moral of the story: Don't use backticks and rename your tables.

 

I did not realise that you need to backtick reserved-words only so that is why I stated that. It is a learning process so I cannot be perfect in my reply, except I am perfect in my reply based on my knowledge. That GM did not need to get on the defensive with his reply.

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.