Page 1 of 1
MYSQL PROBLEM
Posted: Sun Jan 25, 2004 10:09 am
by John Cartwright
Code: Select all
<?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
http://www.******.com/tests/=/tests/index2.php/%20method=?news=THIS+IS+THE+NEWS&submitnews=SUBMIT
and the directory of the file is http://www.*****.com/tests/
BTW the data is not entered in the mysql
Posted: Sun Jan 25, 2004 10:15 am
by Gen-ik
Looks like you're missing a quotation mark from the end of your $PHP_SELF bit. By the way it's always better to use $_SERVER["PHP_SELF"].
echo "<form action=\"={$_SERVER['PHP_SELF']}\" <<<< LOOK
Posted: Sun Jan 25, 2004 10:16 am
by John Cartwright
TY I'll be back soon

TY once again
I love how this place has such quick responses

mad <3
Posted: Sun Jan 25, 2004 10:20 am
by John Cartwright
I added the missing quotation and now it's bringing me to this URL
http://www.********.com/tests/=/tests/index2.php
Posted: Sun Jan 25, 2004 10:26 am
by markl999
echo "<form action=\"={$_SERVER['PHP_SELF']}\"
remove the = ...
echo "<form action=\"{$_SERVER['PHP_SELF']}\"
Posted: Sun Jan 25, 2004 10:31 am
by John Cartwright
Okay how would I display some info in jcart_runtings ( table ) > news >
and then the fields, message, newsDate, etc
and how am I supposed to know which one is which,
i set ID to auto increment by 1... I think that was the right thing to do
Also, how am I supposed to display the newest-oldest news article
TY
Posted: Sun Jan 25, 2004 10:38 am
by John Cartwright
Code: Select all
<?
// 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")
?>
Code: Select all
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
Posted: Sun Jan 25, 2004 10:48 am
by Gen-ik
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]
Posted: Sun Jan 25, 2004 10:50 am
by John Cartwright
Read my last post I updated it ... TY
BTW looking in phpadmin what does null for each field mean?
Posted: Sun Jan 25, 2004 11:43 am
by John Cartwright
HURRAY I FIGURED IT OUT
ty
Posted: Sun Jan 25, 2004 11:51 am
by John Cartwright
echo "<form action=\"{$_SERVER['PHP_SELF']}\"\n"
."<p>Type your news here:<br/>\n"
."<textarea name=\"title\" rows=\"1\" cols=\"40\" wrap></textarea><br/>\n"
."<textarea name=\"message\" rows=\"10\" cols=\"40\" wrap></textarea><br/>\n"
."<textarea name=\"signature\" rows=\"1\" 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
message='$message',
newsDate=CURDATE(),
title='$title'
signature='$sig'";
if (@mysql_query($sql)) {
echo("<p>Your News has been added.</p>");
} else {
echo("<p>Error adding submitted news: " . mysql_error() . "</p>");
}
}
?>
Posted: Sun Jan 25, 2004 1:10 pm
by John Cartwright
nvm i got it
Posted: Sun Jan 25, 2004 1:13 pm
by Straterra
Holy Christ! 4 posts in a row?! Um..in the future, I would use that lil edit button over there to the right.