A little help with my noob code

Discussions on developing plugins for the Cacti Plugin Architecture

Moderators: Developers, Moderators

Post Reply
Voiper99
Cacti User
Posts: 276
Joined: Thu Mar 01, 2007 5:43 pm
Location: Melbourne, Australia

A little help with my noob code

Post by Voiper99 »

Hi all, I have only ever done basic (and I mean very basic) coding and am now stuck already. I am following this guide - http://www.scribd.com/doc/128662/Create ... -PHP-MySQL to assist me in uderstanding how PHP and SQL work together.

This is my code so far:

Code: Select all

<HTML>
 <?php
if($submit)
{
$db = mysql_connect("localhost", "root","pass");
mysql_select_db("learndb",$db);

$first=$_POST[first];
$last=$_POST[last];
$nickname=$_POST[nickname];
$email=$_POST[email];
$salary=$_POST[salary];

$sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary) VALUES
('$first', '$last', '$nickname','$email','$salary')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
}
else
{?>
 <form method="post" action="input.php">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Nick Name:<input type="Text" name="nickname"><br>
E-mail:<input type="Text" name="email"><br>
Salary:<input type="Text" name="salary"><br>
<input type="Submit"name="submit" value=" Enter information"></form>
<?
}?>
</HTML>
When I click "Submit", the "Thank you! Information entered" message does not appear and the DB is not updated.

By the way, my register_globals is set to off which is why I have added the $_POST lines above. I'm sure you guys already knew that but I thought I should add it just in case I have done something wrong.

Thanks everyone.
Voiper99
Cacti User
Posts: 276
Joined: Thu Mar 01, 2007 5:43 pm
Location: Melbourne, Australia

Post by Voiper99 »

I fixed the issue by changing the if statement to:

Code: Select all

if($_POST["submit"])
I won't put "solved" in the title yet as I am sure I will have other noob questions :)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests