help MySQL PHP form

This is a discussion on help MySQL PHP form within the PHP General forums, part of the PHP Programming Forums category; I am new to mysql and php. I am trying to learn this in order to implement a web based ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-14-2007
shaggynuts24@gmail.com
 
Posts: n/a
Default help MySQL PHP form

I am new to mysql and php. I am trying to learn this in order to
implement a web based database to keep track of camera inventory along
with RMA and cost information. I am not sure what I am doing wrong
with this.

I am trying to set this up so that when someone hits submit it enters
the information into the database.

I would also like to find a way to get it to append the information as
well. I have no prior html, php, or mysql experience.

<?php
// database connection
mysql_connect("localhost", "username", "password") or
die(mysql_error());
mysql_select_db("cameradb") or die(mysql_error());

//$query definition
$query = "INSERT INTO cameras (SN, MAC_Adress, CAM_Type, CAM_Location,
CAM_Name, RMA_Number, RMA_Description,
RMA_Req_Date, RMA_Rec_Date, RMA_Ship_Date, RMA_Return_Date, RMA_Cost)

VALUES
('$_post[SN]','$_post[MAC_Adress]',
'$_post[CAM_Type]', '$_post[CAM_Location]', '$_post[CAM_Name]',
'$_post[RMA_Number]', '$_post[RMA_Description]',
'$_post[RMA_Req_Date]', '$_post[RMA_Rec_Date]',
'$_post[RMA_Ship_Date]', '$_post[RMA_Return_Date]',
'$_post[RMA_Cost]')";

{

?>
//form definition and assigning variables
<form action ="<?php mysql_query($query) ?>" method="post">
<p>Camera Serial Number: <input type="text" name="SN" /></p>
<p>Mac Adress: <input type="text" name="Mac_adress" /></p>
<p>Camera Types: <input type="text" name="cam_type" /></p>
<p>Camera Loacation: <input type="text" name="cam_location" /></p>
<p>Camera Name: <input type="text" name="cam_name" /></p>
<p>RMA Number: <input type="text" name="RMA_Number" /></p>
<p>RMA Description: <input type="text" name="RMA_Description" /></p>
<p>RMA Request Date: <input type="text" name="RMA_Req_date" /></p>
<p>RMA Recieve Date: <input type="text" name="RMA_Rec_date" /></p>
<p>RMA Ship Date: <input type="text" name="RMA_Ship_Date" /></p>
<p>RMA Return Date: <input type="text" name="RMA_Return_date" /></p>
<p>RMA Cost: <input type="text" name="RMA_Cost" /></p>
<p><input type="submit" /></p>
</form>

<?php
}

?>

Reply With Quote
  #2 (permalink)  
Old 05-15-2007
Lammi
 
Posts: n/a
Default Re: help MySQL PHP form

On 14 Mai, 20:33, "shaggynut...@gmail.com" <shaggynut...@gmail.com>
wrote:

try this (f. e., there are many ways to do this):


> <?php

if ($_POST['bla'] != '')
{

// database connection
mysql_connect("localhost", "username", "password") or
die(mysql_error());
mysql_select_db("cameradb") or die(mysql_error());

//$query definition
$query = "INSERT INTO cameras (SN, MAC_Adress, CAM_Type,
CAM_Location,
CAM_Name, RMA_Number, RMA_Description,
RMA_Req_Date, RMA_Rec_Date, RMA_Ship_Date, RMA_Return_Date, RMA_Cost)

VALUES
('$_post[SN]','$_post[MAC_Adress]',
'$_post[CAM_Type]', '$_post[CAM_Location]', '$_post[CAM_Name]',
'$_post[RMA_Number]', '$_post[RMA_Description]',
'$_post[RMA_Req_Date]', '$_post[RMA_Rec_Date]',
'$_post[RMA_Ship_Date]', '$_post[RMA_Return_Date]',
'$_post[RMA_Cost]')";
}

?>
<html>
<head>
<title>My first PHP Site</title>
</head>
<body>

//form definition and assigning variables
<form action ="<?php ECHO $_SERVER['PHP_SELF'] ?>" method="post">
<input type="hidden" name="bla" value="blubb">
<p>Camera Serial Number: <input type="text" name="SN" /></p>
<p>Mac Adress: <input type="text" name="Mac_adress" /></p>
<p>Camera Types: <input type="text" name="cam_type" /></p>
<p>Camera Loacation: <input type="text" name="cam_location" /></p>
<p>Camera Name: <input type="text" name="cam_name" /></p>
<p>RMA Number: <input type="text" name="RMA_Number" /></p>
<p>RMA Description: <input type="text" name="RMA_Description" /></p>
<p>RMA Request Date: <input type="text" name="RMA_Req_date" /></p>
<p>RMA Recieve Date: <input type="text" name="RMA_Rec_date" /></p>
<p>RMA Ship Date: <input type="text" name="RMA_Ship_Date" /></p>
<p>RMA Return Date: <input type="text" name="RMA_Return_date" /></p>
<p>RMA Cost: <input type="text" name="RMA_Cost" /></p>
<p><input type="submit" /></p>
</form>
</body>
</html>


save that fiel as something.php and point your browser to the
matchingurl.

have fun!

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:27 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0