5 Replies - 673 Views - Last Post: 24 October 2009 - 03:04 AM Rate Topic: -----

#1 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

adding to my sql

Post icon  Posted 23 October 2009 - 05:25 AM

i have added a new field which i want to be 1 in the user table





The code will explain it all

$nick = 1



then i add there username password to the db


// now we insert it into the database
$insert = "INSERT INTO users (username, password, pokemon, poke1lvl)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['starter']."', '".$_POST['nick']."')";
$add_member = mysql_query($insert);
?>



if i take the post nick out it works but i want it to make poke1lvl 1

i am getting this error

Parse error: syntax error, unexpected T_VARIABLE in /home/a8310104/public_html/Signup.php on line 60

Is This A Good Question/Topic? 0
  • +

Replies To: adding to my sql

#2 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: adding to my sql

Posted 23 October 2009 - 05:47 AM

hi;
what is in line 60?
is it $nick = 1
if it is, then you probably forgot the semicolon at the end of that line
Was This Post Helpful? 0
  • +
  • -

#3 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: adding to my sql

Posted 23 October 2009 - 05:51 AM

View Postahmad_511, on 23 Oct, 2009 - 04:47 AM, said:

hi;
what is in line 60?
is it $nick = 1
if it is, then you probably forgot the semicolon at the end of that line


line 60 is

or die(mysql_error());



and the end of the my sql query

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}

// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}

// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}
$nick = "1"
// now we insert it into the database
$insert = "INSERT INTO users (username, password, pokemon, poke1lvl)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['starter']."', '".$_POST['nick']."')";
$add_member = mysql_query($insert);
?>



that's my code the connect it at the top

i dont think i need


$nick = "1"



could i just do this ?


// now we insert it into the database
$insert = "INSERT INTO users (username, password, pokemon, poke1lvl)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['starter']."', '"1"')";
$add_member = mysql_query($insert);
?>



would that fill poke1lvl has 1 ?
Was This Post Helpful? 0
  • +
  • -

#4 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: adding to my sql

Posted 23 October 2009 - 05:57 AM

try to add '1' without the double quotes
$insert = "INSERT INTO users (username, password, pokemon, poke1lvl)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['starter']."', '1')";
$add_member = mysql_query($insert);


Was This Post Helpful? 1
  • +
  • -

#5 nick1200  Icon User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: adding to my sql

Posted 23 October 2009 - 05:59 AM

View Postahmad_511, on 23 Oct, 2009 - 04:57 AM, said:

try to add '1' without the double quotes
$insert = "INSERT INTO users (username, password, pokemon, poke1lvl)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['starter']."', '1')";
$add_member = mysql_query($insert);



ya that worked thanks :)
is there any gd my sql insert tut ? that you knwo off cus i hate all of the , and " in my sql lol and would like to learn so if i get a error like this again will know whats wrong
Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: adding to my sql

Posted 24 October 2009 - 03:04 AM

if you want to use string with My SQL than you must use single or double quotes with your value, and when you are inserting integer or number to table then there is no needed for single or double quotes :)
something like this:
$insert = "INSERT INTO users (username, password, pokemon, poke1lvl)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '".$_POST['starter']."', 1)";
$add_member = mysql_query($insert);


;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1