New at programming-need help on adding code for a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Mmmm... it seems you're using Internet noteffExplorer so you're not able to see the effect achieved by style="display: block; overflow: auto;". Try Mozilla Firefox to see it.

Anyway, I fiddled a bit with textarea, see what I've got: http://scorphus.no-ip.com/lab/testimonials/

-- Scorphus
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

Post by Lucnet »

Yes thats what I wanted. Thanks it works great. You can see final here http://www.lsscripts.com/projects/testi ... in/new.php

As you can see I have plans to add some buttons and a couple more options. Like the ability to show ones I have approved and ones I have questions about. All I can do now is show the news one submitted. I am unsure on how to make it view ones on hold and ones already approved. The biggest thing is getting a page to open in itself instead of have three different pages for each button. But I am sure I will figure it out as I have gotten this far already. If you have any ideas on a good way to go about it. I will appreciate the advice.

Thanks, again for the help scorphus. :D
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Great! I'm glad it works for you :)

To use only one page to show new, on hold and approved testimonials you could imnplement something like this:

1- Change the links:

Code: Select all

<a href="add.php">Add Testimonials</a>
<a href="show.php?status=new">New Testimonials</a>
<a href="show.php?status=onhold">On Hold Testimonials</a>
<a href="show.php?status=approved">Active Testimonials</a>
2- Create the show.php page, which will be somehow like those new.php, onhold.php and approved.php:

Code: Select all

<?php
// ...
// copy the 'status' passed via GET:
$status = (!empty($_GET['satus']) ? $_GET['satus'] : '%');
// ... connect to DB ...
// change your query i.e.:
$query = "SELECT * FROM testimonials WHERE status LIKE '$status'";
// ... show the testimonials ...
// ...
?>
Hope that helps, looking forward hearing your feedback!

Regards,
Scorphus.
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

Post by Lucnet »

I made the adjustment, but it has caused an error with my mysql_fetch_object. You can see the full error here http://www.lsscripts.com/projects/testi ... n/show.php
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

It sems that the query is wrong. You must catch the DB error message this way:

Code: Select all

<?php
// ...
// copy the 'status' passed via GET:
$status = (!empty($_GET['satus']) ? $_GET['satus'] : '%');
// ... connect to and select database ...
// change your query i.e.:
$query = "SELECT * FROM testimonials WHERE status LIKE '$status'";
// query the database:
$result = msql_query("SELECT * FROM table WHERE id=1", $link) or die("query ($query) failed: " . mysql_error()); // do not echo your query, it is just for the sake of a test
// ... show the testimonials ...
// ...
?>
Let us see the error message. Also, please post the code of show.php, you can remove passwords, db and server config and whatever information you think is irrelevant to what we are arguing here.

Regards,
Scorphus.
Last edited by scorphus on Tue Jul 06, 2004 6:03 pm, edited 1 time in total.
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

Post by Lucnet »

Heres the show.php

Code: Select all

