PHP - Please Help. Really Desperate!
Similar TutorialsRight so here is all the background information you'll need to know; I'm working on a PHP/My SQL Blog, The index.php page works fine and displays the post's fine, On each post there is a link to the article on its own separate page so the php generate a URL like so Code: [Select] http://www.mywebsite.com/news.php?articleid=HEREISTHEIDNUMBER This part all work fine however the news.php page will not work. I keep getting error messages like "Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/tserv1/public_html/news.php on line 3" Can anyone rewrite this page to work for me please. If you can please keep it in the table I have already provided. Thanks Code: [Select] <?php include("config/config.php"); $data = mysql_query("SELECT * FROM blog WHERE articleid = $_GET["articleid"] ORDER by date_posted ASC") or die(mysql_error()); while($row = mysql_fetch_array($data)) { echo "<table class='main'> <tr> <td> <a href='/news.php?articleid=" . $row['articleid'] . "' class='article_title'>" . $row['title'] . "</a> <p>" . $row['introduction'] . "</p></td><tr><td ALIGN='RIGHT' class='small'> Posted by:" . $row['author'] . ", on " . $row['date'] . ",</td></tr></table>"; ?> Hi all, I know this is my first post so please go easy I'm still learning PHP. Basically, I keep getting 'SQL Selection error: Unknown database 'localhost' I have tried a basic 'insert' and 'search' and both attempts return this error. search.php below <?php include 'studentfunc.php'; //import the class in this web page ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Retrieving Pet Data</title> </head> <body> <?php $db1 = new dbstudent(); $db1->openDB(); $sql="SELECT * from student"; $result=$db1->getResult($sql); echo "<table border='1'>"; echo "<tr><th>Pet ID</th><th>Name</th><th>Info</th><th>Info</th></tr>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>{$row['cid']}</td><td>{$row['name']}</td>"; echo "<td>{$row['address']}</td>"; echo"<td><a href='dispownerinfo.php?owner_id={$row['sid']}'>{$row['name']}</a></td>"; echo "</tr>"; } echo "</table>"; $db1->closeDB(); ?> </body> </html> <?php //Save it as db_config.php define('DB_HOST','localhost'); define('DB_NAME','test_work'); define('DB_USER','root'); define('DB_PASSWORD',''); ?> studentfunc.php below Code: [Select] <?php require("db_config.php"); class dbstudent { /* DB connection handle */ private $conn; function insert_student($sid, $name, $address, $postcode, $photo) { $esc_name = mysql_real_escape_string($name, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $esc_photo = mysql_real_escape_string($photo, $this->conn); $sql = "insert into student (sid , name, address, postcode, photo) values ('{$sid}', '{$esc_name}', '{$esc_address}', '{$esc_postcode}', '{$esc_photo}'"; $result = mysql_query($sql, $this->conn); if (!$result) { die("SQL Insertion error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } function openDB() { $this->conn = mysql_connect(localhost, root); if (!$this->conn) { die("SQL Connection error: " . mysql_error()); } $db_selected = mysql_select_db(DB_HOST, $this->conn); if (!$db_selected) { die("SQL Selection error: " . mysql_error()); } } function getResult($sql) { $result = mysql_query($sql, $this->conn); if ($result) { return $result; } else { die("SQL Retrieve Error: " . mysql_error()); } } function update_student($name, $address, $postcode, $photo, $sid) { $esc_name = mysql_real_escape_string($name, $this->conn); $esc_sid = mysql_real_escape_string($sid, $this->conn); $esc_address = mysql_real_escape_string($address, $this->conn); $esc_postcode = mysql_real_escape_string($postcode, $this->conn); $sql = "update student set name='{$esc_name}' where id={$esc_sid}"; $result = mysql_query($sql, $this->conn); if (!$result) { die("SQL Error: " . mysql_error()); } else { $numofrows = mysql_affected_rows($this->conn); return $numofrows; } } function closeDB() { mysql_close($this->conn); } } ?> I just dont get it! I am unimaginable grateful for any assistance here. |