Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › New to HTML/PHP Quick question?
New Posts  All Forums:Forum Nav:

New to HTML/PHP Quick question?

post #1 of 14
Thread Starter 
Alright, Im sorry that Im yet again, another noob posting right off the bat like this, but I am in a bit of a rush.

I need to use php in my html project tonight and it involves a form or table where the user enters information and then will hit submit or reset at the bottom.

My problem is, I dont know what to do with php. I know when they hit submit in the form, its supposed to open up another page or stay on that page and display that the info was received or whatever. But Im not sure how to even start this out.

I dont know how to incorporate php into this. I missed the lecture class two weeks ago and no one has been able to provide adequate notes on what I missed.

All I have right now is the html and the css page set up. I dont know how to do a single thing in php.

Please, someone help me. My assignment is due tomorrow by 9am.

Thanks again.
post #2 of 14
Hope I can help you out a bit here, if you're in a jam and need to get this done fast this is what I would do if in that position.

1) Download and run portableapps.com XAMPP
2) Read this php.net page to basically get the meat of what you need to code
3) Profit

If you need more help let me know, posting your code will help as I can check it for ya biggrin.gif

The flow of your code should be form page (which you've got done) that posts to itself, you'll capture that with PHP and just use echo() on all the different $_POST vars that you capture from the form.

Make a "website" in XAMPP and throw the file on there and run it, I'd call your file index.php for simplicities sake.

Oh yea you'll be able to run this from a thumb drive which'll make it that much easier to show it to the prof.
AMD Rig
(12 items)
 
  
CPUMotherboardGraphicsGraphics
8320 FX Gigabyte 990FX-UD3 XFX R9 270X XFX R9 270X 
RAMHard DriveOptical DriveCooling
Crucial Ballistix Sport Kingston V300 Bluray Cooler Master Seidon 240M 
OSKeyboardPowerCase
Windows 7 x64 Ultimate CM QuickFire Corsair CX750M Corsair 540 Air 
  hide details  
Reply
AMD Rig
(12 items)
 
  
CPUMotherboardGraphicsGraphics
8320 FX Gigabyte 990FX-UD3 XFX R9 270X XFX R9 270X 
RAMHard DriveOptical DriveCooling
Crucial Ballistix Sport Kingston V300 Bluray Cooler Master Seidon 240M 
OSKeyboardPowerCase
Windows 7 x64 Ultimate CM QuickFire Corsair CX750M Corsair 540 Air 
  hide details  
Reply
post #3 of 14
Thread Starter 
Right now for my products.php I have this,





extract($_POST);
echo "Thank you!";

if ( !preg_match("/^\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}$/", $phone ) )
{die("ERROR: Please provide your phone number in form (ddd) ddd-dddd.");
}
?>
[[[[This code in here because my professor wants us to]]]]






I dont know what to do now to get the info that they are entering on my products page to be incorporated with this.

Thanks for the help already!
post #4 of 14
Thread Starter 
I had the < html > and and everything in there but it didnt show up lol
post #5 of 14
index.php:
Code:
<form action="submit.php" method="POST">
  Field 1:<br />
  <input type="text" name="phone" /><br />
  <input type="submit" name="submit" value="submit />
</form>

submit.php:
Code:
<?php
  if (!isset($_POST['phone']))
    die('Please enter your phone number');
  $phone = $_POST['phone'];  
  if ( !preg_match("/^\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}$/", $phone ) )
    {die("ERROR: Please provide your phone number in form (ddd) ddd-dddd.");
  }

  echo 'Your phone number is:'. $phone;

?>


index.php will take the input. Forms require an action (the page it goes to) and a method (post or get). If you used GET the variables would be in the URL. If you use post they're sent directly to the server. Get should only be used for requesting, not for changing/submitting.
The submit page first checks to see if the post variable is set. If not, it throws an error. Then it assigns the post to a normal variable (to keep inline with your professors wants). Then it uses the provided code by your professor.
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
post #6 of 14
index.php:
Code:
<form action="submit.php" method="POST">
  Field 1:<br />
  <input type="text" name="phone" /><br />
  <input type="submit" name="submit" value="submit />
</form>

submit.php:
Code:
<?php
  if (!isset($_POST['phone']))
    die('Please enter your phone number');
  $phone = $_POST['phone'];  
  if ( !preg_match("/^\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}$/", $phone ) )
    {die("ERROR: Please provide your phone number in form (ddd) ddd-dddd.");
  }

  echo 'Your phone number is:'. $phone;

?>


index.php will take the input. Forms require an action (the page it goes to) and a method (post or get). If you used GET the variables would be in the URL. If you use post they're sent directly to the server. Get should only be used for requesting, not for changing/submitting.
The submit page first checks to see if the post variable is set. If not, it throws an error. Then it assigns the post to a normal variable (to keep inline with your professors wants). Then it uses the provided code by your professor.
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
post #7 of 14
Thread Starter 
now does this go in the products.php I made or does that go on the Products.html page?
post #8 of 14
I have no idea what your goals are or how its setup. Just giving an example of what you posted about before.
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
Dink
(20 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core I5 3570K Gigabyte UD3H Sapphire 7950 GSkill Ares 16gb 
Hard DriveOptical DriveCoolingOS
Samsung 840 500GB None Swiftech H220 Windows 7 Ultimate 
MonitorMonitorMonitorMonitor
Crossover 27" 27Q Acer 23" V233H Hanns-G 24" HH241 LG 55" LD520  
KeyboardPowerCaseMouse
Ducky Shine2 DK9008 with Reds Seasonic X750 Gold NZXT Switch 810 Mionix Naos 8200 
Mouse PadAudioAudioAudio
Mionix Ensis 320 LR: Focal 726 Sub: HSU VTF15-H Denon AVR1911 
  hide details  
Reply
post #9 of 14
Thread Starter 
my apologies, I thought you were responding the correct version of what I had or what I needed. Like I said, still pretty new to this stuff.

Basically, I have a form where they will enter the following: Name, Address, City, State, Zip, Email, Phone Number.
I also have a Radio button (3) for the type of payment: Visa, Master, Paypal.

When they enter the information, I need my website to do something. Like, Reply with "Your information has been revieced!" Or if they gave a fake email like "asdf@#.com" it would correct them with an error or something.

Apparently the one class I missed covered ALL of what Im trying to figure out. LOL tongue.gif
post #10 of 14
Quote:
Originally Posted by sheerjeenyus View Post

my apologies, I thought you were responding the correct version of what I had or what I needed. Like I said, still pretty new to this stuff.

Basically, I have a form where they will enter the following: Name, Address, City, State, Zip, Email, Phone Number.
I also have a Radio button (3) for the type of payment: Visa, Master, Paypal.

When they enter the information, I need my website to do something. Like, Reply with "Your information has been revieced!" Or if they gave a fake email like "asdf@#.com" it would correct them with an error or something.

Apparently the one class I missed covered ALL of what Im trying to figure out. LOL tongue.gif

It's ok, you have Google thumb.gif

PHP can be in HTML files or PHP files, it doesn't matter. If you want to do a basic separation of view from logic you can just include the PHP file in the HTML file at the top:
Code:
<?php
    include('product.php');
?>

All of the information you will need will be in $_POST array. If you want to get the contents of that array you can use var_dump, print_r, etc. If you ever need help with a PHP function just go to the PHP.net domain with the function name trailing it and the manual page for that function will load. Like this:
Code:
php.net/print_r

A good rule of thumb is to always check to see if a variable is set using isset. You can even test to see if the form was submitted by using isset on the submit button.
Code:
if(isset($_POST['submit']))
{
    // form logic
}

Edit: To include PHP in a .htm/html file your webserver has to be setup to handle it as such. It's easier to just use the php extension for all files.
Edited by cipp - 3/18/13 at 5:49pm
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › New to HTML/PHP Quick question?