Existence
01-21-2005, 06:53 AM
Sorry to bother you people at CodingForums.com, but I'm having some sort of intricate problem with retrieving and inserting information into my database with my scripting.
I know, that my database works, because I run a Woltlab forum functionally and properly that retrieves and sends it's information and works totally fine.
But, here is my problem. I have a few scripts that are supposed to send queries to MySQL, and retrieve the data, and in one ( which is a news script ) that inserts data. But, when I push my submit buttons, nothing is inserted into the databasing. I'll show you the scripts that I'm using.
Script 1. Globals.php
<?php
$dbhost="localhost";
$dbusername="Censored";
$dbpassword="Censored";
$dbname="Existence";
$connect = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname,$connect) or die ("Good job, idiot. You broke it.");
?>
Script 2. Add_News.php
<?php
include("Globals.php");
if($submit)
{//begin of if($submit).
// Set global variables to easier names
// and pervent sql injection and apostrophe to break the db.
$Title = mysql_real_escape_string($_POST['Title']);
$Text1 = mysql_real_escape_string($_POST['Text1']);
$Text2 = mysql_real_escape_string($_POST['Text2']);
//check if (title) field is empty then print error message.
if(!$Title){ //this means If the title is really empty.
echo "Error: Goddammit, put a title in the update..";
exit(); //exit the script and don't do anything else.
}// end of if
//run the query which adds the data gathered from the form into the database
$result = mysql_query("INSERT INTO news (Title, DTime, Text1, Text2)
VALUES ('$Title',NOW(),'$Text1','$Text2')",$connect);
//print success message.
echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=News.php>";
}//end of if($submit).
// If the form has not been submitted, display it!
else
{//begin of else
?>
<br>
<h3>::Add News</h3>
<form method="post" action="<?php echo $PHP_SELF ?>">
Title: <input name="Title" type="text" size="40" maxlength="255">
<br>
Text1: <textarea name="Text1" rows="7" cols="30"></textarea>
<br>
Text2: <textarea name="Text2" rows="7" cols="30"></textarea>
<br>
<input type="submit" name="submit" value="Add News">
</form>
<?
}//end of else
?>
Script 3. News.php
<?php
// load the configuration file.
include("Globals.php");
//load all news from the database and then OREDER them by newsid
//you will notice that newlly added news will appeare first.
//also you can OREDER by (dtime) instaed of (news id)
$result = mysql_query("SELECT * FROM News ORDER BY NewsID DESC",$connect);
//lets make a loop and get all news from the database
while($myrow = mysql_fetch_assoc($result))
{//begin of loop
//now print the results:
echo "<b>Title: ";
echo $myrow['Title'];
echo "</b><br>On: <i>";
echo $myrow['DTime'];
echo "</i><hr align=left width=160>";
echo $myrow['Text1'];
// Now print the options to (Read,Edit & Delete the news)
echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
|| <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a>
|| <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";
}//end of loop
?>
---------
Please take a moment and look these over and tell me what is being done wrong...
You can E-mail me at ExistenceInfinito@Gmail.com , or leave a comment here -- either way, I'll check often. Thank you for taking the time.
-Jordan.
I know, that my database works, because I run a Woltlab forum functionally and properly that retrieves and sends it's information and works totally fine.
But, here is my problem. I have a few scripts that are supposed to send queries to MySQL, and retrieve the data, and in one ( which is a news script ) that inserts data. But, when I push my submit buttons, nothing is inserted into the databasing. I'll show you the scripts that I'm using.
Script 1. Globals.php
<?php
$dbhost="localhost";
$dbusername="Censored";
$dbpassword="Censored";
$dbname="Existence";
$connect = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname,$connect) or die ("Good job, idiot. You broke it.");
?>
Script 2. Add_News.php
<?php
include("Globals.php");
if($submit)
{//begin of if($submit).
// Set global variables to easier names
// and pervent sql injection and apostrophe to break the db.
$Title = mysql_real_escape_string($_POST['Title']);
$Text1 = mysql_real_escape_string($_POST['Text1']);
$Text2 = mysql_real_escape_string($_POST['Text2']);
//check if (title) field is empty then print error message.
if(!$Title){ //this means If the title is really empty.
echo "Error: Goddammit, put a title in the update..";
exit(); //exit the script and don't do anything else.
}// end of if
//run the query which adds the data gathered from the form into the database
$result = mysql_query("INSERT INTO news (Title, DTime, Text1, Text2)
VALUES ('$Title',NOW(),'$Text1','$Text2')",$connect);
//print success message.
echo "<b>Thank you! News added Successfully!<br>You'll be redirected to Home Page after (4) Seconds";
echo "<meta http-equiv=Refresh content=4;url=News.php>";
}//end of if($submit).
// If the form has not been submitted, display it!
else
{//begin of else
?>
<br>
<h3>::Add News</h3>
<form method="post" action="<?php echo $PHP_SELF ?>">
Title: <input name="Title" type="text" size="40" maxlength="255">
<br>
Text1: <textarea name="Text1" rows="7" cols="30"></textarea>
<br>
Text2: <textarea name="Text2" rows="7" cols="30"></textarea>
<br>
<input type="submit" name="submit" value="Add News">
</form>
<?
}//end of else
?>
Script 3. News.php
<?php
// load the configuration file.
include("Globals.php");
//load all news from the database and then OREDER them by newsid
//you will notice that newlly added news will appeare first.
//also you can OREDER by (dtime) instaed of (news id)
$result = mysql_query("SELECT * FROM News ORDER BY NewsID DESC",$connect);
//lets make a loop and get all news from the database
while($myrow = mysql_fetch_assoc($result))
{//begin of loop
//now print the results:
echo "<b>Title: ";
echo $myrow['Title'];
echo "</b><br>On: <i>";
echo $myrow['DTime'];
echo "</i><hr align=left width=160>";
echo $myrow['Text1'];
// Now print the options to (Read,Edit & Delete the news)
echo "<br><a href=\"read_more.php?newsid=$myrow[newsid]\">Read More...</a>
|| <a href=\"edit_news.php?newsid=$myrow[newsid]\">Edit</a>
|| <a href=\"delete_news.php?newsid=$myrow[newsid]\">Delete</a><br><hr>";
}//end of loop
?>
---------
Please take a moment and look these over and tell me what is being done wrong...
You can E-mail me at ExistenceInfinito@Gmail.com , or leave a comment here -- either way, I'll check often. Thank you for taking the time.
-Jordan.