-
Posts
1,842 -
Joined
-
Last visited
Posts posted by marcus
-
-
Just use a header
Once you send the vote
[code]header("Location: index.php");[/code]
Which will redirect it to index and not send any post data -
Make $links = $_GET[links]
-
Connect to the database itself.
[code]
$dbh = myaql_connect(host,dbuser,dbpass);
$db = mysql_select_db(dbname,$dbh);
[/code] -
Ok, I'm just making a news system with categories and what not. But I keep getting the mysql_error
[code]Unknown column 'test2' in 'field list'[/code]
Test 2 was the new category I was trying to name it.
when trying to update the category name. Below is the code, and the main focus is on the bottom of the code
[code]
<?php
function category(){
$catsql = "SELECT * FROM cat";
$catres = mysql_query($catsql);
$num = mysql_numrows($catres);
if($num == 0){
echo "No Categories, <a href=".'news.php?act=cat'.">click here</a> to add one";
}else {
echo "Category: <select name=category>";
while ($row1 = mysql_fetch_array($catres, MYSQL_BOTH)) {
print "<option value=$row1[id]>$row1[catname]</option>";
}
mysql_free_result($catres);
echo "</select>";
}
}
if(!$act){
?>
<table border=0 cellspacing=2 cellpadding=2>
<tr><td colspan=2 align=right>
<h3>Add A Category</h3>
<form name=addcat method=post action="<?=$PHP_SELF?>">
<tr><td class=cA>
Category Name:<td><input type=text name=catname size=30>
<tr><td colspan=2 align=left>
<input type=hidden name=action value=addcat>
<input type=submit value="Add Category">
</form>
<tr><td colspan=2 align=right>
<h3>Rename A Category</h3>
<form name=addcat method=post action="<?=$PHP_SELF?>">
<tr><td class=cA>
<? category() ?>
<td>
Rename To:<input type=text name=newcatname>
<tr><td colspan=2><input type=hidden name=action value=rename>
<input type=submit value="Rename">
</form>
</table>
<?php
};
?>
<?php
if($act == addcat){
$catname = $_POST[catname];
if(!$catname){
echo "You did not specify a category name";
}else{
$add = "INSERT INTO cat (`catname`) VALUES('$catname')";
$addres = mysql_query($add) or die(mysql_error());
echo "Category $catname has been added to the categories list";
};
};
if($act == rename){
$newcat = $_POST[newcatname];
$newid = $_POST[category];
if(!$newcat){
echo "You did not specify a new category name ID #$newid";
}else{
$ren = "UPDATE `cat` SET catname =$newcat WHERE id='$newid'";
$rena = mysql_query($ren) or die(mysql_error());
echo "Category ID #$newid has been changed to $newcat";
};
};
?>
[/code] -
I had it fixed when I locked it.
-
It works now :)
-
Wouldn't this use .htaccess?
-
Ok, I'm trying to make something that the administrator can delete a certain news id by clicking the Delete $id button. Below is my code. I get no errors, it just doesn't work.
[code]
<?php
$pg = $_GET[pg];
if(!$pg){
$pg = 1;
};
$amount = "$pg * 12";
if(!$act){
?>
<table border=0 cellspacing=2 cellpadding=2>
<tr><td colspan=4 align=right>
<h3>Delete News</h3>
<tr><td colspan=4>
<tr><td class=cA>
ID<td class=cA>Title<td class=cA>Message<td class=cA>Author
<?php
$find = "SELECT * FROM news ORDER BY `id` ASC";
$gofi = mysql_query($find);
while($row1 = mysql_fetch_assoc($gofi)){
echo "
<tr><td>$row1[id]<td>$row1[title]<td>$row1[body]<td>$row1[poster]
<tr><td colspan=4 align=right>
<form name=delete$row1[id] method=post action='".$PHP_SELF."'><input type=hidden name=delid value=$row1[id]><input type=submit value='Delete ".$row1[id]."'></form>";
}
mysql_free_result($gofi);
echo "</table>";
};
?>
<?php
if($act == delid){
$delid = $_POST[delid];
$del = "DELETE FROM `news` WHERE id=$delid";
$delgo = mysql_query($del) or die(mysql_error());
echo "News ID $delid deleted";
};
?>
[/code] -
No problem.
-
And brendan, I chose his because I wasn't sure on ataria's PHP Experience level and to show that it would only include those.
-
Below
[code]
function protect($input)
{
[/code] -
It would make it so only a-z, A-Z and 0-9 are allowed.
-
That's fine. You can include .html files.
-
Well, I don't want to replace any words.
-
I stated that wrong.
How would I be able to create a document that checks if the user submitted a word that was in an array. If they did submit a word it would come up with a message saying like "blah blah blah bad word." And if no word from the array was found it would complete the task.
Something like:
[code]
<?php
$mesg = $_POST[message];
$array = array("words,that,the,user,cannot,submit");
if($mesg == $array){
echo "bad word";
}else {
echo "fine statement";
};
?>
[/code]
something like that, but how would I make it to check if $mesg included any of the words in $array -
You should different queries for each category.
[code]
$cat1 = mysql_query("SELECT * FROM categories WHERE id=1");
$cat1a = mysql_query("SELECT * FROM forums WHERE cid=1 ORDER BY fid");
etc....
[/code] -
Say I have an array of words that I didn't want the user to submit, and if they did submit one of the words it would submit completely, a message would come up saying that they said one of the words.
-
[code]
<?php
$conn = mssql_connect('MYSQLSERVER', 'sa', 'password');
mssql_select_db('[my data-base]', $conn);
?>
[/code] -
I would stick with one of them. Use thorpes.
-
That's an apache error. Usually if your code is like cgi or pl.
-
[code]
if (!ereg("~!@#$%^&*()_+=-,./<>?;':"[]\{}|",$username))
{
echo "$username is not a valid username";
}
[/code] -
Yep, no problem.
-
You aren't connecting correctly.
[code]
<?php
$username = "username";
$password = "password";
$hostname = "localhost";
$database = "database";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
$db = mysql_select_db($database,$dbh) or die("Unable to connect to datase");
$select = mysql_query("SELECT * FROM `dates_table`");
echo "<table><tr><td>Week</td><td>Date Start</td><td>Notes</td><td>Date End</td></tr>";
while ($info = mysql_fetch_assoc($select)) {
$week = $info['week'];
$date_start = $info['date_start'];
$notes = $info['notes'];
$date_end = $info['data_end'];
echo "<tr>
<td>
$week
</td>
<td>
$date_start
</td>
<td>
$notes
</td>
<td>
$date_end
</td></tr>";
}
mysql_free_result($select);
echo "</table>";
?>
[/code]
you're going to have to select a database to connect to -
Connect to your database. Should work then.
You're basically selecting from infinite.
SiteStats
in PHP Coding Help
Posted
Insert their IP into the table, and have something like:
IP | Hits | Time | LastPage
And check if the user's IP already exists in the database, and if it does then it won't create a new row each time. Then just do
[code]
$sql = "SELECT ip FROM stats WHERE ip ='$_SERVER[REMOTE_ADDR]'";
$res = mysql_query($sql);
$res2 = mysql_fetch_assoc($res);
$num = mysql_numrows($res);
if($num > 0){
//update stats
}else {
$sql = "INSERT INTO stats (`ip`) VALUES('$_SERVER[REMOTE_ADDR]')";
$res = mysql_query($sql);
};
[/code]