rh91uk Posted June 22, 2006 Share Posted June 22, 2006 I want to upload an image to the sql database, but I havent a clue how too! Ive tried google, but most of them are quite out of my league, as in i dont know how to add one to the following code:[code]<?php session_start(); if(!$_SESSION['username']){ header("Location: login.php"); exit(); } include('../includes/config.inc.php'); include('../includes/dbconnect.inc.php'); if($_GET['delete']){ $sql = "DELETE FROM `news` WHERE id='" . $_GET['delete'] . "'"; $result = mysql_query($sql) or die ("<b>ERROR: </b>" . mysql_error() . "<b>SQL: </b>$sql"); header("Location: pages.php"); exit();}?><html><head><title>Edit/Add News Story</title><meta http-equiv="Content-Type" content="text/html;"><link href="/includes/style.css" rel="stylesheet" type="text/css"><style type="text/css"><!--.style1 {font-size: 14px}--></style></head><body><h1>Richard Harris</h1><p class="style1">EDIT NEWS STORY </p><p><?php if(!isset($_POST['Submit'])){ $id = $_GET['edit']; $sql = "SELECT * FROM `news` WHERE id='$id'"; $result = mysql_query($sql) or die ("<b>ERROR: </b>" . mysql_error() . "<b>SQL: </b>$sql"); $rows = mysql_num_rows($result); while ($news = mysql_fetch_array($result)) { $news_title = $news["title"]; $news_content = $news["content"]; $news_img = $news["img"]; } ?><form method="post" action="<?=$_SERVER['../../../../My%20Documents/admin/PHP_SELF'];?>"> <table width="436" border="0" cellpadding="3" cellspacing="1"> <tr> <td width="67"><strong>Title</strong></td> <td width="354"><input name="title" type="text" class="txtboxlrg" value="<?=$news_title;?>" size="50"></td> </tr> <input name="id" type="hidden" value="<?=$id;?>"> <tr> <td valign="top"><strong>Content</strong></td> <td><textarea name="content" cols="50" rows="22" class="txtboxlrg" width="472"><?=$news_content;?></textarea></td> </tr> <tr> <td></td> <td align="center" class="header2"><input name="Submit" type="submit" onFocus="this.blur();" value="Update"></td> </tr> </table></form> <?php } else { if((!$_POST['title']) || (!$_POST['content']) || (!$_POST['img'])){ echo "You are missing a required field, please <a href=\"javascript:history.back()\">go back</a> and correct before proceeding!"; } else { if($_POST['id']){ $sql = "UPDATE `news` SET title='" . $_POST['title'] . "', content='" . $_POST['content'] . "' , img='" . $_POST['img'] . "', author='" . $_SESSION['firstname'] . " " . $_SESSION['lastname'] . "', updated=NOW() WHERE id = '" . $_POST['id'] . "'"; $result = mysql_query($sql) or die ("<b>ERROR: </b>" . mysql_error() . "<b>SQL: </b>$sql"); echo "News Item \"" . $_POST['title'] . "\" updated successfully - return to <a href=\"pages.php\" onFocus=\"this.blur();\">pages</a>!"; } else { $sql = "INSERT INTO `news` ( `id` , `title` , `content` , `img` , `author`, `added` ) VALUES('', '" . $_POST['title'] . "', '" . $_POST['content'] . "', '" . $_POST['img'] . "', '" . $_SESSION['firstname'] . " " . $_SESSION['lastname'] . "', NOW())"; $result = mysql_query($sql) or die ("<b>ERROR: </b>" . mysql_error() . "<b>SQL: </b>$sql"); $id = mysql_insert_id(); echo "News Item \"" . $_POST['title'] . "\" added successfully - return to <a href=\"pages.php\" onFocus=\"this.blur();\">pages</a>"; } } } ?></p></body></html>[/code]If soemone here could help me, maybe write me an addition, i would be greateful! Quote Link to comment https://forums.phpfreaks.com/topic/12633-image-upload-function/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.