Jump to content

[SOLVED] mySQL failure


BlueGeek

Recommended Posts

This is one of those "Worked all week to get this thing working, finished on Friday, took the weekend off, it was broken on Monday".

 

I've been whipping up this basic posting system using PHP and mySQL, and, well, it broke.  I'm not exactly sure why, it was working, capable of scrubbing and storing large text posts, but then it just stopped.  All the data from the form was going through just fine, so I figured that mySQL was choking on something I was sending it.

 

First I gave it very basic, punctuation, space, and return free data (just the word test for title and post body), which worked.  I followed that up by removing all of my scrubbing functions to see if I might have thrown it a bad replacement somewhere in there, failed.  I gave it the same test post without the scrubbers, fail.  Finally I put it all back, with the clean ups and gave it the test post, FAIL!!!

 

I really hate just throwing a large block of code on the forums and myself at all of your mercies, so if there's any other information that would help, please tell me.  Below is the code I believe to be at fault.

 


if(isset($_POST['author']) and isset($_SESSION['li_username']) and $_SESSION['li_clearance'] == 0 and $_POST['dauthor'] == $_SESSION['li_username'])
{
	mysql_connect($server,$username,$password);	
	@mysql_select_db($database) or die( "Unable to select database");

	$title = mysql_real_escape_string($_POST['title']);
	$author = $_POST['dauthor'];
	$aunum = $_POST['author'];
	$body = mysql_real_escape_string($_POST['body']);
	date_default_timezone_set('America/New_York');
	$posttime = date("Y-m-d H:i:s");


	$query = mysql_real_escape_string("INSERT INTO posts VALUES ('','".$title."','".$aunum."','".$posttime."','".$body."')");

	$result = mysql_query($query);
	echo "<h1>GET PREVIEWED</h1>";
	echo makePost($title, $author, $posttime, $body);
	echo '<p>Done!</p>';

	mysql_close();

}else{
	echo "<p>improper use: ".$_POST['author']."</p>";
}

 

I've cut out the fat (ie: general HTML generating and file importing) on this to make it as readable as possible.

 

the DB, password, server, and username variables all come from an included file.  The makePost function doesn't interact with the databases, it's just a function that generates the HTML for a post (so it's easy to change site wide).  In this case, makePost posts a preview of the just-made post (which it does, indicating that the data is, in fact, making it's way all the way to this point).

 

I'm not at all sure that I haven't (in fact I'm fairly certain I have) just deleted something accidentally and forgotten to put it back in.

 

Thank you for your help, in advance,

 

-Sandy

Link to comment
https://forums.phpfreaks.com/topic/174098-solved-mysql-failure/
Share on other sites

And like that I figured it out.  That mysql_real_escape_string doesn't belong there in that query, silly me.  Funny how some things are more apparent in black and white than highlighted in a colorful code editing program.

 

Thanks, all the same, forum, you're the shit.

 

EDIT: how do I mark this as resolved?

Link to comment
https://forums.phpfreaks.com/topic/174098-solved-mysql-failure/#findComment-917729
Share on other sites

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.