Jump to content

php/sql problem


Imaulle

Recommended Posts

Hello,

 

The following code does not return any errors, but nothing is ever inserted into the database. I'm sure it's something super simple :\

 

 

$result = mysql_query("SELECT filename FROM p_headerimages ORDER BY ordernum") or die(mysql_error());
$newcount = count($result) +1;
$query2 = "INSERT INTO `psitez_wrdp12`.`p_headerimages` (`filename`, `ordernum`) VALUES (\''$file_name'\', \''$newcount'\');";
$result2= mysql_query($query2);

 

 

 

Here is the database stuff

 

--
-- Table structure for table `p_headerimages`
--

CREATE TABLE IF NOT EXISTS `p_headerimages` (
  `filename` varchar(64) NOT NULL,
  `ordernum` tinyint(3) unsigned NOT NULL,
  PRIMARY KEY  (`ordernum`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

--
-- Dumping data for table `p_headerimages`
--

INSERT INTO `p_headerimages` (`filename`, `ordernum`) VALUES
('slideshow.jpg', 1),
('slideshow1.jpg', 2),
('slideshow2.jpg', 3),
('slideshow3.jpg', 4),
('slideshow4.jpg', 5),
('slideshow5.jpg', 6),
('slideshow6.jpg', 7);

 

 

 

 

any ideas?? Thank you for your help!

 

Link to comment
https://forums.phpfreaks.com/topic/235969-phpsql-problem/
Share on other sites

try this

$result = mysql_query("SELECT filename FROM p_headerimages ORDER BY ordernum") or die(mysql_error());
$newcount = count($result) +1;
$query2 = "INSERT INTO `psitez_wrdp12`.`p_headerimages` (`filename`, `ordernum`) VALUES ('$file_name', '$newcount')";
$result2= mysql_query($query2) or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/235969-phpsql-problem/#findComment-1213110
Share on other sites

When I set ordernum as 'auto-increment' and then do just

 

$query2 = "INSERT INTO p_headerimages (`filename`) VALUES ('$file_name')";

 

 

it works, but then the number that gets put into ordernum is not what I want it to be. Do I need to add another value like just id or something?

Link to comment
https://forums.phpfreaks.com/topic/235969-phpsql-problem/#findComment-1213122
Share on other sites

$result = mysql_query("SELECT filename FROM p_headerimages ORDER BY ordernum") or die(mysql_error());
$newcount = mysql_num_rows($result)+1;
$query2 = "INSERT INTO p_headerimages (`filename`, `ordernum`) VALUES ('$file_name', '$newcount')";
$result2= mysql_query($query2) or die(mysql_error());

 

 

This is now working. Except the database does not seem to have a key or nothing is sorted. Do I need to worry about that?

Link to comment
https://forums.phpfreaks.com/topic/235969-phpsql-problem/#findComment-1213127
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.