Jump to content

[SOLVED] PHP MySQL update/add problem


mlmorg

Recommended Posts

Hey all,

I have an admin section on a site and I'm having a lot of weird problems with it when it I try and update or add certain things. To make it easy on everybody I'll just put up the code for the admin section for the "About" page of the website. I've set it up so that the user is able to change the text about the website in the admin section on this page. The code for viewing and updating the About section is done all in one page:

 

<?
$table = "about";

if($_POST["action"] == "Update") {
$about = $_POST["about"];
$query = "UPDATE $table SET about = '$about' WHERE id=1";
mysql_query($query);
echo "*Record Updated*<br /><br /><a href='index.php'><- Go Back</a><br /><br /><br />";
echo "$about<br /><br />";
}

else {
$query = "SELECT * FROM $table WHERE id=1";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
if (mysql_num_rows($result) > 0) {
while($row = mysql_fetch_array($result)) {
	$about = "".$row['about']."";
	}
}
else {
echo "No rows found!";
}
?>

You may change the About section below:<br /><br />
<form name="about" action="<? $_SERVER['PHP_SELF']; ?>" method="post">
About: <br /><textarea name="about" class="form" rows=20 cols=80><? echo "$about"; ?></textarea><br /><br />
<input type="submit" class="form" value="Update" name="action"></form>
<a href="index.php"><- Go Back</a><br /><br />

<?
mysql_free_result($result);
}
?>

 

As you can see it's a pretty simple view and update page...but it doesn't work. If I try to add text to it nothing happens. If I put the text into the mysql database through a third party program (like Cocoa MySQL) obviously the text adds...but I can't update the text. I have noticed that if I delete all the text it deletes it all. Also, I can add short amounts of text at a time and it will update. But if I add a large amount of text (maybe 150 characters or more) it doesn't update.

 

The rest of the admin section is written basically the same way. Some parts of the admin section work and some don't. For example, I have a news section and I can update the post where id = 1 but I can't update post #2. Also, it's the same with the Artist section: I can the first artist so that id=1 but if I try to add another (id=2) it doesn't work...beyond that I think maybe id 5 and 6 work...the others (3, 4) don't. All my other sections...which really only incorporate just a short amount of text kept in varchar's work and update fine.

 

Anyone have any ideas what might be going on here?

Any help would be greatly greatly appreciated!

Thanks,

Matt

Link to comment
Share on other sites

Ok this is the error I get:

 

Error in query: UPDATE about SET about = 'This Side Up Sounds is an NYC based management company, label, and booking agency founded by Seth Kallen in 2004. The company was created originally as an avenue to distribute and market Seth Kallen's original music, but in 2006 Kallen branched out and began guiding the career of DC based Jukebox the Ghost. Since then, This Side Up has helped develop the careers of numerous young artists, exclusively working with some, and freelance booking for others. In the summer of 2007 This Side Up added Natalie Prass and Jon Check to their roster of artists they work with on a daily basis.

 

 

Our office is located in Manhattan's East Village. Please send materials for consideration to:

 

This Side Up Sounds

4 Stuyvesant Oval

#4D

New York, NY 10009

 

 

TEST' WHERE id=1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's original music, but in 2006 Kallen branched out and began guiding the career o' at line 1

 

What does this mean?

Link to comment
Share on other sites

A person on another forum told me I have to update and add using mysql_real_escape_string() for each variable. Like:

 

<?
mysql_query("UPDATE $table SET text = '" . mysql_real_escape_string($text) . "' WHERE id = '$id'");
?>

 

Worked great.

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.