Web Design Forum: Input data from a form to database - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Input data from a form to database Rate Topic: -----

#1 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 07:36 AM

Hello friends,

i was just following this tutorialof how to input data from a form inside a database but seems to be lost somewhere



After i make the form 

and insert.php they havent mentioned to create a VALUES table in the database?

sorry am i right?


0

#2 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 07:46 AM

I think the tutorial is more of a concepts so yes you are correct

read step 3 again and replace the values as you need
0

#3 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 08:00 AM

View PostGeeks, on 16 March 2010 - 07:46 AM, said:

I think the tutorial is more of a concepts so yes you are correct

read step 3 again and replace the values as you need


so i have to make  a results.php to display the data but how do i have any relation between the two




data.html

<!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" xml:lang="en" lang="en">

   <head>
   <title>Database </title>


   </head>
   
   <body>
   
     <form action="insert.php" method="post">
  Value1: <input type="text" name="field1-name"><br/>
  Value2: <input type="text" name="field2-name"><br/>
  Value3: <input type="text" name="field3-name"><br/>
  Value4: <input type="text" name="field4-name"><br/>
  Value5: <input type="text" name="field5-name"><br/>
  <input type="submit">
  </form>
  
   
   
   
   
   </body>
   
   
</html>



insert.php
<?php

  $username="sash_007";
  $password="";
  $database="your_databse";
  
  $field1-name=$_POST['Value1'];
  $field2-name=$_POST['Value2'];
  $field3-name=$_POST['Value3'];
  $field4-name=$_POST['Value4'];
  $field5-name=$_POST['Value5'];

  mysql_connect (localhost,$username,$password);
  @mysql_select_db($database) or die ("Unable to select database");
  
  $query = "INSERT INTO tablename VALUES
  ('','$field-name','$field2-name','field3-name','field4-name','field5-name');
  
  mysql_query($query);
  mysql_close();




?>


result.php

<?php


$username="sash_007";
$password="";
$database="your_databse";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$query="SELECT * VALUES";
$result=mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

echo "<b><center>Database Outout</center></b><br/><br/>"

$i=0;
while ($i < $num)  {

 $field1-name=mysql1_result ($result,$i,"field1-name");
 $field2-name=mysql1_result ($result,$i,"field2-name");
 $field3-name=mysql1_result ($result,$i,"field3-name");
 $field4-name=mysql1_result ($result,$i,"field4-name");
 $field5-name=mysql1_result ($result,$i,"field5-name");
 
 echo "<b>$field1-name<br/>
 $field2-name</b><br/>$field3-name<br/>$field4-name<br/>$field5-name<hr><br/>";
 
 $i++;
 
}

?>




the what is the name of this page


<html>
<body>
<?php
$username="username";
$password="password";
$database="your_database";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM tablename";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Value1</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value2</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value3</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value4</font></th>
<th><font face="Arial, Helvetica, sans-serif">Value5</font></th>
</tr>

<?php
$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"field1");
$f2=mysql_result($result,$i,"field2");
$f3=mysql_result($result,$i,"field3");
$f4=mysql_result($result,$i,"field4");
$f5=mysql_result($result,$i,"field5");
?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td>
</tr>

<?php
$i++;
}
?>
</body>
</html>





am i going right?  :blink:
0

#4 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 08:32 AM

lets start over it's easier than you think

lets do one at a time

have you created a database ?
0

#5 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 09:13 AM

View PostGeeks, on 16 March 2010 - 08:32 AM, said:

lets start over it's easier than you think

lets do one at a time

have you created a database ?



ya i have

 your_databse



user-sash_007

pass-none


0

#6 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 09:17 AM

your website looks awesome by the way, you have a real talent
what tables does your DB have and how are those tables structured eg:

[table1]
[ID][item_name][item_desrciption]


[table2]
[field1][field2][field3][field4]
0

#7 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 09:30 AM

View PostGeeks, on 16 March 2010 - 09:17 AM, said:

