Please chech this code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aditya
Forum Newbie
Posts: 15
Joined: Mon Jan 15, 2007 7:44 am

Please chech this code

Post by aditya »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

<html>
<body>

<html>
<head>
<form  action="lastform.php" method="post">
<h3> REGISTRATION DETAILS</h3>
<table>
<tr><td>Name:</td><td> 
<input type="text" name="name1"></td></tr>
<tr><td>Email:</td><td> 
<input type="text" name="e-mail1" size="30"></td></tr>
<tr><td>Address:</td><td> 
<input type="text" name="address1" size="30"></td></tr>
<tr><td>ph Number:</td><td> 
<input type="text" name="Ph_number" size="30"></td></tr>
</table>
</br>

<input type="submit" value="continue" name="submit">
</form>


</body>
</html>


//second form

<?php
$as=$_POST['name1'];
$as1=$_POST['e-mail1'];
$as2=$_POST['address1'];
$as3=$_POST['Ph_number'];
?>

<?php

$user_name = "root";
$password = "";
$database = "aditya";
$server = "127.0.0.1";

$db_handle = mysql_connect($server,$user_name,$password);
$db_found = mysql_select_db($database, $db_handle);

if($db_found)
{

$result=mysql_query("INSERT INTO details(name,e-mail,address,Phnumber) VALUES('$as','$as1','$as2','$as3')");
mysql_close($db_handle);

print "Records added to the database";
}
else 

{
print "Database NOT Found ";
mysql_close($db_handle);

}

?>
<html>
<head>
<body>
<form  action="view.php" method="post">
<input type="submit" value="VIEW RECORDS" name="submit">
</body>
</head>
</html>


// third from

<?php
$user_name = "root";
$password = "";
$database = "aditya";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "SELECT * FROM details";
$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
print $db_field['name'] . "<BR>";
print $db_field['e-mail'] . "<BR>";
print $db_field['address'] . "<BR>";
print $db_field['Phnumber'] . "<BR>";
}

mysql_close($db_handle);

}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}


?>





my problem is i can send any values from form 1 to database. please how ? and very this code.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

what problem do you specifically have (error etc?) and what have you tried to solve it.
Did you try to read manual , there are examples howto work with form data and connect & insert data to database.
aditya
Forum Newbie
Posts: 15
Joined: Mon Jan 15, 2007 7:44 am

Please chech this code

Post by aditya »

My problem is i am unable to pass the values to database. please send code
aditya
Forum Newbie
Posts: 15
Joined: Mon Jan 15, 2007 7:44 am

Please chech this code

Post by aditya »

REGISTRATION DETAILS
Name:
Email:
Address:
ph Number:



in the above fields. i am trying to type in any word and send to the database . but that word can not save in database. so plese check the code one . please reply to me
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

when you submit the form... make var_dump($_POST) on top of your script see if expected data is there....
sorry won't give you any complete code.
also use error_reporting(E_ALL); on top of script and ini_set('display_errors','on'); That should give you a hint on whats wrong.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Post by Chalks »

Some security issues with your script... just a helpful reminder:
You don't validate your user input at all which is Bad. Nor do you make sure that all fields exist. Also, you allow sql injection. Here are some things/functions you'll want to check out for each of these issues.

Use regex to validate user input
isset() to see if data exists
mysql_real_escape_string() for sql injection


There may be more things to look at, but that will get you started.
Post Reply