Jump to content


Photo

Php Mysql Weirdo Error

php mysql database insert

  • Please log in to reply
18 replies to this topic

#1 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 11:54 AM

Hi,
I'm not new to Sql or PHP or atleast I hope not :happy-04: . I coded a simple register form in HTML and this file opens a 'newuser.php' which in turn opens another one, and another finally after checking all INPUT fields, reaches a 'enterintodb.php' .

Now, here's the joke. Every field enters into the table of MySql except for the password field. All entries including 1st name, last name, etc etc. get added to the table and like I said , password doesn't add.

Just to be sure, at the end I echo all the fields and then echo "New user created !" .

No MySql error or any syntax error displayed. The password field echoes w/o any problems, it displays the entered password. But no entry in the DB .

password column : varchar(255) , utf16_general_ci ,

Iv also attached the enterintodb.php file .
the others don't matter, coz when I echo $password, it displays perfectly.

in the form this is the password field " <input type="password" name="password" size="20" style="border-left-width=0px"> "

and don't worry about sql auth, i run a separate PHP file for that before enterintodb.php

So, guys, help me out :) please

Here's the attachment = Attached File  enterintodb.php   371bytes   7 downloads

#2 jcbones

jcbones

    Advanced Member

  • Gurus
  • 2,573 posts
  • LocationNorth Carolina

Posted 17 November 2012 - 12:05 PM

You have either:
1. spelling error in your column names.
2. spelling error in your variable name.

#3 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:13 PM

You have either:
1. spelling error in your column names.
2. spelling error in your variable name.


Well, I don't seem to have a variable spelling error, seems to me the echo wouldn't have worked at all.
No column spelling error either, double checked both. I'm running on Xampp, with phpmyadmin .
restarted MySql twice, no progress there either . :sweat: Any other way this could happen ?. Collation problems ?, any special setting for MySql to handle password fields ??

#4 Pikachu2000

Pikachu2000

    I hate everything.

  • Staff Alumni
  • 11,378 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 17 November 2012 - 12:15 PM

Have you echoed the query string and made sure it contains the values you'd expect it to contain?
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "

#5 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:17 PM

Have you echoed the query string and made sure it contains the values you'd expect it to contain?


Can you give me an idea on how to do that, also
correct me here, do you mean ?

$sql = whatever query
echo $sql ; ?

#6 Pikachu2000

Pikachu2000

    I hate everything.

  • Staff Alumni
  • 11,378 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 17 November 2012 - 12:20 PM

Exactly. Immediately after defining the $sql variable, and before executing the query.
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "

#7 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:24 PM

Exactly. Immediately after defining the $sql variable, and before executing the query.


Alright, looks like we're getting somewhere.
echoed the query, the insert password value turns blank for some reason .
Any idea ?, all other inserts have solid values, only the pw value disappears during query

#8 MMDE

MMDE

    Advanced Member

  • Members
  • PipPipPip
  • 654 posts
  • Locationhome

Posted 17 November 2012 - 12:26 PM

Alright, looks like we're getting somewhere.
echoed the query, the insert password value turns blank for some reason .
Any idea ?, all other inserts have solid values, only the pw value disappears during query

We don't see your code, how should we know?
Please post it! :P

My tip is to trace it all the way back to where you think you get it from and echo it all the way from there to wherever you lose it.

Edited by MMDE, 17 November 2012 - 12:26 PM.

Posted Image
^ Wrote the font in PHP. :)

#9 Pikachu2000

Pikachu2000

    I hate everything.

  • Staff Alumni
  • 11,378 posts
  • LocationFuture Independent Republic of Texas
  • Age:106

Posted 17 November 2012 - 12:26 PM

Something is causing $password to be empty/undefined before it gets to the query. Do you have error reporting set up and on?
"Java" is to "Javascript" about the same as "fun" is to "funeral".

Why $_SERVER['PHP_SELF'] is bad. || Why ORDER BY RAND() is bad || Every problem can be solved with rm -rf *

Random Quote: "

#10 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:26 PM

as you can see

INSERT INTO userregistry (email,password11,firstname,lastname,contact,sex,dob,active,date) VALUES ('vikram12345@gmail.com','','cv','sd','9535283163','1','01012000','1','November 17, 2012, 10:53 pm')

