Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support
It is currently Thu Jul 24, 2014 2:23 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: A little help with my noob code
PostPosted: Wed Aug 11, 2010 5:58 pm 
Offline
Cacti User

Joined: Thu Mar 01, 2007 5:43 pm
Posts: 275
Location: Melbourne, Australia
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-dynamic-sites-with-PHP-MySQL to assist me in uderstanding how PHP and SQL work together.

This is my code so far:

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2010 6:07 pm 
Offline
Cacti User

Joined: Thu Mar 01, 2007 5:43 pm
Posts: 275
Location: Melbourne, Australia
I fixed the issue by changing the if statement to:

Code:
if($_POST["submit"])


I won't put "solved" in the title yet as I am sure I will have other noob questions :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group