Jump to content

Problems with extracting values from a row...


ack

Recommended Posts

I am trying to extract field data from a specific row,

 

Here is my code:

 

    $query = "SELECT * FROM music WHERE title = '%$selected%'";

 

    $musicresult = mysql_query($query) or die ("Couldn't execute query.");

 

    $row = mysql_fetch_array($musicresult);

 

      /* extract the contents of the row */

    Line 98 extract($row);

   

echo $title." "."<BR>";

    echo $select."<BR>";

    /* set contents of selected to 1  */

$selectval = $select;

++$selectval ;

 

    echo $selectval."<BR>";

/* Put the data into the database */

//$query= "UPDATE music SET select=$selectval WHERE title=$selected";

//$result = mysql_query($query) or die ("could not save new data!");

 

 

 

 

Here is the error message:

 

 

Warning: extract() [function.extract]: First argument should be an array in /home/content/a/c/k/acksfaq/html/theackshow/THANKYOU.PHP on line 98

 

The two echo statements that follow line 98 do not generate an output

 

About the only thing that is different with is table compared with a table that this code works with is the fact that this table (music) is not indexed.

 

What the heck am I doing wrong??

 

Thanks,

 

Ack

 

 

 

 

Link to comment
Share on other sites

Just because a query executes without any errors, does not mean that it matched any rows. You should use mysql_num_rows to find out if there are any rows in the result set before you attempt to fetch the data from the result set.

 

If you echo the $query variable, you will likely be able to see why it is not matching anything in your table (I suspect that $selected is either empty or does not match any title.)

Link to comment
Share on other sites

Thanks,  PFMaBiSmAd and wigwambam!

 

I tried "LIKE" instead of "=" and was able to pull the field contents in the row.  I guess that somehow a leading or trailng space manged to get appended to the string that I was looking for because the contents of the title field was extracted from the same table then passed from a dynamic php page to this page using URL parameters...

 

So, I have the data, now I want to increment the content of a counter field (to track how many times this particular row of data has been selected) and store it back into the table...

 

The incrementing is working but the I can't seem to manage the simple task of storing the incremented variable back into to table...

 

 

$query= "UPDATE music SET select=$selectval, WHERE title=$title";

$selectresult = mysql_query($query) or die ("could not save new data!");

 

So just how moronic am I???

 

I've slept a few times since  I last monkeyed with php...

 

Thanks in advance!

Link to comment
Share on other sites

as $query is invalid SQL syntax but you don't get the die() message, I suspect either error reporting is turned off or the code below is never reached:

 

$query= "UPDATE music SET select=$selectval, WHERE title=$title";
$selectresult = mysql_query($query) or die ("could not save new data!");

Link to comment
Share on other sites

as $query is invalid SQL syntax but you don't get the die() message, I suspect either error reporting is turned off or the code below is never reached:

 

$query= "UPDATE music SET select=$selectval, WHERE title=$title";
$selectresult = mysql_query($query) or die ("could not save new data!");

 

 

I do get the die("could not save new data!" ) when the code executes.

 

I have discovered that sample code found at various PHP sites tend to lack a bit when it comes to accuracy.  Thus it is often hard to understand what the proper syntax is required for proper execution.  I end up playing for hours with the code until I somehow hit upon the solution.  Very frustrating...

 

Assuming that the query contains invalid SQL syntax, what is that syntax error?  Alternatively, is there a way to debug this problem? 

 

 

By the way,...

 

This project's purpose  is to create a music request page for an Internet radio show that I have.  A plug-in has been written for winamp, but it cannot be easily adapted to other similar applications.  A PHP-based clone would be useful for other "DJs" wanting to offer request funtionality without having to sacrifice the ability to use the audio mixing software of their choice.

 

Bonus:

 

It makes for a good introduction to PHP!

 

 

 

Humbly submitted,

 

Ack

Link to comment
Share on other sites

You can use mysql_error() to find out why your query is failing. You can also look at it.

 

You have an extra comma after $selectval, that wasn't present in the first post. You also need single-quotes around the string data values in the query.

 

Well, I removed the extra comma and I tried all the variations that i could think of with single quotes including "%" as seen in the original post's $query string an all I got was the die() message - could not save new data!

 

Also, I was unable to see any results with

 

echo mysql_errno($query) ;

 

 

Placed after the

 

$query= "UPDATE music SET select=$selectval, WHERE title=$title";

$selectresult = mysql_query($query) or die ("could not save new data!");

 

Very puzzling...

 

Link to comment
Share on other sites

Ken!

 

Thanks!

 

Your snippet suggestion revealed - in an obtuse way - the problem with the query along with the fact that the variable content is correct:

 

Problem with the query: UPDATE music SET select='1' WHERE title='Free Xone Janet Jackson The Velvet Rope Soul and R&B.wma'

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

 

'select='1' WHERE title='Free Xone Janet Jackson The Velvet Rope Soul and R&B.wma' at line 1

 

(Sorry about the choice of the song title.  For some reason I typed in "Jackson" and clicked on the first title that appeared  :-[  )

 

The at line 1 is puzzling...

 

<?php                                line 1

session_start();              line 2

?>                                      line 3

....

 

 

Gotta get to work.  I'll check with the hosting company and find out the version of PHP that is running.

 

Thanks!

Link to comment
Share on other sites

The 'at line 1' part of the sql error message refers to line 1 of the query (queries can be formed with multiple lines of sql.)

 

The part of the query that is called out in - the right syntax to use near 'select is where the error is occurring at.

 

Select is a reserved mysql keyword, as in SELECT * FROM your_table.... Either rename your column to something else or you must enclose it in back-ticks `` every time you use it in a query.

Link to comment
Share on other sites

kenrbnsn AND PFMaBiSmAd:

 

You are the BEST!

 

You have been patient with a guy who, in a matter of 8 months, had a great deal of "learnin'" leak out of his noggin!

 

Naming a field "select" is pretty stupid.

 

That was the biggest goof that i made with this project.  Many smaller ones preceeded it.

 

All of you helped me get on the right track - which I appreciate very much!

 

If any of you get the offroading bug and buy a Suzuki Samurai or Sidekick (know by other names incluiding Asuna, Tracker and Vitara), feel free to stop by http://www.acksfaq.com for help!

 

Most Sincerely,

 

Ack

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.