Wolphie Posted October 5, 2007 Share Posted October 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72015-solved-module-form-creation/ Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 looks like your database connection didn't work, so $con isn't a valid resource. where is $con set? Quote Link to comment https://forums.phpfreaks.com/topic/72015-solved-module-form-creation/#findComment-362823 Share on other sites More sharing options...
GingerRobot Posted October 5, 2007 Share Posted October 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72015-solved-module-form-creation/#findComment-362824 Share on other sites More sharing options...
Wolphie Posted October 5, 2007 Author Share Posted October 5, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72015-solved-module-form-creation/#findComment-362827 Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2007 Share Posted October 5, 2007 The connection to the database is fully functional because creating a module specifically for the left dimension works. PHP disagrees. but i'd try what GingerRobot suggested: remove $con from you mysql_query() calls. Quote Link to comment https://forums.phpfreaks.com/topic/72015-solved-module-form-creation/#findComment-362830 Share on other sites More sharing options...
Wolphie Posted October 5, 2007 Author Share Posted October 5, 2007 Problem resolved. ($con was the problem). Thanks for all of your help. I may be back pretty soon since i'm attempting a rather large project on my own. (A mini content management system) Quote Link to comment https://forums.phpfreaks.com/topic/72015-solved-module-form-creation/#findComment-362835 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.