your website looks awesome by the way, you have a real talent
what tables does your DB have and how are those tables structured eg:

[table1]
[ID][item_name][item_desrciption]


[table2]
[field1][field2][field3][field4]


thanks

so in this case according to the example i have to make 2 tables ?



0

#8 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 09:41 AM

no, ignore the example we are going to start over

how do you work on your database ?

phpmyadmin ?
0

#9 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 09:50 AM

View PostGeeks, on 16 March 2010 - 09:41 AM, said:

no, ignore the example we are going to start over

how do you work on your database ?

phpmyadmin ?




ya



0

#10 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 10:03 AM

create new database named test_data_base
create a table in test_data_base named test_table_1 give it 4 fields
name these fields
ID - Set to number, and primary key, and to auto increment
Name - Set to Text
Surname - Set To Text
Email - Set to Text

so you will have
[test_data_base]
[test_table_1]
[ID][NAME][SURNAME][EMAIL]

now in phpmyadmin open test_table_1 click on insert and add some data for 1 user
leave ID blank, it will set automatically
Name = John
Surname = Doe
Email = jdoe@mymail.com

0

#11 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 10:35 AM

Hello geek

hope i am going rght Attached File  A.jpg (51.95K)
Number of downloads: 4


0

#12 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 10:47 AM

almost, change ID type to number and put a check on A_I
0

#13 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 11:18 AM

hello i did this



Attached File  A.jpg (50.52K)
Number of downloads: 3



and got this error



Fatal error: Maximum execution time of 60 seconds exceeded in C:\wamp\apps\phpmyadmin3.2.0.1\libraries\relation.lib.php on line 9
0

#14 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 11:24 AM

it looks right, has it stored that now ?
0

#15 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 11:46 AM

ok now i get thisAttached File  A.jpg (80.78K)
Number of downloads: 5
0

#16 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 11:49 AM

looks good click on browse and see what you get
0

#17 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 11:53 AM

i see this

Attached File(s)

  • Attached File  A.jpg (27.53K)
    Number of downloads: 4

0

#18 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 12:11 PM

perfect,
you have a DB and a TABLE with some DATA&nbsp;<div><br></div><div>EDIT : my code got all messed up gonna repost</div>
0

#19 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 12:16 PM

lets create a page to print the data from the table

call it print_data.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></head>
  <body>
    <?php
      // we are just going to show how the php talks to the DB here
      $username="sash_007";   //set username
      $password="";   //set password
      $database = "test_data_base";  //set database
      $server = "localhost";  //set server
      $sqlcon = mysql_connect($server,$username,$password);  //connect to DB 
      @mysql_select_db($database) or die( "Unable to select database");  //connect to table
      $query = "SELECT * from test_table_1"; //set query
      $data = mysql_query($query) or die('Query failed: ' . mysql_error()); //fetch data
      unset($query); //save resources by killing unused variables
      if (!$data ) //some simple error checking 
      { 
        //communicate with user if there is an error
        echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
        exit; //stop processing if there is an error
      }
      else
      {   
        while($row = mysql_fetch_row($data)) //loop through results which are now matched with parameters
        { 
          //echo each value
          echo "ID = $row[0]<br />";   // indexing always starts at 0
          echo "NAME = $row[1]<br />";
          echo "SURNAME = $row[2]<br />";
          echo "EMAIL = $row[3]<br />";              
        }
      } 
      unset($data); //save resources by killing unused variables
    ?>
  </body>
</html>    



0

#20 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 12:21 PM

View PostGeeks, on 16 March 2010 - 12:16 PM, said:

lets create a page to print the data from the table

