Page 1 of 1

Php converting an $_POST

Posted: Sat Nov 20, 2010 5:05 am
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]

Re: Php converting an $_POST

Posted: Sat Nov 20, 2010 5:32 am
by tabutcher
hello

have you connected to the database?

Re: Php converting an $_POST

Posted: Sat Nov 20, 2010 5:41 am
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

Re: Php converting an $_POST

Posted: Sat Nov 20, 2010 7:03 am
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"));

Re: Php converting an $_POST

Posted: Sat Nov 20, 2010 10:14 am
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

Re: Php converting an $_POST

Posted: Sat Nov 20, 2010 10:24 am
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.

Re: Php converting an $_POST

Posted: Sat Nov 20, 2010 10:29 am
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!