Jump to content

[SOLVED] Module Form Creation


Wolphie

Recommended Posts

Hi, i've been having some trouble with my script i've created below.

I'm not quite sure on how to correct it.

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<link rel="stylesheet" href="styles/style.css" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>

<title>CMPS - Modules</title>


</head>
<body>


<?php

require("includes/config.php");


$var = $_GET['do'];

switch($var)
{

default:

	?>

	<a href="modules.php?do=create">Create New Module</a><br />
	<a href="modules.php?do=edit">Edit Module</a><br />
	<a href="modules.php?do=delete">Delete Module</a><br />

	<?

break;


case "create":
	@include("create");

	?>

	<table cellpadding="0" cellspacing="0" border="0" align="center" class="create">
	<form action="?do=createnew" method="post">
	<tr><td>
	Table:
	</td><td>
	<select name="selections">
		<option value="left">Left</option>
		<option value="center">Center</option>
	</select>
	</td></tr>
	<tr><td>
	Title:
	</td><td>
	<input type="text" maxlength="100" size="25" name="title" />
	</td></tr>
	<tr><td>
	Content:
	</td><td>
	<textarea cols="20" rows="5" name="content"></textarea>
	</td></tr>
	<tr><td> 

	</td><td>
	<input type="submit" value="Submit" style="font-family: Tahoma; font-size: 11px;" />
	</td></tr>
	</form>
	</table>

	<?

break;


case "createnew":
	@include("createnew.php");

	function selectTable()
	{
		$var = $_REQUEST['selections'];
		$title = $_POST['title'];
		$content = $_POST['content'];


		switch($var)
		{
			case "left":

				$head = '<tr><td width="20%" class="modhead" width="500" height="35">';
				$body = '<tr><td width="20%" class="modbody" width="500" height="35">';

				$sql = sprintf("INSERT INTO `left` (title, content, head, body) VALUES( '%s', '%s', '%s', '%s' )",
    				mysql_real_escape_string($title),
    				mysql_real_escape_string($content),
				mysql_real_escape_string($head),
				mysql_real_escape_string($body)
				);

				if(mysql_query($sql, $con))
				{
					echo 'Module Created. [<a href="index.php">Home</a>]';
				}
				else
				{
					die("Error: " . mysql_error());
				}


			break;

			case "center":

				$head = '<tr><td width="20%" class="cmodhead" width="180" height="35">';
				$body = '<tr><td width="20%" class="cmodbody" width="180" height="35">';

				$sql = sprintf("INSERT INTO `center` (title, content, head, body) VALUES( '%s', '%s', '%s', '%s' )",
    				mysql_real_escape_string($title),
    				mysql_real_escape_string($content),
				mysql_real_escape_string($head),
				mysql_real_escape_string($body)
				);

				if(mysql_query($sql, $con))
				{
					echo 'Module Created. [<a href="index.php">Home</a>]';
				}
				else
				{
					die("Error: " . mysql_error());
				}

			break;

			default:

				echo "Table does not exist. Please select a table from the drop down selection box.";

			break;	

		}
	}

	selectTable();

break;

}


mysql_close($con);
?>



</body>
</html>

 

 

Here is the error message:

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\xampp\htdocs\dev\dave\modules.php on line 127

 

Thanks if anybody can help. I appreciate it.

Link to comment
https://forums.phpfreaks.com/topic/72015-solved-module-form-creation/
Share on other sites

Well, as it says, the argument you passed to the mysql_query() fuction is not a valid link resource. Therefore, something has gone wrong with your connection to the database. Do you have any error checking in config.php?(which i presume contains the database connection?)

 

Also, the link parameter is actually optional. You might not need it anyway.

 

 

The $con variable is set inside the config.php file. The connection to the database is fully functional because creating a module specifically for the left dimension works. I'm having trouble using the drop down selection box to define which dimension to input into the database.

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.