Can't Update mysql Table

PHP Forum 4 college - Can't update topic table

Page 1 of 1

6 Replies - 3358 Views - Last Post: 06 December 2009 - 10:42 PM Rate Topic: -----

#1 kingofleinster  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 09-December 08

Can't Update mysql Table

Posted 05 December 2009 - 04:18 PM

Hi Folks

Bit Stuck here , I have to do a php forum for college ,

I have created the database & the tables , I'm in the process of trying to create a topic & then adding to it .

The problem is I can't get the php to update the database

keeps throwing back "The Suggestion Box is empty".

:blink:

here is my code






<?php
session_start();



if (! isset($_SESSION['authenticated']))
	{
	  header ("Location:login.php");

	}




require_once("db_connect.php"); ?>

<html><head><title>New Topic</title></head>

<body>
<h1>New Topic</h1>

<?php

$self = $_SERVER['PHP_SELF'];
 

if (isset($_REQUEST['new']))

{ ?>

<form action="<?php echo $self ?> " method="post">

Enter Your New Topic Name:<br>
<textarea name="topicname" rows="1" cols="50"> </textarea><br>
Enter Topic Details<br>
<textarea name="detail" rows="10" cols="50"></textarea><br>
<p><input type="submit" name="add" value="submit"></p>
</form>
<?php 
}


else

{
	$db_link = db_connect("ForumPN");
	if(isset($_REQUEST['add']))
	{
		$topicname = $_REQUEST['topicName'];
		$details = $_REQUEST['detail'];
		$query = "INSERT INTO topic SET time=NOW()," . "topicName='$topicname'," . "detail = '$details'";
		mysql_query($query);
		
	}
	
	
	$query = "SELECT time, topicName, detail FROM topic";
	$result = mysql_query($query);
	
	if(mysql_num_rows($result) > 0)
	{
		while ($row = mysql_fetch_assoc($result));
		{
			$time= $row['time'];
			$topicname = $row['topicName'];
			$details = $row['detail'];
			
			echo "<b>$time:</b>$topicname</b>$details<br>\n";
			
			}
			
			}
			else
			
			{
				echo "The Suggestion box is empty";
				
			}
			?>
			
	<p><a href="<?php echo $self ?>?new=1">Submit A new Topic</a></p>
	
	</body>
	</html>
	<?php
	}
	?>
		





Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Can't Update mysql Table

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Can't Update mysql Table

Posted 05 December 2009 - 04:21 PM

and is the query actually inserting stuff into the database?

Have you tried adding a or die(mysql_error()); after the call to mysql_query($query) after the insertion should be done??
Was This Post Helpful? 0
  • +
  • -

#3 kingofleinster  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 09-December 08

Re: Can't Update mysql Table

Posted 05 December 2009 - 04:39 PM

View PostRudiVisser, on 5 Dec, 2009 - 03:21 PM, said:

and is the query actually inserting stuff into the database?

Have you tried adding a or die(mysql_error()); after the call to mysql_query($query) after the insertion should be done??

Hi

I've tried adding it in but still no joy

Below is the table i'm trying to add it into , its called topic

Field Type Null Default Comments
topicId int(5) No
userId int(5) No
topicName varchar(50) No
detail varchar(50) No
time timestamp No CURRENT_TIMESTAMP
views int(5) No
reply int(5) No
Was This Post Helpful? 0
  • +
  • -

#4 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Can't Update mysql Table

Posted 05 December 2009 - 04:42 PM

Right

Try changing the block to this:
if(isset($_REQUEST['add']))
	{
		echo '<b>Adding record... [TEST]</b>';
		$topicname = mysql_real_escape_string($_REQUEST['topicname']);
		$details = mysql_real_escape_string($_REQUEST['detail']);
		$query = "INSERT INTO topic SET time=NOW()," . "topicName='$topicname'," . "detail = '$details'";
		mysql_query($query) or die(mysql_error());
		echo '<b>Great success!</b>';
	}


See if you can see the text it should echo.
Was This Post Helpful? 0
  • +
  • -

#5 kingofleinster  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 09-December 08

Re: Can't Update mysql Table

Posted 06 December 2009 - 03:51 PM

View PostRudiVisser, on 5 Dec, 2009 - 03:42 PM, said:

Right

Try changing the block to this:
if(isset($_REQUEST['add']))
	{
		echo '<b>Adding record... [TEST]</b>';
		$topicname = mysql_real_escape_string($_REQUEST['topicname']);
		$details = mysql_real_escape_string($_REQUEST['detail']);
		$query = "INSERT INTO topic SET time=NOW()," . "topicName='$topicname'," . "detail = '$details'";
		mysql_query($query) or die(mysql_error());
		echo '<b>Great success!</b>';
	}


See if you can see the text it should echo.

Hi

I added the above code & ran it
Printed on screen

Adding Record ........[TEST] Great Success!


Which I hope is good
Was This Post Helpful? 0
  • +
  • -

#6 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: Can't Update mysql Table

Posted 06 December 2009 - 05:09 PM

Yeah but kinda screwed up.

Could you check that it is doing what it says? Do the row changes actually exist in the table?
Was This Post Helpful? 0
  • +
  • -

#7 bmoyles0117  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 27
  • Joined: 17-April 09

Re: Can't Update mysql Table

Posted 06 December 2009 - 10:42 PM

According to your code, if you have no rows in your topic table, that is when you will receive the result "No Suggestion in box". Ensure that you have rows in your topic table if you're still receiving this error.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1