Jump to content

Database query isn't working.


mischievousx3

Recommended Posts

I'm having a problem with adding icon/avatar to my database..this is a submit form where I just submit the avatar url. I don't know how to change the submit link from avatar_add.php?mode=submit to index.php?mode=submit&x=avatar_add.

http://www.graphics.allmerk-noplay.com/index.php?x=avatar_add

 

 

<?php
$host =""; // host name
$user =""; // user
$pass =""; // password
$dbase =""; // database name

// connect to the server
mysql_connect("$host","$user","$pass");
// and select the database
mysql_select_db($dbase);

$mode=$_GET["mode"]; // get the mode
$QUERY_STRING = 'x=avatar_add';

if(!isset($mode) || empty($mode)) // if mode is empty, switch to case index
{
$mode='index';
}

switch($mode)
{

case 'index'; // displays the form
?>


<form method="post" action="avatar_add.php?mode=submit">
Avatar URL:<br>
<input type="text" name="avatar_url" size="30"><br><br>
<input type="submit" value="Submit">


<?php
break;

case 'submit'; // form processing mode

$avatar_url=$_POST["avatar_url"];

// check for empty fields
if(empty($avatar_url))

{
echo "Error! Please go back and fill in all the required fields!";
// if you have a footer include, insert it before the die statement
die; // stops the script from executing the rest of the code
}

// let's get the date in YYYY-MM-DD format
$date = date("Y-m-d");

$query="INSERT into icons_db (id,avatar_url) VALUES ('','$avatar_url')";
$result=mysql_query($query) or die ("Couldnot execute query: $query." . mysql_error());

if($result) // if mysql query successful
{ echo "Thank you! The avatar has been added to or database."; }

break;

}

?> 

Link to comment
https://forums.phpfreaks.com/topic/230932-database-query-isnt-working/
Share on other sites

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.