Jump to content

Why wont my table update? :|


BrianM

Recommended Posts

Here is my code:

 

<!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=iso-8859-1" />
<title>Examples
</title>
</head>

<?php

if(!isset($_POST['text'])) {
echo "<form action='/examples/index.php' method='post'>";
echo "<input type='text' name='text'>";
echo "<input type='submit'>";
echo "</form>";
} else {
$text = mysql_escape_string($_POST['text']);
$mysql_connect = mysql_connect('localhost', 'brian', '');

mysql_query("UPDATE `08-12345-1` SET Req=($text) WHERE PermitProcess='COUNTY PRE-APP MEETING'", $mysql_connect);

mysql_close($mysql_connect);

echo "The record was updated in your MySQL database!";
}

?>

<body>
</body>
</html>

 

I execute

 

UPDATE `08-12345-1` SET Req='some_text' WHERE PermitProcess='COUNTY PRE-APP MEETING'

 

in the phpMyAdmin query window and it works just fine, updates the table in my browser, but when I go to use the same statement in this script, it doesn't want to cooperate... :| anyone see any problem with it? I'll be really excited if somebody can figure this out, as I've been at this same part of my website for about a week now, with no further progress due to this problem.

Link to comment
https://forums.phpfreaks.com/topic/103900-why-wont-my-table-update/
Share on other sites

AHHHH!!!! Still doesn't work. I'm about to pull my hair out :o Arg.

 

<!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=iso-8859-1" />
<title>Examples
</title>
</head>

<?php

if(!isset($_POST['text'])) {
echo "<form action='/examples/index.php' method='post'>";
echo "<input type='text' name='text'>";
echo "<input type='submit'>";
echo "</form>";
} else {
$text = mysql_escape_string($_POST['text']);
$mysql_connect = mysql_connect('localhost', 'brian', '');

mysql_query("UPDATE `08-12345-1` SET Req='$text' WHERE PermitProcess='COUNTY PRE-APP MEETING'");

mysql_close($mysql_connect);

echo "The record was updated in your MySQL database!";
}

?>

<body>
</body>
</html>

 

This is what I have now, after changing what you stated. I just don't understand why it works in the query window in phpMyAdmin but not when put into this script... >.>

replace these lines:

$mysql_connect = mysql_connect('localhost', 'brian', '')
  or die("Failed to connect");
$text = mysql_escape_string($_POST['text']);
mysql_query("UPDATE `08-12345-1` SET Req='$text' WHERE PermitProcess='COUNTY PRE-APP MEETING'")
  or die("Update error: ".mysql_error());
mysql_close($mysql_connect);

$text won't be set to anything because you are using mysql_escape_string() before you have a connection to a mysql server.

 

When learning php, developing php code, or debugging php code, do yourself a favor and turn off full php error_reporting and the display_errors setting to get php to help you.

Now it's telling me no database selected >.> I clearly see I have one selected `08-12345-1` .. what's wrong with it now? :[

 

<!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=iso-8859-1" />
<title>Examples
</title>
</head>

<?php

if(!isset($_POST['text'])) {
echo "<form action='/examples/index.php' method='post'>";
echo "<input type='text' name='text'>";
echo "<input type='submit'>";
echo "</form>";
} else {
$mysql_connect = mysql_connect('localhost', 'brian', '')
  or die("Failed to connect");
$text = mysql_escape_string($_POST['text']);
mysql_query("UPDATE `08-12345-1` SET Req='$text' WHERE PermitProcess='COUNTY PRE-APP MEETING'")
  or die("Update error: ".mysql_error());
mysql_close($mysql_connect);

echo "The record was updated in your MySQL database!";
}

?>

<body>
</body>
</html>

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.