Jump to content

Code Won't Work Anymore?


Recommended Posts

<?php
require "global.php";

if ($_POST)
{
$name = $_POST['name'];
$data = sprintf("INSERT INTO forums VALUES (DEFAULT,'$name')");
mysql_query($data);
$fid = mysql_insert_id();
header( 'Location: viewforum.php?fid='.$fid);
exit;
}

echo '
<form action="" method="POST">
<table>
<tr><td>Forum Name: </td><td><input name="name" /></td></tr>
</table>
<input type="submit" value=" Add Forum " />
</form>';
?>

 

This added forums whenever I made one to my MySQL database in the table "forums"

For whatever reason, whenever I make a forum, it makes it end in ".php?fid=0" and does not create the forum on the database.

 

Any ideas?  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/257257-code-wont-work-anymore/
Share on other sites

This code is naive and never checks the result of the query to determine if it actually succeeded.  If I was placing a bet, my bet would be that a connection to the database is not occurring and this is why it not longer functions.

 

I have a link in my signature to a page that describes how to check database results properly for mysql.

What is the database structure.  When you do an insert query without specifying columns as you are doing, then the column count must exactly match the values list. 

 

insert into table foo values ('a', 'b') 

 

By specifying a column list you don't have that issue when omitting values for certain columns:

 

insert into foo (col1, col3) values ('col1 value', 'col3 value')

 

 

 

-- phpMyAdmin SQL Dump
-- version 3.4.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 18, 2012 at 02:17 PM
-- Server version: 5.1.56
-- PHP Version: 5.2.9

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `(DATABASE)`
--

-- --------------------------------------------------------

--
-- Table structure for table `forums`
--

CREATE TABLE IF NOT EXISTS `forums` (
  `fid` int(10) NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `descs` text,
  PRIMARY KEY (`fid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

--
-- Dumping data for table `forums`
--

INSERT INTO `forums` (`fid`, `name`, `descs`) VALUES
(1, 'Requests', 'Have a request for TG? Forums, graphics, and anything else.');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

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.