Jump to content

Php form will not send to db.


alexmark

Recommended Posts

Hi all

 

I have a form please see code and it will not send to db. each time I try it it sends back the error message that no information has been entered in form.

<?php
	if ( $_SESSION['logged_in'] ):
?>
    (1)
        <?php
	endif;
?>
    <?php
if(isset($_POST['formSubmit']))
{
	$errorMessage = "";

	if(empty($_POST['social'])) 
        {
		$errorMessage .= "<li>You forgot to enter a Social Media Platform!</li>";
	}
	if(empty($_POST['url'])) 
        {
		$errorMessage .= "<li>You forgot to enter a URL!</li>";
	}

        $varsocial = $_POST['formsocial'];
	$varurl = $_POST['formurl'];

	if(empty($errorMessage)) 
        {
		include '/dbc.php';

		$sql = "INSERT INTO social (id, social, url) VALUES (".
						PrepSQL($id) . ", " .
						PrepSQL($varsocial) . ", " .
						PrepSQL($varurl) . ") " ;
		mysql_query($sql);

		header("Location: thankyou.html");
		exit();
	}
}
            
    // function: PrepSQL()
    // use stripslashes and mysql_real_escape_string PHP functions
    // to sanitize a string for use in an SQL query
    //
    // also puts single quotes around the string
    //
    function PrepSQL($value)
    {
        // Stripslashes
        if(get_magic_quotes_gpc()) 
        {
            $value = stripslashes($value);
        }

        // Quote
        $value = "'" . mysql_real_escape_string($value) . "'";

        return($value);
    }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin Add social Media</title>
<link href="/csssheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<center><div style="width:785px">
<table td class="background1" valign="top" width="785px" colspan="1" border=0 cellpadding=0 cellspacing=0 align="center">
  <tr>
    <td width="100%"><center><br><a href= "../admin.php" class="creamlink11">Log Out</a></center></td>
  </tr>
  <td></td>
</table>
<?php
include("../menu/admin_menu.php")

?>

</td>
  </tr>
  <tr>
    <td bgcolor="#F6F6F6" height='1'></td>
</tr>

  <tr>
    <td >
<table width="785" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="785" bgcolor="#232B34" class="bodyfontred">


<table border=0 width='100%' cellspacing=0 cellpadding=0>
<tr>
<td valign="top" align=center>
</td>
</tr>
<tr>
<td align=center>
<center>
<img src="/images/linebreak.jpg" width="350" height="1">
</center>
       <?php
	    if(!empty($errorMessage)) 
	    {
		    echo("<p>There was an error with your form:</p>\n");
		    echo("<ul>" . $errorMessage . "</ul>\n");
            }
        ?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post" enctype="multipart/form-data">
<table>
<tr>
<td class="bodyfontwhite" align="right">
<label for='formsocial'>Social Media Name</label></td>
			<td><input  type="text" name="formsocial"  size="40" maxlength="100" value="<?=$varsocial;?>"/></td>
<td><label for='formurl'>URL</label></td>
<td><input type="text" name="formurl"  size="40" maxlength="250" value="<?=$varurl;?>"/></td>
</tr>
<tr>
</tr>
</table>
<center><input type="submit" name="formSubmit" value="Submit"/></center>
</form>
<tr><td class=bodyfontwhite>
<center><b><a name='help'></a>H E L P</b></center><br>
<p align=justify>To Add a Social Net Work type the text you wish to display. Add the URL address Then click the Submit button.
</p>
</td></tr></table>
	</td>		
      </tr>
    </table>
	</td>		
      </tr>
 <tr>
  <center><td width="785" align="center" bgcolor="#000000" class="bodyfont" height="40"><a href="http://www.improvedinternetmarketing.com/" title="Improved Internet Marketing">Web Design</a> by Improved Internet Marketing</TD></center>
 </tr>
    </table>
    </div></center>
</body>
</html>

Link to comment
Share on other sites

Missing form infront of your post Vars

 

	if(empty($_POST['social'])) 
        {
		 $errorMessage .= "<li>You forgot to enter a Social Media Platform!</li>";
	 }
	 if(empty($_POST['url'])) 
        {
		 $errorMessage .= "<li>You forgot to enter a URL!</li>";
	 }

	if(empty($_POST['formsocial'])) 
        {
		 $errorMessage .= "<li>You forgot to enter a Social Media Platform!</li>";
	 }
	 if(empty($_POST['formurl'])) 
        {
		 $errorMessage .= "<li>You forgot to enter a URL!</li>";
	 }

Link to comment
Share on other sites

lordshoa you are the star!

 

I have another question though now that it submits correctely. How do i echo out a statment saying that it has entered the info correctely in the db?

 

Would the following work?

 

	mysql_query($sql);

		// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Successful";
}

else {
echo "ERROR";
}


	}
}

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.