Page 1 of 1

Parameter refuses to store

Posted: Mon Jan 04, 2010 9:26 pm
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.

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 9:30 pm
by manohoo
Show the structure of table "album"

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 9:37 pm
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.

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 9:41 pm
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.

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 9:51 pm
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.

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 9:58 pm
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

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 10:00 pm
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.

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 10:11 pm
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.

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 10:20 pm
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.

Re: Parameter refuses to store

Posted: Mon Jan 04, 2010 10:28 pm
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.