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
https://forums.phpfreaks.com/topic/39437-solved-insert-query-half-doesnt-work/
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?

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);

 

 

Archived

This topic is now archived and is closed to further replies.

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