call it print_data.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></head>
  <body>
    <?php
      // we are just going to show how the php talks to the DB here
      $username="sash_007";   //set username
      $password="";   //set password
      $database = "test_data_base";  //set database
      $server = "localhost";  //set server
      $sqlcon = mysql_connect($server,$username,$password);  //connect to DB 
      @mysql_select_db($database) or die( "Unable to select database");  //connect to table
      $query = "SELECT * from test_table_1"; //set query
      $data = mysql_query($query) or die('Query failed: ' . mysql_error()); //fetch data
      unset($query); //save resources by killing unused variables
      if (!$data ) //some simple error checking 
      { 
        //communicate with user if there is an error
        echo "sorry there was an error if you think we should know about this please let us know at <a href='mailto:email@server.com'>email@server.com</a>"; 
        exit; //stop processing if there is an error
      }
      else
      {   
        while($row = mysql_fetch_row($data)) //loop through results which are now matched with parameters
        { 
          //echo each value
          echo "ID = $row[0]<br />";   // indexing always starts at 0
          echo "NAME = $row[1]<br />";
          echo "SURNAME = $row[2]<br />";
          echo "EMAIL = $row[3]<br />";              
        }
      } 
      unset($data); //save resources by killing unused variables
    ?>
  </body>
</html>    







it shows 




Unable to select database


0

#21 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 12:26 PM

looks like you put a space infront of the name of you database, not a problem

change&nbsp;<div>
$database ="test_data_base";//set database
<div>to&nbsp;</div><div>
$database =" test_data_base";//set database
</div><div>&nbsp;note the space

</div></div>
0

#22 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 12:38 PM

View PostGeeks, on 16 March 2010 - 12:26 PM, said:

looks like you put a space infront of the name of you database, not a problem

change&nbsp;<div>
$database ="test_data_base";//set database
<div>to&nbsp;</div><div>
$database =" test_data_base";//set database
</div><div>&nbsp;note the space

</div></div>



ya it shows 




ID = 1
NAME = Jon
SURNAME = Doe
EMAIL = jdoe@mymail.com



0

#23 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 12:46 PM

perfect , lets create simple form page, it will not do anything yet.

<div>This site is not loving me</div><div><br></div><div>will repost</div>
0

#24 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 12:49 PM

create this page

call it new_user.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></head>
  <body>
    <!-- THIS FORM WILL SEND THE DATA TO update_page.php then update_page.php will handle it -->
    <form method="post" action="update_page.php">
      NAME : <input type="text" name="input_name" /><!--USER WILL ENTER NAME HERE -->
      <br />   
      SURNAME : <input type="text" name="input_surname" /><!--USER WILL ENTER SURNAME HERE -->
      <br />
      EMAIL : <input type="text" name="input_email" /><!--USER WILL ENTER EMAIL HERE -->
      <br /><br />
      <input type="submit" value="add user"><!-- THE SUBMIT BUTTON SEND THE INFORMATIO -->
    </form>
  </body>
</html>    


0

#25 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 12:58 PM

View PostGeeks, on 16 March 2010 - 12:49 PM, said:

create this page

call it new_user.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></head>
  <body>
    <!-- THIS FORM WILL SEND THE DATA TO update_page.php then update_page.php will handle it -->
    <form method="post" action="update_page.php">
      NAME : <input type="text" name="input_name" /><!--USER WILL ENTER NAME HERE -->
      <br />   
      SURNAME : <input type="text" name="input_surname" /><!--USER WILL ENTER SURNAME HERE -->
      <br />
      EMAIL : <input type="text" name="input_email" /><!--USER WILL ENTER EMAIL HERE -->
      <br /><br />
      <input type="submit" value="add user"><!-- THE SUBMIT BUTTON SEND THE INFORMATIO -->
    </form>
  </body>
</html>    




ya done



0

#26 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 01:01 PM

now we create the page that does the updatethis is a very simple version, it won't check for duplicates etc. but it will give you an idea<div><br></div><div>EDIT : this site hates me will repost</div>
0

#27 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 01:03 PM

name this page update_page.php

This post has been edited by Geeks: 16 March 2010 - 01:04 PM

0

#28 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 01:04 PM

name this page update_page.php


