MyBB Community Forums

Full Version: php add, and delete :D
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi MyBB not been very active recently, but im back and this time ready to create some scripts. Unfortunately not MyBB scripts as my site isnt large enough to have a forum at the moment.

Ive basically created a MySQL table and filled it with loads of words, I then have a script which displays a random one of these words.

<?php

$link = mysql_connect("localhost", "user", "password") or die (mysql_error ());

mysql_select_db ('database', $link) or die (mysql_error ());

$sql = mysql_query ("SELECT `Article_Title` FROM `keywords` ORDER BY RAND() LIMIT 0,1") or die (mysql_error ());

$res = mysql_fetch_assoc ($sql);

$randomquote = $res['Article_Title'];

echo $randomquote;

?>

The table is called 'keywords' and the column is called 'Article_Keywords'

in theory I would like it when the keyword is displayed, for a image to appear on the right of the keyword, a cross, which would delete that keyword from the database, therefore the keyword would never appear again.

I would also like a form on a seperate page which has a form, and when I enter a new keyword into that form and press submit, that keyword is then added onto my database.

Could anyone possibly help me to do this?

Thanks, Hapatio.
add.jsp
<form method="post" action="add.php?app=exec&inc=jsp">

<table cellspacing="5" cellpadding="5" style="margin-left: 60px;">
<tr>
<td valign="top"><strong>Keyword: </strong></td>
<td valign="top"><input type="text" name="keyword" size="50" maxlength="100" value="" style="width: 436px;"/></td>
</tr>
<tr>
<td align="right" colspan="2"><input type="submit" name="save" value="Add Keyword!" /></td>
</tr>
</table>

</form>

add.php
<?php

// Coded By: Kyonko

// connect to database
$conn = mysql_connect("localhost","db_user","db_passwrd") or 
die (mysql_error());

// select databse
$db = mysql_select_db("db_name", $conn) or die(mysql_error());

// execute query
$sql_result = mysql_query($sql,$conn) or die (mysql_error());

// run execution code 
$sql = "INSERT INTO `keywords` (keyword) VALUES ('$_POST['keyword'])";

if ($sql_result) {

echo "
<table style='margin-left:18px;'>
<tr>
<td align='left'><strong>Keyword Added Successfully!</strong></td>
</tr>
</table>

<table cellspacing='5' cellpadding='5' style='margin-left:16px;'>
<tr>
<td valign='top'><strong>Keyword: </strong></td>
<td valign='top'>".stripslashes($_POST[keyword])."</td>
</tr>
</table>";

}

?>

The first part is the form you would need to save it as .html or what ever I have my saved as .JSP since it runs using JSP (Java Server Protocol) on my server. In any rate the add.php will add and display the data on the page. You still will need to add tables and ect.

To delete the words, its a simple MySQL query. In any case just PM me and fully explain what you need and I will make something for you on a quick hand.
Hi thanks for your support, it means a lot.

The script produces
Quote:Parse error: syntax error, unexpected T_STRING in /home/sitename/public_html/add.php on line 7

error. Line 7 is

Quote:die (my sql_error());

Is that a error which can be easily debugged, thanks again for helping.
hmm odd, I must have added a space.

here is the correct term that had to be used.
or die (mysql_error());

You can also add this part to the add.php code to the very top
<?php
if ((!$_POST[keyword]))) 
{
     header("Location: add.jsp"); //make sure to change add.jsp to what ever you are using.
     exit;
}

?>

This part will check if the input was send and if it was not it will send you back to add.jsp form to add the keyword ^^

And your mostly welcome ^^, for the delete part just PM me and I will give it to you.