Php converting an $_POST

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
m1nistry
Forum Newbie
Posts: 11
Joined: Sat Nov 20, 2010 4:55 am

Php converting an $_POST

Post by m1nistry »

Hello Guys, i need your help on a code cuz i can't find the error...let me show you...

Well i created an form with POST action. I am tring to take the data from one text field with input type into varriable to run an mysql_query and from ex album name find the album id witch is in the same record/table etc... let me show you the codes.

Form Action

Code: Select all

<form action='upload.php' method='post'
enctype='multipart/form-data'>
The Form input

Code: Select all

Album Name:<input type='text' name='albumname' maxlength='150'>
Then i take the "name='albumname'" and i add a variable on it...

Code: Select all

$albumname = $_POST['albumname'];
And for last i give the mysql_querys

Code: Select all

//find the albumid of the Name Album that was given in the form
$albumid = mysql_query("SELECT id FROM albums WHERE name = $albumname");

// insert The file record into the Database
$create = mysql_query("INSERT INTO items VALUES ('','$id','$albumid','i','$photoname','$photodescription','$location')") or die("Error Uploading");
So When i run the script...the error that i get is into $create varieble where i run a query at $albumid is giving 0 and not the data i am giving from form...

If any one can help...please!
(sorry for my not perect eng tho)
[/b]
tabutcher
Forum Newbie
Posts: 20
Joined: Fri Aug 21, 2009 7:10 am

Re: Php converting an $_POST

Post by tabutcher »

hello

have you connected to the database?
m1nistry
Forum Newbie
Posts: 11
Joined: Sat Nov 20, 2010 4:55 am

Re: Php converting an $_POST

Post by m1nistry »

tabutcher wrote:hello

have you connected to the database?
Ofc Mate...That's not the problem for sure...the query workin just is not giving the right data...

Plus i tryed to echo the results before go thru the 2nd query and i got Recurce#5 ... not even close at my inputed data
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Php converting an $_POST

Post by Celauran »

m1nistry wrote:

Code: Select all

//find the albumid of the Name Album that was given in the form
$albumid = mysql_query("SELECT id FROM albums WHERE name = $albumname");
There's the problem. You're assigning a mysql result to $albumid, rather than the value contained in said result.

Try this:

Code: Select all

list($albumid) = mysql_fetch_row(mysql_query("SELECT id FROM albums WHERE name = $albumname"));
m1nistry
Forum Newbie
Posts: 11
Joined: Sat Nov 20, 2010 4:55 am

Re: Php converting an $_POST

Post by m1nistry »

Celauran wrote:
m1nistry wrote:

Code: Select all

//find the albumid of the Name Album that was given in the form
$albumid = mysql_query("SELECT id FROM albums WHERE name = $albumname");
There's the problem. You're assigning a mysql result to $albumid, rather than the value contained in said result.

Try this:

Code: Select all

list($albumid) = mysql_fetch_row(mysql_query("SELECT id FROM albums WHERE name = $albumname"));
I Tried it...nothing

Storing the data with values "0"
And Giving That Warning

Code: Select all

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in ... line 47
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Php converting an $_POST

Post by Celauran »

m1nistry wrote:

Code: Select all

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in ... line 47
Which means your query is failing and returning false. Forgot to specify quotes around $albumname.

Code: Select all

list($albumid) = mysql_fetch_row(mysql_query("SELECT id FROM albums WHERE name = '$albumname'"));
If that still returns false, then your query itself is no good or you're trying to get an album name that isn't in the DB.
m1nistry
Forum Newbie
Posts: 11
Joined: Sat Nov 20, 2010 4:55 am

Re: Php converting an $_POST

Post by m1nistry »

Celauran wrote:
m1nistry wrote:

Code: Select all

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in ... line 47
Which means your query is failing and returning false. Forgot to specify quotes around $albumname.

Code: Select all

list($albumid) = mysql_fetch_row(mysql_query("SELECT id FROM albums WHERE name = '$albumname'"));
If that still returns false, then your query itself is no good or you're trying to get an album name that isn't in the DB.
Worked :) ty mate i was searching for that error fix like all day!
Post Reply