MySql query not running in php script

Problems with the Windows version of XAMPP, questions, comments, and anything related.

MySql query not running in php script

Postby wastvedt » 11. August 2004 19:47

Hi!
My last question was answered so quickly and so well that I thought I'd put this one out there too. I'm not sure that I provided enough info, so if you need more, just let me know. The following code is taken from a form page that handles itself. The first conditional ckecks that the required fields have been filled out. The page has already connected to the database. When I run the script the first query doesn't work, and so $tid always equals 0. I tried putting it directly into MySql using phpMyAdmin with strings instead of variables, and it ran fine.
Code: Select all
   if ($sc && $t && $d) {  // If everything has been filled out correctly.
      // Add the record to the database.
      $query = "INSERT INTO photo_titles (title, description, photo_date) VALUES ( $t, $c, $d )";
      
      $result = @mysql_query ($query); // Run the query
      $tid = @mysql_insert_id(); // Get the photo_title_pk
      
      if ($tid > 0) {  // If everything worked
         
         // Creat a photos entry for each of the photos sub categories

Thanks for any help anyone can provide,
wastvedt :D
wastvedt
 
Posts: 6
Joined: 09. August 2004 19:34
Location: Pennsylvania, US

Postby Wiedmann » 11. August 2004 20:14

Code: Select all
$result = @mysql_query ($query);


Replace with:
Code: Select all
$result = mysql_query($query)
    or die('Query failed: '.mysql_error());

What happens?
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Just figured it out

Postby wastvedt » 11. August 2004 21:38

I just sat down to look at your reply, and tried one more thing before I did, and it worked! In the INSERT INTO query, I enclosed each of the variables ($t, $c, and $d) in single quotes, and for some reason it ran like a charm! Thanks anyways!
wastvedt :D
wastvedt
 
Posts: 6
Joined: 09. August 2004 19:34
Location: Pennsylvania, US


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 78 guests