Moderators: macek, egami, gesf

Kenneth wrote:Jay, thanks! How would I do the second one you said? I like my pages using PHP_SELF all in one. Thanks
Ken Cooper


Kenneth wrote:Thanks a lot Jay, I really appreciate. But believe it or not, I'm only 14, and I'm a kid that is just learning PHP. If its not too much trouble, could you possibly make up some code so I could see an example. Like I was talking about the Average thing before, I got code for example. Yes, I do have id's to seperate themselves. Thanks a lot, I really appreciate it.
Ken Cooper
<?
$query = "Select * from thisTable where Field=Value";
$result = query($query); //(I made my own function query which connects and executes the query, basically thats all it is)
if ($result) {
print "Results already in database";
} else {
$query = "Insert results into Table";
$inserted = query($query)
print ($inserted)? "Insert Successful":"Insert Failed";
}


Kenneth wrote:Sorry, I tried it, and it still entered the same data. Is there any other way? Well one more thing, if its not to much to ask, if its still possible, when you do an if else statement, doesn't echo a message, because I just want it to show the form both ways. Is there a way? Thanks a lot, I really appreciate it!!
Ken Cooper

<?
$connection = @mysql_connect("localhost", "cooperce_poll", "hermie") or die("Couldn't connect.");
$db = @mysql_select_db(cooperce_poll, $connection) or die("Couldn't select database.");
$sql = "SELECT *
FROM topics
ORDER BY id DESC
";
$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");
$contact_list = "<ul>";
while ($row = mysql_fetch_array($result)) {
$id5 = $row['id'];
$topic5 = $row['topic'];
$date5 = $row['date'];
$contact_list .= "<li><a href=\"old_opinions.php?theID=$id5\">$topic5</a> -- $date5";
}
$contact_list .= "</ul>";
?>
<?
include("connect.php");
$sql2 = "SELECT * FROM topics ORDER BY id";
$query2 = mysql_query($sql2) or die("Cannot query the database.<br>
" . mysql_error());
while($result2 = mysql_fetch_array($query2)) {
$topic = stripslashes($result2["topic"]);
$tid = stripslashes($result2["id"]);
$date = stripslashes($result2["date"]);
$display_past = "<ul>";
$display_past .= "<li><a href=old_opinions.php?id=$tid>$topic</a> -- $date</li>";
$display_past .= "</ul>";
}
$sql_count = "SELECT count(oid) FROM opinions WHERE id = \"$tid\"";
$result_count = @mysql_query($sql_count) or die("Couldn't execute query.");
$count = mysql_result($result_count,0,"count(oid)");
?>
<p><a href="http://www.coopercentral.org"><img src="images/cclogo.gif" width="222" height="132"></a></p>
<body link="#0000FF" vlink="#800080" alink="#FF0000" text="#000000" bgcolor="#FFFFF0">
<table border=1>
<tr>
<td bgcolor="#C7DFFC" valign="top">
<?php
$title = "Give us your Opinion! - $count so far!";
$titlecolor = "800000";
$titlefont = "/home/cooperce/public_html/fonts/COMIC.ttf";
$titlesize = "24";
$rotation = "90";
echo "<IMG SRC=\"/includes/graftext.php?title=$title&titlecolor=$titlecolor&titlefont=$titlefont&titlesize=$titlesize&rotation=$rotation\" ALT=\"$title\">";
?><td valign="top">Write a <b><i>brief</i></b> opinion of the topic below.
<table border=1>
<tr>
<td bgcolor=#CCFFB1 align=center><font size=4><b><? echo $topic; ?></b></font> </td>
</tr>
<tr>
<td>
<form method=POST action=<?php echo $PHP_SELF; ?>>
<p><input type=text name=text size=100 maxlength=225><input type=submit value=Post!></p>
</form>
</td>
</tr><td>
<?php
include("connect.php");
$today = date("M j, Y, h:i");
if(!empty($text)) {
$text = addslashes($text);
$sql = "INSERT INTO opinions SET oid='', id='$tid', opinion='$text', date='$today'";
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
$text=NULL;
$oid=NULL;
$id=NULL;
$date=NULL;
$today=NULL;
} else {
}
$sql3 = "SELECT * FROM opinions WHERE id = \"$tid\" ORDER BY oid DESC";
$query3 = mysql_query($sql3) or die("Cannot query the database.<br>" . mysql_error());
while($result3 = mysql_fetch_array($query3)) {
$opinion = stripslashes($result3["opinion"]);
$today5 = stripslashes($result3["date"]);
echo "
<font size=2>$opinion</font> <font size=1>-- <b>$today5</b><hr></font>
";
}
?>
</td>
</tr>
</hr>
</table>
</table>
<p></p>
<h2>Past Opinions</h2>
<p><?php echo "$contact_list"; ?></p>
<p></p>
<p align="right"> </p>
<p align="right"><a href="http://www.coopercentral.org">Coopercentral.org</a>
2002<br>
Email me: <a href="mailto:Kenny@coopercentral.org">Kenneth L. Cooper III</a><br>
<a href="privacy.php">Coopercentral Privacy Policy</a></p>

Kenneth wrote:I like the first one, where I count. Sorry, but could you possibly just give me an example? Don't go way out of your way, but your awesome at this stuff. Could you just give me a little example, I know what you mean, just general code of that. Thanks a lot, I really appreciate it!!
Ken Cooper
Kenneth wrote:Ya, I know, what I mean is, the resolve the 0 part, or do I just put that code in, and it does it? I don't know, just learning. Thanks a lot, I really appreciate it.!!
Ken Cooper
Return to PHP coding => General
Users browsing this forum: No registered users and 2 guests