Jump to content

[SOLVED] Why isn't this working? Am I missing something?


Recommended Posts

Hello mates it is I again. Seems my n00bness is at work again. I have the following code written and it simply is not working. Seeing if you lads could be of some help to myself.

 

My php file for the content management:

<!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=UTF-8" />
<title>Dr. Michael D. Doyle | Payment Information</title>

<LINK REL=StyleSheet HREF="content_management.css" TYPE="text/css" />

<script defer type="text/javascript" src="pngfix.js"></script>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body>

<div id="container">

    <h3>Michael D. Doyle Content Management System</h3>
        
        <div id="form_wrapper"> 
                  
                <form action="put.php" method="post">
                <div><label for="index">Homepage</label><textarea name="index" rows="15" cols="70"> </textarea></div>
                <div><label for="mot">Meet Our Team</label><textarea name="mot" rows="15" cols="70"> </textarea></div>
                <div><label for="pf">Patient Forms</label><textarea name="pf" rows="15" cols="70"> </textarea></div>
                <div><label for="fi">Financial Information</label><textarea name="fi" rows="15" cols="70"> </textarea></div>
                <div><label for="loc">Locations</label><textarea name="loc" rows="15" cols="70"> </textarea></div>
                <div><label for="con">Contact</label><textarea name="con" rows="15" cols="70"> </textarea></div>
                <div><label for="ms">Mission Statement</label><textarea name="ms" rows="15" cols="70"> </textarea></div>
                <div><label for="dis">Disclaimer</label><textarea name="dis" rows="15" cols="70"> </textarea></div>          
                <div class="actions"><input type="submit" input name="submit" value="Submit Content" id="add" class="submit"/></div>
                </form>
            
        </div>
</div>
</body>
</html>

 

Now my put.php that will process these inputs and place them in the mySQL database:

<?php
    if(isset($_POST['add']))
    {
    include 'config.php';
    include 'opendb.php';
                  
    $index = $_POST['index'];
$mot = $_POST['mot'];
$pf = $_POST['pf'];
$fi = $_POST['fi'];
$loc = $_POST['loc'];
$con = $_POST['con'];
$ms = $_POST['ms'];
$dis = $_POST['dis'];
                                      
    $query = "INSERT INTO cms (index, team, form, financial, locations, contact, mission, disclaimer) VALUES ('$index', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')";
    mysql_query($query) or die('Error, insert query failed');
        
    include 'closedb.php';
    echo "Update complete.";
   	}
?>

 

Here are my included php files that I use to connect to the database.

opendb:

<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>

 

config:

<?php 
$dbhost = 'localhost';
$dbuser = 'drmdoyle_user';
$dbpass = 'password is hidden';
$dbname = 'drmdoyle_content';
?>

 

closedb:

<?php mysql_close($conn); ?>

 

I am sure it is something small but my eyes are tired and I need another pair of eyes to look at it for me. Any help would be delightful. Cheers!

It was reporting this:

$query = "INSERT INTO cms (index, team, form, financial, locations, contact, mission, disclaimer) VALUES ('$index', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')";
    mysql_query($query) or die('Error, insert query failed');

 

Error, insert query failed

 

Now it does nothing.

 

www.drmdoyle.com/content_management.php for testing

RestlessThoughts is right... your checking to see if $_POST['add'] is set, but it is never set because there is no field with name add, its id is add, but not its name... so change your code to say $_POST['submit'] or change your form from name="submit" to name="add".... try it...let us know what happens...

New code. Still doesn't work :(

 

<!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=UTF-8" />
<title>Dr. Michael D. Doyle | Payment Information</title>

<LINK REL=StyleSheet HREF="content_management.css" TYPE="text/css" />

</head>

<body>

<div id="container">

    <h3>Michael D. Doyle Content Management System</h3>
        
        <div id="form_wrapper">         
                <form method="post" action="put.php">
                <div><label for="index">Homepage</label><textarea name="home" rows="15" cols="70"> </textarea></div>
                <div><label for="mot">Meet Our Team</label><textarea name="mot" rows="15" cols="70"> </textarea></div>
                <div><label for="pf">Patient Forms</label><textarea name="pf" rows="15" cols="70"> </textarea></div>
                <div><label for="fi">Financial Information</label><textarea name="fi" rows="15" cols="70"> </textarea></div>
                <div><label for="loc">Locations</label><textarea name="loc" rows="15" cols="70"> </textarea></div>
                <div><label for="con">Contact</label><textarea name="con" rows="15" cols="70"> </textarea></div>
                <div><label for="ms">Mission Statement</label><textarea name="ms" rows="15" cols="70"> </textarea></div>
                <div><label for="dis">Disclaimer</label><textarea name="dis" rows="15" cols="70"> </textarea></div>          
                <div class="actions"><input type="submit" input name="submit" value="Submit Content" class="submit"/></div>
                </form>            
        </div>
</div>
</body>
</html>

 

put.php:

 

<?php
    if(isset($_POST['submit']))
    {
    include 'config.php';
    include 'opendb.php';
                  
    $home = $_POST['home'];
$mot = $_POST['mot'];
$pf = $_POST['pf'];
$fi = $_POST['fi'];
$loc = $_POST['loc'];
$con = $_POST['con'];
$ms = $_POST['ms'];
$dis = $_POST['dis'];
                                      
    $query = "INSERT INTO cms (home, team, form, financial, location, contact, mission, disclaimer) VALUES ('$home', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')";
    mysql_query($query) or die('No worky');
        
    include 'closedb.php';
    echo "Worky!";
   	}
?>

<div class="actions"><input type="submit" input name="submit" value="Submit Content" class="submit"/></div>

 

into

 

<div class="actions"><input type="submit" name="submit" value="Submit Content" class="submit"/></div>

 

<div class="actions"><input type="submit" input name="submit" value="Submit Content" class="submit"/></div>

 

into

 

<div class="actions"><input type="submit" name="submit" value="Submit Content" class="submit"/></div>

 

Changed it. Close, but no cigar. Still giving me the error that it can't insert into the table. Any other advice anyone has? I absolutely cannot think of what it is that I am doing wrong. I have ran over this code a million times.

You know pritnig out the actual error message may help.

 

<?php
    if(isset($_POST['submit']))
    {
    include 'config.php';
    include 'opendb.php';
                  
    $home = $_POST['home'];
   $mot = $_POST['mot'];
   $pf = $_POST['pf'];
   $fi = $_POST['fi'];
   $loc = $_POST['loc'];
   $con = $_POST['con'];
   $ms = $_POST['ms'];
   $dis = $_POST['dis'];
                                      
    $query = "INSERT INTO cms (home, team, form, financial, location, contact, mission, disclaimer) VALUES ('$home', '$mot', '$pf', '$fi', '$loc', '$con', '$ms', '$dis')";
    mysql_query($query) or die('No worky: ' . mysql_error());
        
    include 'closedb.php';
    echo "Worky!";
      }
?>

 

mysql_error would help you. My bet is you have a ' single quote in your data coming in and mysql_real_escape_string that data will probably fix it.

Like this:

 

<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname) or die ('Error connecting to mysql');
?>

 

Did you try it?

 

Yes, like that.

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.