[/size][/color][/size][/font]
[font="arial, verdana, tahoma, sans-serif"][size="3"][color="#1C2837"][size=2]
<!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></head>
  <body>
  <?php
      $username="sash_007";  //set username
      $password="";   //set password
      $database = "test_data_base";  //set database
      $server = "localhost";  //set server
      $sqlcon = mysql_connect($server,$username,$password);  //connect to DB 
      @mysql_select_db($database) or die( "Unable to select database");  //connect to table
      
      // the data that was sent is stored in a variable called $_POST
      
      $new_name = $_POST["input_name"];
      $new_surname = $_POST["input_surname"];
      $new_email = $_POST["input_email"];
      
      $update_query = "INSERT INTO `test_data_base`.`test_table_1` ( `ID`, `name` , `surname` , `email` ) 
                       VALUES (NULL , '$new_name', '$new_surname', '$new_email');";
      $update = mysql_query($update_query) or die('Query failed: ' . mysql_error());
      echo "<h1 align='center'>USER ADDED</h1>";      
   ?>
   
   <!-- THIS FORM WILL SEND THE DATA TO update_page.php then update_page.php will handle it -->
    <form method="post" action="update_page.php">
      NAME : <input type="text" name="input_name" /><!--USER WILL ENTER NAME HERE -->
      <br />   
      SURNAME : <input type="text" name="input_surname" /><!--USER WILL ENTER SURNAME HERE -->
      <br />
      EMAIL : <input type="text" name="input_email" /><!--USER WILL ENTER EMAIL HERE -->
      <br /><br />
      <input type="submit" value="add user"><!-- THE SUBMIT BUTTON SEND THE INFORMATIO -->
    </form>
   </body>
</html>    
[/size][/color][/size][/font]
[font="arial, verdana, tahoma, sans-serif"][size="3"][color="#1C2837"][size=2]


0

#29 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 01:07 PM

done now when i try to add new user i get this error





Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\wamp\www\practice\update_page.php on line 10
Unable to select database

shld i  drop root from privileges



0

#30 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 01:10 PM

try this , I changed the username and password

always just double check that.


<!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></head>
  <body>
  <?php
      $username="sash_007";  //set username
      $password="";   //set password
      $database = " test_data_base";  //set database
      $server = "localhost";  //set server
      $sqlcon = mysql_connect($server,$username,$password);  //connect to DB 
      @mysql_select_db($database) or die( "Unable to select database");  //connect to table
      
      // the data that was sent is stored in a variable called $_POST
      
      $new_name = $_POST["input_name"];
      $new_surname = $_POST["input_surname"];
      $new_email = $_POST["input_email"];
      
      $update_query = "INSERT INTO `test_data_base`.`test_table_1` ( `ID`, `name` , `surname` , `email` ) 
                       VALUES (NULL , '$new_name', '$new_surname', '$new_email');";
      $update = mysql_query($update_query) or die('Query failed: ' . mysql_error());
      echo "<h1 align='center'>USER ADDED</h1>";      
   ?>
   
   <!-- THIS FORM WILL SEND THE DATA TO update_page.php then update_page.php will handle it -->
    <form method="post" action="update_page.php">
      NAME : <input type="text" name="input_name" /><!--USER WILL ENTER NAME HERE -->
      <br />   
      SURNAME : <input type="text" name="input_surname" /><!--USER WILL ENTER SURNAME HERE -->
      <br />
      EMAIL : <input type="text" name="input_email" /><!--USER WILL ENTER EMAIL HERE -->
      <br /><br />
      <input type="submit" value="add user"><!-- THE SUBMIT BUTTON SEND THE INFORMATIO -->
    </form>
   </body>
</html>    



0

#31 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 01:23 PM

View PostGeeks, on 16 March 2010 - 01:10 PM, said:

try this , I changed the username and password

always just double check that.


