Resend my activation email : Register : Log in 
BCF: Bike Chat Forums


Help a PHP/SQL virgin.

Reply to topic
Bike Chat Forums Index -> The Geek Zone
View previous topic : View next topic  
Author Message

Faldo
World Chat Champion



Joined: 05 Aug 2007
Karma :

PostPosted: 16:15 - 22 Jun 2010    Post subject: Help a PHP/SQL virgin. Reply with quote

Right, total n00b at this, so if anything I say doesn't make sense feel free to correct me, preferably without too much pisstaking.

I want to make a form, submit the data to an SQL database then send the user an email confirming the data that has been submitted.

I then want to be able to recreate that data on another webpage.

So, for example, I'll have text fields for name, location, favourite biscuit etc, then a dropdown list for country, maybe a check box for T&Cs confirmation. I want to send that info to the database (I can make MySQL database & tables with PHPmyAdmin right?). I then want another page to access the data and show it.

Can anyone point me to any Opensource scripts that I can have a play with?

Cheers Thumbs Up .
 Back to top
View user's profile Send private message You must be logged in to rate posts

The Shaggy D.A.
Super Spammer



Joined: 12 Sep 2008
Karma :

PostPosted: 16:29 - 22 Jun 2010    Post subject: Reply with quote

Tizag has good tutorials for PHP and MySQL :-

https://www.tizag.com/phpT/
https://www.tizag.com/mysqlTutorial/
____________________
Chances are quite high you are not in my Monkeysphere, and I don't care about you. Don't take it personally.
Currently : Royal Enfield 350 Meteor
Previously : CB100N > CB250RS > XJ900F > GT550 > GPZ750R/1000RX > AJS M16 > R100RT > Bullet 500 > CB500 > LS650P > Bullet Electra X & YBR125 > Bullet 350 "Superstar" & YBR125 Custom > Royal Enfield Classic 500 Despatch Limited Edition (28 of 200) & CB Two-Fifty Nighthawk > ER5
 Back to top
View user's profile Send private message You must be logged in to rate posts

Faldo
World Chat Champion



Joined: 05 Aug 2007
Karma :

PostPosted: 16:31 - 22 Jun 2010    Post subject: Reply with quote

The Shaggy D.A. wrote:
Tizag has good tutorials for PHP and MySQL :-

https://www.tizag.com/phpT/
https://www.tizag.com/mysqlTutorial/


Cheers Shag, I'll take a look at that later.
 Back to top
View user's profile Send private message You must be logged in to rate posts

Kickstart
The Oracle



Joined: 04 Feb 2002
Karma :

PostPosted: 16:47 - 22 Jun 2010    Post subject: Reply with quote

Hi

That should be very easy to do.

You can use phpmyadmin to create databases.

You are best off using a basic development setup on your own PC to write it and then putting it to a real server when it is ready. I use Wampserver but there are others which others prefer.

Watch out for SQL injection. Basically make sure you use mysql_real_escape_string.

Personally I would suggest finding a basic php script for anything and understanding how that works before moving on to try and write something.

But essentially you would want something like the following. Note that I haven't test run this in the slightest, but hopefully it will give you the right idea.

Code:

<?php

// Just got the countries in an array here, although realistically you would have them in a database instead.
$CountryArray = array(1 => 'Britain', 2 => 'Argentina', 5 => 'Brazil');
$ErrorMessage = '';

if ($_REQUEST['Submit'])
{
   // Submit button hit

   $username = $_REQUEST['username'];
   $userlocation = $_REQUEST['userlocation'];
   $userbiscuit = $_REQUEST['userbiscuit'];
   $usercountry = ((is_numeric($_REQUEST['usercountry'])) ? intval($_REQUEST['usercountry']) : 0); // If country isn't a valid interger then just use 0 instead, should be the id of it from the array at the top (or the id from the database)
   
   $Error = false;
   //Validate Input, set $Error = true if errors found
   
   
   if($Error)
   {
      $ErrorMessage = 'Fix them errors and try again';
   }
   else
   {   

      $dbms = 'mysql';
      $dbhost = 'yourhostname';
      $dbname = 'yourdatabasename';
      $dbuser = 'userid';
      $dbpasswd = 'password';

      // Make the database connection.
      $Conn = mysql_connect($dbhost,$dbuser,$dbpasswd);

      mysql_select_db($dbname,$Conn) or die(mysql_error());
      
      $sql = "INSERT INTO sometable (Id, Username, UserLocation, UserFavBiscuit, UserCountry) VALUES(NULL, '".mysql_real_escape_string($username)."', '".mysql_real_escape_string($userlocation)."', '".mysql_real_escape_string($userbiscuit)."', $usercountry') ";

      $void = mysql_query($sql) or die(mysql_error());
      
      // Send email
      $subject = 'A note for Faldo';
      $message = "The following details were entered on a form .\n";
      $message .= "A line with some details $username   $userlocation   $userbiscuit.\n";
      $message = wordwrap($message, 70);
      $headers = 'From: The Web Page' . "\r\n" .
      $headers .= "X-Mailer: PHP/" . phpversion()."\n";
      $headers .= "Importance: High\n";
      mail($to, $subject, $message, $headers);   
      
      // All went OK so redirect to another script.
      header('Location:AnotherScript.php');
   }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Faldo Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
   <form method="post" name="form1" target="_self">
      <input type='text' id='username' name='username' value='<?php echo $username ?>' /><br />
      <input type='text' id='userlocation' name='userlocation' value='<?php echo $userlocation ?>' /><br />
      <input type='text' id='userbiscuit' name='userbiscuit' value='<?php echo $userbiscuit ?>' /><br />
      <select name='usercountry' >
         <?php
         foreach($CountryArray AS $CountryId=>$CountryName)
         {
            echo "<option value='$CountryId'".(($usercountry == $CountryId) ? "selected='selected'" : '' )." >$CountryName</option><br />";
         }
         ?>
      </select>
      <?php echo $ErrorMessage; ?><br />
   </form>
</body>
</html>



All the best

Keith
____________________
Traxpics, track day and racing photographs - Bimota Forum - Bike performance / thrust graphs for choosing gearing
 Back to top
View user's profile Send private message Send e-mail You must be logged in to rate posts

Faldo
World Chat Champion



Joined: 05 Aug 2007
Karma :

PostPosted: 16:53 - 22 Jun 2010    Post subject: Reply with quote

Excellent Keith, a lot of that makes some sense to me. I'll have a play about with them tomorrow.

Thanks Thumbs Up .
 Back to top
View user's profile Send private message You must be logged in to rate posts
Old Thread Alert!

The last post was made 16 years, 80 days ago. Instead of replying here, would creating a new thread be more useful?
  Display posts from previous:   
This page may contain affiliate links, which means we may earn a small commission if a visitor clicks through and makes a purchase. By clicking on an affiliate link, you accept that third-party cookies will be set.

Post new topic   Reply to topic    Bike Chat Forums Index -> The Geek Zone All times are GMT + 1 Hour
Page 1 of 1

 
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Read the Terms of Use! - Powered by phpBB © phpBB Group
 

Debug Mode: ON - Server: birks (www) - Page Generation Time: 0.08 Sec - Server Load: 0.69 - MySQL Queries: 13 - Page Size: 50.55 Kb