^ the echoed sql query

Edited by PFMaBiSmAd, 17 November 2012 - 12:31 PM.
removed formatting to fix micro-font size


#11 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:28 PM

I shall upload the detailsverify.php, the code that verifies all fields

#12 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:28 PM

<?php
date_default_timezone_set('Asia/Kolkata') ;
$estatus = 0 ;
$erepeatstatus = 0 ;
$passwordstatus = 0 ;
$repeatpasswordstatus = 0 ;
$date = date("F j, Y, g:i a");
$active = 1 ;
$blankemail = 0 ;
$blankpassword = 0 ;
$allokay = 0 ;
if (strlen($email)==0)
{
$blankemail = 2 ;
}
else
{
$blankemail = 1 ;
}

if (strlen($password)==0)
{
$blankpassword = 2 ;
}
else
{
$blankpassword = 1 ;
}

if(!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$estatus = 2 ;
}
else
{
$estatus = 1 ;
}

if($emailtwo == $emailtwo)
{
$erepeatstatus = 1 ;
}
else
{
$erepeatstatus = 2 ;
}


if (strlen($password)<= 10)
{
$passwordstatus = 1 ;
}
else
{
$passwordstatus = 2 ;
}

if($password == $passwordtwo)
{
$passwordrepeatstatus = 1 ;
}
else
{
$passwordrepeatstatus = 2 ;
}

echo $email."<br>" ;
echo $emailtwo."<br>" ;
echo $password."<br>" ;
echo $passwordtwo."<br>" ;
//echo intval($email);


$allokay = $blankemail.$blankpassword.$estatus.$erepeatstatus.$passwordstatus.$passwordrepeatstatus ;
echo $allokay ;
if($allokay == 111111)
{
require ('sqlauth2.php') ;
require ('enterintodb.php') ;
echo "new user registered " ;
}
else
{
$goto = "http://localhost:78/bullet2/newuserregister.php?blankemail=".$blankemail."&blankpassword=".$blankpassword."&emailformat=".$estatus."&emailrepeat=".$erepeatstatus."&longpassword=".$passwordstatus."&passwordrepeat=".$passwordrepeatstatus ;
header("Location: $goto ");
}
exit ;

?>

#13 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 17 November 2012 - 12:29 PM

Any bets that you are trying to check if it is empty, but are actually assigning an empty string to it?
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#14 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:34 PM

Any bets that you are trying to check if it is empty, but are actually assigning an empty string to it?


It doesn't get assign empty. echoed $password right before mysql query. displays the value fine
anything wrong with the mysql code ?

#15 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:41 PM

Solved it, any guesses !!!!!!, come on, this is fun !

#16 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 12:45 PM

Alright, here it is :

before addintodb.php
I run sqlauth.php

Since I'm runnin sql w/o a password, the $password from the form and $password from the auth file conflict.
Thereby the $password sets to null .
change sql $password to $passworda or whatever and conflict resolved :)

#17 PFMaBiSmAd

PFMaBiSmAd

    Advanced Member

  • Staff Alumni
  • 16,767 posts
  • LocationColorado, U.S.A.

Posted 17 November 2012 - 01:12 PM

When you try to copy/paste together a html document using php include statements, that's the kind of problems you run into.
Signature: (not a comment about anything you posted unless specifically indicated)
Debugging step #1: To get past the garbage-out equals garbage-in stage in your code, you must check that the inputs to your code are what you expect.

Programming is just problem solving, but it is done in another language. You must learn enough of the programming language you are using to be able to read and write code.

#18 vikram12345

vikram12345

    Member

  • Members
  • PipPip
  • 22 posts
  • LocationBangalore, INDIA

Posted 17 November 2012 - 11:22 PM

When you try to copy/paste together a html document using php include statements, that's the kind of problems you run into.


Very much, should quit linking multiple php files together.

#19 jcbones

jcbones

    Advanced Member

  • Gurus
  • 2,573 posts
  • LocationNorth Carolina

Posted 18 November 2012 - 05:28 PM

This is why I 'DEFINE' my all of my configuration variables (constants).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com