- 1. Load The Links
- 2. Have An "Edit Button To The Right Of The Link (On Admin Page Only))
- 3. Add Links
- 4. Remove Links
Could somebody please help me out? Thanks.
Moderator: General Moderators
Code: Select all
<?
//initilize PHP
if($_POST['submit']) //If submit is hit
{
//then connect as user
//change user and password to your mySQL name and password
mysql_connect("DOMAIN","LOGIN","PASSWORD");
//select which database you want to edit
mysql_select_db("DATABASENAME");
//convert all the posts to variables:
$name = $_POST['name'];
$url = $_POST['url'];
//Insert the values into the correct database with the right fields
//mysql table = studentwork
//table columns = id, name, url
//post variables = $name, $url
$result=MYSQL_QUERY("INSERT INTO studentwork (id,name,url)".
"VALUES ('NULL', '$name', '$url')");
//confirm
echo "Student Page Added";
}
else
{
// close php so we can put in our code
?>
<form method="post" action="addwork.php">
<TABLE>
<TR>
<TD>Name:</TD>
<TD><INPUT NAME='name' TYPE='TEXT' id="name" size=60></TD>
</TR>
<TR>
<TD>URL:</TD>
<TD><INPUT NAME='url' TYPE='TEXT' id="url" VALUE='' size=60></TD>
</TR><br>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>
<?
} //close the else statement
?>
Code: Select all
include "config.php";
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());
// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());
// read data from database
$result = mysql_query("select * from $table order by id desc limit $rows", $link)
or die ("Could not read data because ".mysql_error());
// print the data in a table
if (mysql_num_rows($result)) {
print "<table cellpadding=0 cellspacing=0 border=0 width=\"100%\">\n";
while ($qry = mysql_fetch_array($result)) {
print "<tr><td> <a href=\"" . "$qry[url]\" target=\"_blank\">$qry[name]</a>";
//print $qry[comment];
print "</td></tr>\n";
}
print "</table>\n";
}
mysql_close();
Code: Select all
<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("DOMAIN","LOGIN","PASSWORD");
//select which database you want to edit
mysql_select_db("DBNAME");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from studentwork order by id");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$title=$r["name"];//take out the title
$id=$r["id"];//take out the id
//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM news WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Name:
<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["name"] ?>" SIZE=30>
<br>
URL:
<input name="message" type="text" value="<? echo $myrow["url"] ?>" size="30">
<br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$title = $_POST["name"];
$message = $_POST["url"];
$sql = "UPDATE studentwork SET name='$title',url='$message' WHERE id=$id";
//replace news with your table name above
$result = mysql_query($sql);
echo "Student Work Updated!";
}
}
?>Could someone please help me out?Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/jfenske.awardspace.com/school/3/editwork.php on line 115
I did have one mistake. I misspelled a table name.Ruud Hermans wrote:I'm not a PHP / MySQL guru but if I'm right this error appears when the named table can't be found in your database (at least as far as I am aware that is one of the reasons).
1. Did you edit the script so it could connect to your database?
2. Did you checked if there are no spelling mistakes in the table names?
*If I'm wrong please correct me I'm still trying to figure this all out myself to.
No problem helping others out can only make yourself smarter.ORiGIN wrote: I did have one mistake. I misspelled a table name.
Thanks a lot for all of the help