Jump to content

[SOLVED] Whats wrong with my code?


ballhogjoni

Recommended Posts

I am trying to update or insert the data in a specific field in my db, but its not working. I think it has something to do with passing the variable. Can someone review the code below and tell me what I am missing?

 

<?php
$index_page_title = $_POST['indexpagetitle'];

if (isset($index_page_title)) {
$username="xxxx";
$password="xxxxx";
$database="xxxx";

mysql_connect('localhost',$username,$password);
mysql_select_db($database) or die( "Unable to select database");

$result = mysql_query("SELECT * FROM Title") or die(mysql_error());
$num_rows = mysql_num_rows($result) or die(mysql_error());

if ($num_rows >= 1) {
	mysql_query("UPDATE Title SET newTitle = '".$index_page_title."'") or die(mysql_error());
	echo 'you updated you title to '.$index_page_title;
	echo '<FORM><INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)"></FORM>';
} else { 
	mysql_query("INSERT INTO Title (newTitle) VALUES ('$index_page_title')") or die(mysql_error());
	echo 'you Added your title to '.$index_page_title;
	echo '<FORM><INPUT TYPE="button" VALUE="Go Back" onClick="history.go(-1)"></FORM>';
}

} else {
?>

<!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>Admin Only</title>
</head>

<body>
Change home page title
<br />
<form action="" method="POST">
<table>
<tr>
	<td align="right">
	Title:
	</td>
	<td>
	<input type="text" name="indexpagetitle">
	</td>
</tr>
<tr>
	<td colspan="2" align="center">
	<input type="submit" value="Change Home Page Title"/><?php echo $index_page_title; ?>
	</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>

Link to comment
https://forums.phpfreaks.com/topic/60426-solved-whats-wrong-with-my-code/
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.