Please help me with my code! Thanks in advance

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Audioslaved
Forum Newbie
Posts: 2
Joined: Tue Jun 10, 2003 11:46 pm
Location: Honolulu, HI
Contact:

Please help me with my code! Thanks in advance

Post by Audioslaved »

It is supposed to be really simple, one text field that submits to a DB table with two rows. Here is the code, for some reason it does not submit to the database. Any help would be greatly appreciated. Thank you.

Code: Select all

<?php

function defaultDisplay() &#123;
    include ('../header.php');
    echo "<form action="$SERVER&#1111;'PHP_SELF']" method="post">"
        ."<b>AOR</b> "
        ."<input type="text" name="title" size="50" maxlength="80"><br>";
    echo "<br><br><input type="submit" name="op" value="Submit">"
	."<br>(Submit)</form>";
    include ('../footer.php');
&#125;


function SubmitStory() &#123;

$db = mysql_connect("localhost", "********", "*******") or die("Sorry buddy that failed!");
mysql_select_db("audiosla_arc");

$title = mysql_escape_string($_POST&#1111;'title']);

$query = "INSERT INTO arc_aor VALUES (NULL, '$title')";
$result = mysql_query($query, $db);
    if(!$result) &#123;
    	echo "There was some sort of error, nice try ass!<br>";
     	exit();
    &#125;
    include ('../header.php');
    $query = "SELECT * from arc_aor";
    $result = mysql_query($query, $db);
    $waiting = sql_num_rows($result, $db);
    echo "<center><br>You just submitted $waiting To the Database. Thank you!</center>";
    include ('../footer.php');
&#125;

switch($op) &#123;

    case "Submit":
	SubmitStory();
	break;

    default:
	defaultDisplay();
	break;

&#125;

?>
[NOTE] The stars were purposely put there [/NOTE]
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

replace

Code: Select all

if(!$result) { 
       echo "There was some sort of error, nice try ass!<br>"; 
        exit(); 
    }
with

Code: Select all

if(!$result) {
  echo mysql_error();
  die();
}
And let me know what happens.
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

You are trying to submit the form to it's self but you can't becuase you are trying to access "PHP_SELF" from a undefined array $SERVER.

Try $_SERVER['PHP_SELF'] (note the underscore).

Regards,
Audioslaved
Forum Newbie
Posts: 2
Joined: Tue Jun 10, 2003 11:46 pm
Location: Honolulu, HI
Contact:

Post by Audioslaved »

It says "No Database Selected"
I have triple-checked PHPMYADMIN and confirmed what I have for my DB is correct.
User avatar
cactus
Forum Regular
Posts: 343
Joined: Tue Jun 10, 2003 4:16 am
Location: UK

Post by cactus »

Try passing your connection ($db) to the mysql_select_db() method:

mysql_select_db("audiosla_arc", $db);

Try it, it may be that simple, other wise check the spelling of your database name, it's this silly things that always pass people by :)

Regards,
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

if you build software that doesn't run, use errorhandling to find a problem. I use errorhandling by default.

Code: Select all

mysql_select_db("audiosla_arc");
Can be replaced with...

Code: Select all

mysql_select_db("audiosla_arc") or die("databaseerror: ".mysql_error());
Post Reply