/    Sign up×
Community /Pin to ProfileBookmark

New web host, php form not working

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=php]<!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>[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@KryDosAug 30.2014 — Wow. There is 100% SQL-injection. Please do not use old-mysql functions. You can use PDO or MySQLi (I like PDO).

Using PDO you can bind parameters to your query and pdo automatically will remove all insecure symbols.
Copy linkTweet thisAlerts:
@rootAug 30.2014 — I would say that your database connection will likely be the issue... also...

mysql_query($sql) is missing a parameter, your $link to your database that you get from your connection.

suggest that you post your database connection file but edid out the username and password details!

You did take a backup to upload to the new server?

As stated, mysqli_ over mysql_ functions

you also may have to look at your php.ini settings to ensure that php is operational and your able to execute PHP scripts.
Copy linkTweet thisAlerts:
@NogDogAug 30.2014 — ...

mysql_query($sql) is missing a parameter, your $link to your database that you get from your connection.

...[/QUOTE]


It's optional in the old mysql_*() functions -- it will pick the last(?)/only connection if there is one.


Anyway, while I would hope you would migrate away from the old and deprecated mysql extension as the others have recommended, if you stay with this code, you should be using mysql_real_escape_string() to sanitize values [i]before[/i] using them in mysql_query(), not [i]afterwards[/i] for data retrieved from the DB.
Copy linkTweet thisAlerts:
@ginerjmAug 30.2014 — Your update query updates every record in the table?
Copy linkTweet thisAlerts:
@GravyAug 31.2014 — Ignoring all the bad code...

Perhaps in the cpanel (assumption) you added a user, added the database, but didn't give the user permission to access/modify the database?
×

Success!

Help @mricketts spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...