<!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></head>
  <body>
  <?php
      $username="sash_007";  //set username
      $password="";   //set password
      $database = " test_data_base";  //set database
      $server = "localhost";  //set server
      $sqlcon = mysql_connect($server,$username,$password);  //connect to DB 
      @mysql_select_db($database) or die( "Unable to select database");  //connect to table
      
      // the data that was sent is stored in a variable called $_POST
      
      $new_name = $_POST["input_name"];
      $new_surname = $_POST["input_surname"];
      $new_email = $_POST["input_email"];
      
      $update_query = "INSERT INTO `test_data_base`.`test_table_1` ( `ID`, `name` , `surname` , `email` ) 
                       VALUES (NULL , '$new_name', '$new_surname', '$new_email');";
      $update = mysql_query($update_query) or die('Query failed: ' . mysql_error());
      echo "<h1 align='center'>USER ADDED</h1>";      
   ?>
   
   <!-- THIS FORM WILL SEND THE DATA TO update_page.php then update_page.php will handle it -->
    <form method="post" action="update_page.php">
      NAME : <input type="text" name="input_name" /><!--USER WILL ENTER NAME HERE -->
      <br />   
      SURNAME : <input type="text" name="input_surname" /><!--USER WILL ENTER SURNAME HERE -->
      <br />
      EMAIL : <input type="text" name="input_email" /><!--USER WILL ENTER EMAIL HERE -->
      <br /><br />
      <input type="submit" value="add user"><!-- THE SUBMIT BUTTON SEND THE INFORMATIO -->
    </form>
   </body>
</html>    







changed and i got this


Query failed: Table 'test_data_base. test_table_1' doesn't exist



i tried adding spaceAttached File  A.jpg (45.57K)
Number of downloads: 3


0

#32 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 01:29 PM

try :


<!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></head>
  <body>
  <?php
      $username="sash_007";  //sash_007 //set username
      $password="";   //set password
      $database = " test_data_base";  //set database
      $server = "localhost";  //set server
      $sqlcon = mysql_connect($server,$username,$password);  //connect to DB 
      @mysql_select_db($database) or die( "Unable to select database");  //connect to table
      
      // the data that was sent is stored in a variable called $_POST
      
      $new_name = $_POST["input_name"];
      $new_surname = $_POST["input_surname"];
      $new_email = $_POST["input_email"];
      
      $update_query = "INSERT INTO test_table_1 ( `ID`, `name` , `surname` , `email` ) 
                       VALUES (NULL , '$new_name', '$new_surname', '$new_email');";
      $update = mysql_query($update_query) or die('Query failed: ' . mysql_error());
      echo "<h1 align='center'>USER ADDED</h1>";      
   ?>
   
   <!-- THIS FORM WILL SEND THE DATA TO update_page.php then update_page.php will handle it -->
    <form method="post" action="update_page.php">
      NAME : <input type="text" name="input_name" /><!--USER WILL ENTER NAME HERE -->
      <br />   
      SURNAME : <input type="text" name="input_surname" /><!--USER WILL ENTER SURNAME HERE -->
      <br />
      EMAIL : <input type="text" name="input_email" /><!--USER WILL ENTER EMAIL HERE -->
      <br /><br />
      <input type="submit" value="add user"><!-- THE SUBMIT BUTTON SEND THE INFORMATIO -->
    </form>
   </body>
</html>    



0

#33 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 01:41 PM

ya now it showsAttached File  A.jpg (27.17K)
Number of downloads: 3
0

#34 User is offline   Geeks 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 321
  • Joined: 07-October 09
  • Reputation: 11
  • Gender:Male
  • Location:South Africa
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 16 March 2010 - 01:48 PM

what else do you need ?
1

#35 User is offline   sash_007 

  • Trap Grand Marshal Member
  • PipPipPipPip
  • Group: Members
  • Posts: 638
  • Joined: 18-July 09
  • Reputation: 5
  • Gender:Male
  • Experience:Intermediate
  • Area of Expertise:Web Designer

Posted 16 March 2010 - 01:50 PM

View PostGeeks, on 16 March 2010 - 01:48 PM, said:

what else do you need ?



its ok buddy thanks for what u have done :clapping: for guiding me in my database venture



0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users