SamW Posted June 23, 2009 Share Posted June 23, 2009 What's going on? http://www.ballpointstudio.com/form2.php Fill in the form with anything and hit submit. It should display what you entered, as well as every other row, but...instead, it doesn't. This is my code: <?php mysql_connect("localhost", "CENSORED", "CENSORED") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("runetyco_cms") or die(mysql_error()); echo "Connected to MySQL<br />"; $content = $_POST['content']; $result = mysql_query("SELECT * FROM cms") or die(mysql_error()); mysql_query("INSERT INTO cms (content) VALUES('$content' ) ") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo "Name: ".$row['content']; ?> Link to comment https://forums.phpfreaks.com/topic/163347-solved-frustrating-php-mysql-unknown-character/ Share on other sites More sharing options...
JonnoTheDev Posted June 23, 2009 Share Posted June 23, 2009 The value will not be contained in the array as you are selecting the result set prior to inserting the record. swap the queries around. Should also be an associated array if you are using the field key. mysql_query("INSERT INTO cms (content) VALUES('$content' ) ") or die(mysql_error()); $result = mysql_query("SELECT * FROM cms") or die(mysql_error()); $row = mysql_fetch_assoc($result ); Link to comment https://forums.phpfreaks.com/topic/163347-solved-frustrating-php-mysql-unknown-character/#findComment-861839 Share on other sites More sharing options...
AviNahum Posted June 23, 2009 Share Posted June 23, 2009 try this: <?php mysql_connect("localhost", "CENSORED", "CENSORED") or die(mysql_error()); echo "Connected to MySQL<br />"; mysql_select_db("runetyco_cms") or die(mysql_error()); echo "Connected to MySQL<br />"; $content = $_POST['content']; mysql_query("INSERT INTO cms (content) VALUES('$content' ) ") or die(mysql_error()); $result = mysql_query("SELECT * FROM cms") or die(mysql_error()); while ($row = mysql_fetch_array( $result )) { echo "Name: ".$row['content']; } ?> Link to comment https://forums.phpfreaks.com/topic/163347-solved-frustrating-php-mysql-unknown-character/#findComment-861840 Share on other sites More sharing options...
n1tr0b Posted June 23, 2009 Share Posted June 23, 2009 you have a simple error mate From mysql_query("INSERT INTO cms (content) VALUES('$content' ) ") or die(mysql_error()); To: mysql_query("INSERT INTO cms (content) VALUES("$content") ") or die(mysql_error()); From echo "Name: ".$row['content']; From echo "Name: ". $row['content'] .""; correct me if i have some errors to... Link to comment https://forums.phpfreaks.com/topic/163347-solved-frustrating-php-mysql-unknown-character/#findComment-861841 Share on other sites More sharing options...
JonnoTheDev Posted June 23, 2009 Share Posted June 23, 2009 aviavi, mysql_fetch_array() will not return associative keys therefore your code wont work // bad $row = mysql_fetch_array($result); // this index will not exist print $row['content']; // good $row = mysql_fetch_assoc($result); print $row['content']; Link to comment https://forums.phpfreaks.com/topic/163347-solved-frustrating-php-mysql-unknown-character/#findComment-861856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.