New web host, php form not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mricketts
Forum Newbie
Posts: 2
Joined: Fri Dec 20, 2013 5:53 pm

New web host, php form not working

Post by mricketts »

I changed web hosting companies and now a php form that was working is no longer working. I haven't been able to figure out what the problem is. The form is a simple text input form that adds the text to a database. Every time the user inserts text with a comma, an error occurs. Below is the code for the form. Any help is much appreciated.

Code: Select all

<!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></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php require_once('inc/header.html'); ?>
<?php require_once('../Connections/websitedatabase.php'); ?>

<?php
if (isset($_POST['note'])):

  $note = $_POST['note'];
  $name = $_POST['name'];
  $id = $_POST['id'];
  $sql = "UPDATE presidentnotes SET
          note='$note',
          name='$name'
          ";
  if (@mysql_query($sql)) {
    echo '<p>The note has been updated.</p>';
  } else {
    echo '<p>Error updating note. Details: ' .
        mysql_error() . '</p>';
  }
?>
<?php
else: 
  $presidentnotes = @mysql_query(
      "SELECT note, name FROM presidentnotes ");
  if (!$presidentnotes) {
    exit('<p>Error fetching note details: ' .
        mysql_error() . '</p>');
  }
  $presidentnotes = mysql_fetch_array($presidentnotes);
  $note = $presidentnotes['note'];
  $name = $presidentnotes['name'];

  $note = mysql_real_escape_string($note);
  $name = mysql_real_escape_string($name);
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h1>President's Note on hompage - Edit5</h1>

<label>Note:<br /> 
  <textarea name="note" cols="100" rows="12"><?php echo $note; ?></textarea>
</label><br />
<label>Name:<br /> <input name="name" type="text" value="<?php echo $name; ?>" size="40" /></label><br />
<input type="hidden" name="id" value="<?php echo $id; ?>" />
<input type="submit" value="SUBMIT" /></p>
</form>

<p>
  <?php endif; ?>

<p>&nbsp;</p>
</body>
</html>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: New web host, php form not working

Post by Celauran »

mricketts wrote:Every time the user inserts text with a comma, an error occurs.
Could you be more specific?
mricketts wrote:

Code: Select all

if (@mysql_query($sql)) {
Don't do that. mysql_query and all mysql_ functions are deprecated. Also, using @ there suppresses errors, making it difficult to see what's going wrong.
phpdeveloper1
Forum Newbie
Posts: 19
Joined: Tue Aug 12, 2014 6:13 am
Location: Chennai, India

Re: New web host, php form not working

Post by phpdeveloper1 »

mricketts wrote:<?php require_once('../Connections/websitedatabase.php'); ?>
Has this file been updated with the new database credentials?
Chris, Php Developer and Programmer,
https://www.phpfreelanceprogrammer.com/
Post Reply