PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
// Connect to the database server
$dbcnx = @mysql_connect("localhost", "********",
"**********");
if (!$dbcnx) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>"
);
exit();
}
// Select the newsdatabase
if (! @mysql_select_db("jcart_runtings") ) {
echo( "<p>Unable to locate the" .
"database at this time.</p>" );
exit();
}
echo "<form action="=$PHP_SELF\ method="post">\n"
."<p>Type your news here:<br/>\n"
."<textarea name="news" rows="10" cols="40" wrap></textarea><br/>\n"
."<input type="submit" name="submitnews" value="SUBMIT" /></p>\n"
."</form>\n";
if ($submitnews == "SUBMIT") {
$sql = "INSERT INTO news SET
news='$news',
newsDate=CURDATE()";
if (@mysql_query($sql)) {
echo("<p>Your News has been
added.</p>");
} else {
echo("<p>Error adding submitted news: " .
mysql_error() . "</p>");
}
}
?>
?>
When I try using that form to add information I get brought to a link like this
<?
// Connect to the database server
$dbcnx = @mysql_connect("*****", "******",
"******");
if (!$dbcnx) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>"
);
exit();
}
// Select the news database
if (! @mysql_select_db("jcart_runtings") ) {
echo( "<p>Unable to locate the " .
"database at this time.</p>" );
exit();
}
$result = mysql_query("SELECT `newsDate` FROM `news` ORDER BY `id` DESC LIMIT 10")
?>
I finally got it right without getting any error messages but the field isn't showing up :S :S.... any thoughts?
Btw there is info in the mysql db to be displayed
Last edited by John Cartwright on Sun Jan 25, 2004 10:57 am, edited 4 times in total.
An example might be $result = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC LIMIT 10") and then use while($arr = mysql_fetch_array($result){} to loop throught the results.
Check these out for more info...
:: [php_man]mysql_query[/php_man]
:: [php_man]mysql_fetch_array[/php_man]