Jump to content

Why doesn't my INSERT query work?


3raser

Recommended Posts

<?php
include_once("includes/config.php");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><? $title; ?></title>
<meta http-equiv="Content-Language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
</head>
<body>

<div id="wrap">

<div id="header">
<h1><? $title; ?></h1>
<h2><? $description; ?></h2>
</div>

<? include_once("includes/navigation.php"); ?>

<div id="content">
<div id="right">
<h2>Create</h2>
<div id="artlicles">
<?php

if(!$_SESSION['user'])
{

        $username = $_POST['username'];
        $password = $_POST['password'];
        $name = $_POST['name'];
        $server_type = $_POST['type'];
        $description = $_POST['description'];

        if(!$username || !$password || !$server_type || !$description || !$name)
        {

        echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings! All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>";
        echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'>
       
        <option value='Any'>Any</option>
        <option value='PvP'>PvP</option>
        <option value='Creative'>Creative</option>
        <option value='Survival'>Survival</option>
        <option value='Roleplay'>RolePlay</option>
       
        </select></td></tr>
       
        <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40'></textarea></td></tr>";
        echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>";
        }
        elseif(strlen($password) < 
        {
        echo "Password needs to be higher than 8 characters!";
        }
        elseif(strlen($username) > 13)
        {
                echo "Username can't be greater than 13 characters!";
        }
        else
        {
                $check1 = $db->prepare("SELECT username,name FROM servers WHERE username = ? OR name = ? LIMIT 1");
                $check1->execute(array($username, $name));
               
                if($check1->rowCount() > 0)
                {
                        echo "Sorry, there is already an account with this username and/or server name!";
                }
                else
                {
                        $ip = $_SERVER['REMOTE_ADDR'];

                        $insertQuery = $db->prepare("INSERT INTO servers (id, username, password, name, type, description, ip, votes, beta) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
                        $insertQuery->execute(array(null, $username, $password, $name, $server_type, $description, $ip, 0, 1));

					if($insertQuery->errorInfo() > 0)
					{
						echo "Sorry, there was the following error:";
						print_r($insertQuery->errorInfo());
					}
					else
					{
                        echo "Server has been succesfully created!";
					}
                }
        }
       
}
else
{
        echo "You are currently logged in!";
}

?>
</div>
</div>

<div style="clear: both;"> </div>
</div>

<div id="footer">
<a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop
</div>
</div>

</body>
</html>

 

Whats wrong with that page? :/

Link to comment
Share on other sites

You need to ask specific questions about what you are trying to achieve and what's not working.  What error messages are you getting? What's not working? What have you done to rectify the problem?

 

I'm not getting any error messages. The data from the INSERT query near the bottom of the code just simply isn't doing it's job, basically not sending the data to the database. And I need help to figure out why.

Link to comment
Share on other sites

echo the query, and paste it into myAdmin or whatever you use.  See if it works.

 

Not to sure on how to echo a the query I'm using, since it uses two different lines of code to run it.

 

But I don't think there are any errors... :/  - errorInfo() doesn't report anything, so no need to check for more errors.

Link to comment
Share on other sites

So, it doesn't work, and you are sure it isn't a coding problem!

 

The next step I would suggest is to stab the server with an ice-pick.  Maybe you can get the little troll living inside that is stopping your script from executing properly.

 

;)

Link to comment
Share on other sites

So, it doesn't work, and you are sure it isn't a coding problem!

 

The next step I would suggest is to stab the server with an ice-pick.  Maybe you can get the little troll living inside that is stopping your script from executing properly.

 

;)

 

Er, I'm not trolling. I seriously can't get this code to work. And I don't know any way besides errorInfo() to debug this. Even when I do that, I receive no errors. If you don't want to contribute towards helping solve this, then please just leave this thread.

 

And it IS a coding problem.

Link to comment
Share on other sites

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.