Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Old 01-21-2005, 06:53 AM   PM User | #1
Existence
New to the CF scene

 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Existence is an unknown quantity at this point
Exclamation MySQL Not Responding...

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 Code:
<?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 Code:
<?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 Code:

<?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.
Existence is offline   Reply With Quote
Old 01-21-2005, 07:08 AM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,435
Thanks: 2
Thanked 38 Times in 38 Posts
Brandoe85 will become famous soon enough
Welcome here! It's not bothering, we are here to help.
Ok, where is $submit defined? Try changing your if statement to:
if(isset($_POST['submit'])), instead of if($submit)
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 01-21-2005, 07:12 AM   PM User | #3
Existence
New to the CF scene

 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Existence is an unknown quantity at this point
Oh my God. Thank you, Brando. That's exactly what it needed.

I've only begun to start with PHP, and I found this script online. I hope that one day I'll be able to code this from scratch.

Thank you for your time, Brando -- you're awesome.

Last edited by Existence; 01-21-2005 at 07:12 AM.. Reason: Brando was spelled "Brendoe" xD!!
Existence is offline   Reply With Quote
Old 01-21-2005, 07:15 AM   PM User | #4
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,435
Thanks: 2
Thanked 38 Times in 38 Posts
Brandoe85 will become famous soon enough
It's no problem at all. good luck with future coding!
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 01-21-2005, 07:24 AM   PM User | #5
Existence
New to the CF scene

 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Existence is an unknown quantity at this point
Alright, now I have a second question -- Because this code ( from what I can read ) will display every archived file, I don't know how to only grab the top five rows from my DB. Is it like ( In the SQL of "SELECT * FROM news ORDER BY NewsID DESC" ) Do I change it from "SELECT * FROM news ORDER BY NewsID DESC FETCH TOP 5 ROWS " or something. I feel like an idiot. Haha.

If you could help me with this final thing, my script will be completed.
Existence is offline   Reply With Quote
Old 01-21-2005, 07:36 AM   PM User | #6
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,435
Thanks: 2
Thanked 38 Times in 38 Posts
Brandoe85 will become famous soon enough
You could do, SELECT * FROM news ORDER BY NewsID DESC LIMIT 5.
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 01-21-2005, 07:44 AM   PM User | #7
Existence
New to the CF scene

 
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Existence is an unknown quantity at this point
Haha, thanks again, padre. You're a Genius.
Existence is offline   Reply With Quote
Old 01-21-2005, 07:46 AM   PM User | #8
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,435
Thanks: 2
Thanked 38 Times in 38 Posts
Brandoe85 will become famous soon enough
You're welcome!
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:58 AM.

Home - Contact Us - Archives - Link to CF - Resources - Top 

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.