<?
/*Added this*/$status = (!empty($_GET['satus']) ? $_GET['satus'] : '%');
include "../inc/config.php";
switch($action) {
	case "approve":
		db();
		mysql_query("UPDATE ls_testimonials SET approved='y' WHERE id=$id");
		$pagecontent.="Item {$id} Approved<br><br>";
		db_close();
	break;
	case "hold":
		db();
		mysql_query("UPDATE ls_testimonials SET approved='h' WHERE id=$id");
		$pagecontent.="Item {$id} On Hold<br><br>";
		db_close();
	break;
	case "delete":
		db();
		mysql_query("DELETE FROM ls_testimonials WHERE id=$id");
		$pagecontent.="Item {$id} Deleted<br><br>";
		db_close();
	break;
	default:
	break;
}
db();
/*Added this*/ $query = "SELECT * FROM ls_testimonials WHERE status LIKE '$status'"; 
//$formdata_res=mysql_query("SELECT * FROM ls_testimonials WHERE approved='y'");
$pagecontent.="<table width=150 background=../inc/skins/default/images/menu_bg.gif>";
$pagecontent.="<tr><td><font color=#000000><b>Menu</b></font></td></tr>
<tr><td><font color=#000000><a href=add.php>Add Testimonials</a></font></td></tr>
<tr><td><font color=#000000><a href=show.php?status=n>New Testimonials</a></font></td></tr>
<tr><td><font color=#000000><a href=show.php?status=h>On Hold Testimonials</a></font></td></tr>
<tr><td><font color=#000000><a href=show.php?status=y>Active Testimonials</a></font></td></tr>";
$pagecontent.="</table>";
/*$pagecontent.="<table width=760>";
  $pagecontent.="<td width=175><center><a href='?id={$formdata->id}&action=approve'>approve</a> | ";
  $pagecontent.="<a href='?id={$formdata->id}&action=hold'>hold</a> | ";
  $pagecontent.="<a href='?id={$formdata->id}&action=delete'>delete</a> </center></td>";
  $pagecontent.="</tr>";
$pagecontent.="</table>";*/
$pagecontent.="<table width=760>";
$pagecontent.="<tr bgcolor=#CCCCCC><td width=233>Email</td><td width=230>Website</td><td width=233>Testimonial</td><td width=60>Action</td></tr>";
/*Error on this line*/ while ($formdata=mysql_fetch_object($formdata_res)) {
	$link_display=htmlentities($formdata->link_display);
	$email=htmlentities($formdata->email);
	$company=htmlentities($formdata->company);
	$testimonials=htmlentities($formdata->testimonials);
  $pagecontent.="<tr bgcolor=#EEEEEE>";
  $pagecontent.="<td><a href='mailto:{$email}'>{$email}</a></td>";
  $pagecontent.="<td><a href='{$company}' target=new>{$company}</a></td>";
  $pagecontent.="<td><textarea style=width=230; border: 0; rows=1>{$testimonials}</textarea></td>";
  $pagecontent.="<td><center><a href='?id={$formdata->id}&action=approve'><img src=../inc/skins/default/images/approve.gif width=17 height=17 border=0 ALT=Approve></a> ";
  $pagecontent.="<a href='?id={$formdata->id}&action=hold'><img src=../inc/skins/default/images/hold.gif width=17 height=17 border=0 ALT=Hold></a> ";
  $pagecontent.="<a href='?id={$formdata->id}&action=delete'><img src=../inc/skins/default/images/delete.gif width=17 height=17 border=0 ALT=Delete></a> </center></td>";
  $pagecontent.="</tr>";
}
$pagecontent.="</table>";
db_close();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Approval Page</title>
</head>
<body>
<?=$pagecontent;?>
<br><br><br><br>

<!-- DO NOT REMOVE THIS CODE BELOW -->
<table width="750" border="0" cellpadding="0" cellspacing="0" >
  <tr>
    <td><center>
        <font size="2">Powered by: <a href=http://www.lsscripts.com>LS Testimonials</a></font> 
        <br>
        <font size="2">Ver. 1.0</font> 
      </center></td>
  </tr>
</table>
<!-- COPYRIGHT CODES END -->
</body>
</html>
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

You've commented the line where you really query the dtabase:

Code: Select all

<?php
// ...
//$formdata_res=mysql_query("SELECT * FROM ls_testimonials WHERE approved='y'");
// ...
?>
Change this line like this:

Code: Select all

<?php
//...
/*Added this*/ $query = "SELECT * FROM ls_testimonials WHERE status LIKE '$status'"; // Here just create a variable holding the query string
$formdata_res=mysql_query($query) or die("query failed: " . mysql_error()); // Here we send the query to the database server
// ...
?>
What you get then?

-- Scorphus

[edit]
Added or die(mysql_error()). Thanks feyd!
[/edit]
Last edited by scorphus on Tue Jul 06, 2004 6:04 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

don't forget to add "or die(mysql_error())" ;)
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

Post by Lucnet »

That didn't do it ether.

I am getting this error now

Fatal error: Call to undefined function: msql_error() in /home/lsscript/public_html/projects/testimonials/admin/show.php on line 56
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mysql_error() not msql_error()
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Lucnet, sorry for the mistype :oops:

And feyd, thanks again!

-- Scorphus
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

Post by Lucnet »

OK now we are getting this error.

query failed: Unknown column 'status' in 'where clause'
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Oh... just change 'status' to 'approved' ;)

-- Scorphus
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

Post by Lucnet »

Ok that was it. Thanks.

Ok now another one for you. Hope you don't mind. How can I add a welcome page and add the add testimonial page.

Heres the index.php I am useing for a welcome. http://www.lsscripts.com/projects/testimonials/admin

Heres the add testimonial page
http://www.lsscripts.com/projects/testi ... in/add.php
I can go to it from the menu of the show.php. But it loads the add.php file.
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

I'm not sure if I understand you, but I think you want the 'Add Testimonial' page with same header (welcome message and stuff) as the main page.

Well, I think you better open a new thread in the Client Side forum. Try to reformulate your question and always post some code if you think it's relevant. I think you might have more chance to get answered there with a new thread.

Hope I can answer you there.

-- Scorphus
Post Reply