Jump to content

[SOLVED] INSERT query half doesn't work


Greaser9780

Recommended Posts

Here's the form:

<form action="addplayer.php" method="post">

Player Name:<input type="text" name="name"><br>

Position:<input type="text" name="pos"><br>

<button type="submit">Submit</button>

</form>

 

Here's the script:

<?php

include("db.php");

array_pop($_POST);

if ( get_magic_quotes_gpc() ) {

    $_POST= array_map('stripslashes', $_POST);

}

$name = mysql_real_escape_string(trim($_POST['name']));

$pos = mysql_real_escape_string(trim($_POST['pos']));

 

$sql = mysql_query("INSERT INTO `players` (`name`,`pos`) VALUES ('$name','$pos')") or die(mysql_error());

 

 

$playerid = mysql_insert_id();

include("addplayerform.html");

?>

 

The name will get entered but the position "pos" will not go into the table. I even set default value for what my $_POST['pos'] is and it still won't go in.  Field is set to varchar 20 and that's it.

Link to comment
Share on other sites

Just FYI, <button> isn't supported by all browsers, you should use <input type="submit">

 

What happens if you do:

$q = "INSERT INTO `players` (`name`,`pos`) VALUES ('$name','$pos')";

print $q;

$sql = mysql_query($q) or die(mysql_error());

 

What does it show you the query says?

Link to comment
Share on other sites

Its not recognizing the variable is what i would say, i've had this problem many of times.

 

Make sure the $pos var is getting posted to the page with the query.

 

Try adding:

 

$pos = $_POST['pos'];

 

At the begining of the php code then running the other functions separatly.

 

$pos = mysql_real_escape_string($pos);
$pos = trim($pos);

 

 

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.