Parameter refuses to store

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zetapulse
Forum Newbie
Posts: 6
Joined: Mon Jan 04, 2010 9:14 pm

Parameter refuses to store

Post by zetapulse »

Hello, I'm new to php & need some help with a script I made:

Code: Select all

$No=$_GET['cust']; //gets customer ID as $No
 
if(isset($_POST['Submit']))
{
 
 
$talbum=$_POST['txtalbumname'];
$Date=date("j-m-Y");
 
$sql=mysql_query("insert Into album(Name,Date,accountNo) values ('$talbum','$Date','$No') ") or die ("error in adding".mysql_error()); //stores $No in MySQL table
}
The problem is that no matter what I do, the value stored in accountNo (which should be the value in $No) ends up being 0. I've tried replacing

Code: Select all

('$talbum','$Date','$No')
with

Code: Select all

('$talbum','$Date','53')
& the value stored in the table is still 0!

$No is storing the value correctly, I tried

Code: Select all

echo "$No";
in a random place on the website & got the expected value printed. Please help, don't want to sound desperate but it's kind of an emergency.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Parameter refuses to store

Post by manohoo »

Show the structure of table "album"
zetapulse
Forum Newbie
Posts: 6
Joined: Mon Jan 04, 2010 9:14 pm

Re: Parameter refuses to store

Post by zetapulse »

Code: Select all

Table:album
Field        Type
No           int(255)
Name         varchar(255)
Date         text
accountNo    int(255)
I don't know if this is how you meant but that's the "album" table's structure.
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Parameter refuses to store

Post by Griven »

Inside MySQL, run the query "EXPLAIN album". This will give a detailed output of the structure of the table.

You may want to try testing your queries directly in MySQL via either command line or a program like MySQL Query Browser. This will allow you to see what your query does independently of your PHP code.
zetapulse
Forum Newbie
Posts: 6
Joined: Mon Jan 04, 2010 9:14 pm

Re: Parameter refuses to store

Post by zetapulse »

Code: Select all

Field   Type    Null    Key     Default     Extra
No  int(255)    NO  PRI     NULL    auto_increment
Name    varchar(255)    NO      NULL     
Date    text    NO      NULL     
accountNo   int(255)    NO      NULL    
I ran

Code: Select all

INSERT INTO album(Name,Date,accountNo) values ('10','10','10') ")
& all values including accountNo were entered successfully. Name & Date never had a problem anyway, it's just accountNo.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Parameter refuses to store

Post by manohoo »

I duplicated your table and your code in my system, everything works fine:

Code: Select all

<?php
 
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db("test");
 
$talbum='txtalbumname';
$Date=date("j-m-Y");
$No = 25;
$sql=mysql_query("insert Into album(Name,Date,accountNo) values ('$talbum','$Date','$No') ") or die ("error in adding".mysql_error()); //stores $No in MySQL table
 $result=mysql_query("select * from album");
$get_info = mysql_fetch_row($result);
foreach ($get_info as $field) 
{echo $field."<br />";}
?>
 
Output:
0
txtalbumname
5-01-2010
25
Last edited by manohoo on Mon Jan 04, 2010 10:07 pm, edited 1 time in total.
zetapulse
Forum Newbie
Posts: 6
Joined: Mon Jan 04, 2010 9:14 pm

Re: Parameter refuses to store

Post by zetapulse »

Sooo this is probably a problem with my computer :/

I already tried restarting the MySQL & Apache servers, so I'll try restarting my PC & report back.
zetapulse
Forum Newbie
Posts: 6
Joined: Mon Jan 04, 2010 9:14 pm

Re: Parameter refuses to store

Post by zetapulse »

I've restarted my computer but am getting the same problem.

I'll keep my eyes open for any new posts that might help me, but in the meantime, thanks for your help.
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: Parameter refuses to store

Post by SimpleManWeb »

I doubt this will solve it but it's worth a try.

The following MySQL insert statement is more correct, give it a try:

Code: Select all

 
    Insert into `album` (`Name`,`Date`,`accountNo`) values ('".$talbum."','".$Date."','".$No."')
 
Like I said, I doubt that will fix it but it's the only thing I can see that could possibly be the problem.
zetapulse
Forum Newbie
Posts: 6
Joined: Mon Jan 04, 2010 9:14 pm

Re: Parameter refuses to store

Post by zetapulse »

Nope, didn't help. But here's a funny thing:

Disregarding my website's function, I went on & made a different-valued "cust" (the value stored in "accountNo") & started making the same MySQL entries with it. It's working seamlessly :banghead: I signed out & logged back in as the older "cust" &, well, the problem persists.
Post Reply