Php/mysql Programmers, Please Help Me Out !

A Member? Please Login  
type your username and password to login
Date: October 12, 2008, 11:08 AM
248984 members and 147558 Topics
Latest Member: Aunissilbonliz
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Php/mysql Programmers, Please Help Me Out !
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Php/mysql Programmers, Please Help Me Out !  (Read 751 views)
MT
Php/mysql Programmers, Please Help Me Out !
« on: July 20, 2007, 10:59 PM »

dEAR Gurus,

I just installed mysql, Php and Apache into my system using WAMP CD.
 
I just started learning PHP and Mysql. I was just trying to add 3 fields in my html (namely name , address and Sex)into Mysql database. After running the program, I went to check mysql if those items were actually added, but it was actually added with everything blank out ie. the table in the database increased in row, but there's nothing inside despite filling out the forms in my html.

I have been on this for the past 3 days and couldnt figure out the problem. I'm getting so discouraged now, please help ,


I have this code in my PHP :

<?php
$conn = mysql_connect("localhost", "root","") or die("unable to connect first phase");
mysql_select_db("england",$conn) or die("select error");
$nko = "insert into uk(name,address,sex) values('$oruko','$addr','$se')";
mysql_query($nko) or die (mysql_error());
echo "ADDED";
?>

This in my html Code
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>, Latest, </title>
</head>

<body>
<center>
  <b> <font color="blue">This Is My Experiment, </font></b>
</center>

<form id="form1" name="form1" method="post" action="wapa.php">
  <p>
   <table width="500" border="0" cellpadding="1">
  <tr>
    <td width="70">Name :  </td>
    <td width="48"><input type = "text" name = "oruko" /></td>
      </tr>
  <tr>
    <td>Address :</td>
    <td><input type = "text" name = "addr" /></td>
   
  </tr>
  <tr>
    <td>Sex :</td>
    <td><input type = "text" name = "se" size = "3"/></td>
   </tr>
<tr>
<td></td>
<td><input type = "submit" value = "OLUGBON" name = "submit" />
</table>

   
   
  </p>
  <p>
    <label>I hope u will love this, </label>
  </p>
</form>
<p>&nbsp;</p>
</body>

</html>
Cactus (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #1 on: July 21, 2007, 05:18 AM »

u wrote

$nko = "insert into uk(name,address,sex) values('$oruko','$addr','$se')";


it ought to be

$nko = "insert into uk(name,address,sex) values($oruko,$addr,$se)";
MT
Re: Php/mysql Programmers, Please Help Me Out !
« #2 on: July 21, 2007, 03:39 PM »

Still not working Angry
Cactus (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #3 on: July 21, 2007, 04:46 PM »

and hope u named the file for the php script wapa.php
IronFist (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #4 on: July 21, 2007, 04:47 PM »

could you put up your wapa.php code. I believe wapa.php should handle your query.
try instantiating the html form variables first in your wapa.php e.g.
Code:
<?
$oruko = $_POST["oruko"];
$addr = $_POST["addr"];
$se = $_POST["sex"];
?>

then your mysql query can then follow to handle your form.
smartsoft (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #5 on: July 21, 2007, 05:05 PM »

Wapa.php
====================================================================================
<? php

include  ("dbinfo.php");
//Declare your variables man ! dude

$name = addslashes($_POST['name']);
$address = addslashes($_POST['address']);
$sex = addslashes($_POST['sex']);

// if i hit the submit button, it should insert my records
if($wapa){
$sql = " INSERT INTO uk (name,address,sex)VALUES("$name", "$address", "$sex")";
echo " Your information inserted successfully";
}else {
echo " Sorry you entry can not be registerd at this time ";
}
?>




db.php
=====================================================================================
Copy into your db information i mean in a notepad and save it as dbinfo.php change the details oo

<?php

$database = "dbname";
$host = " localhost";
$username = "smartsoft";
$password = " nairaland";

$conn = mysql_connect ("locahost", "root", "")or die ("cannot connect at this time");
$db = mysql_select_db ("dbname",$conn)or die (mysql_error());
?>

Note : remember that i don't need to put my password because i'm using XAMPPS, it's when i want to upload i can now put in my password.

=====================================================================================

I didn't test it ooo just try and test it,  any problem just let me know i will fix and it will work got to run to church now see ya.

Hey is (uk) your table or Database  huh ? Check that well ooooooo
MT
Re: Php/mysql Programmers, Please Help Me Out !
« #6 on: July 21, 2007, 07:28 PM »

@ironfist

Thanks. It worked. It got submitted into the database. However, I need to get cleared.

Is it anytime I try to submit a form that I have to instantiate the variable form or is it peculiar to my example alone. I asked this question because the textbook that I followed word for word didnt even ask me to instantiate.

please get me clarified on this.

@All

Thanks for being your brother's keeper. One day u will be remembered when i create a webiste more powerful than nairaland Cheesy
opensource (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #7 on: August 05, 2007, 12:08 AM »

you can also try place it in a if {} statement ,  then go for customs errors will help you will building more complex application ,  Also you need to do Object oriented programming and have security in mind when coding .


Always have a file called "conect.php" which makes the db connection placed somewhere else on the host

the reuse it by call

require_once('conect.php');

register then the sections and continue

well that complex ,  its really a good start we were ones there
Ka (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #8 on: August 05, 2007, 02:03 PM »

Quote from: MT
Is it anytime I try to submit a form that I have to instantiate the variable form or is it peculiar to my example alone. I asked this question because the textbook that I followed word for word didnt even ask me to instantiate.

As you probably know, when you send the information in a form to a script (like wapa.php in your case), the values that have been entered or selected in each of the form elements are sent in a $_POST array. Again, in your case, people would have entered a value in your oruko, addr and se text fields. These values will be put in the $_POST array.

So if you want to insert these values that have been entered into your database, you have to first get them from the $_POST array, and that's what IronFist was doing when he wrote this:

Quote
$oruko = $_POST["oruko"];
$addr = $_POST["addr"];
$se = $_POST["sex"];

In other words, he declared variables to hold the values entered into these form elements, and then used the values that were now in these variables in the query.

Of course, you could just write a query like this:

Quote
$nko = "insert into uk(name,address,sex) values($_POST["oruko"],$_POST["addr"],$_POST["se"])";

but I think this wouldn't be very readable.
bakenda (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #9 on: August 06, 2007, 06:20 PM »

@MT (and others who can be of help).

I'm hearing about the WAMP Cd for the first time here.
Ive been looking for something like that.
I used to test run my codes directly on the server,
I downloaded the WINLAMP package but there was
download error.
How can I get a copy of the WAMP Cd?
Thanks.
opensource (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #10 on: August 06, 2007, 11:18 PM »

get easyPhp  its better and good

if you need i can assist  but don't flood me with pm just post here i will upload to an FTP
bakenda (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #11 on: August 09, 2007, 05:55 PM »

@opensource
OK.I need,can you just supply the download URL.
Thanks
krs1 (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #12 on: August 17, 2007, 08:23 PM »

@ bakenda
Here is the link to a free download of WAMP

http://www.wampserver.com/en/download.php

enjoy!
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #13 on: August 22, 2007, 12:46 PM »

Kindly help me with this code ,problem is its not returning any value and the databse is well set up.if i don't put a where clause it works but once i put the where clause it doesnt return a value
html code is

<form name="form2" method="post" action="parishlist3.php">
                          <select name="parish">
                            <option>ABARANJE </option>
                            <option>ABORU</option>
                            <option>AJEGUNLE</option>
                            <option>ALAGBADO</option>
                            <option>ALAPERE</option>
                            <option>AMAZING GRACE</option>
                            <option>IKOTUN</option>
                            <option>KETU</option>
                            <option>MAFOLUKU</option>
                            <option>OWODE-ELEDE</option>
                            <option>OWORONSOKI</option>
                            <option>GREAT GRACE</option>
                            <option>LEKKI</option>
                            <option>IJERE</option>
                            <option>ORIGANRIGAN</option>
                          </select>
                          <input type="submit" name="Submit2" value="Submit">
                        </form>


and the php code is


   <?php
// Connects to your Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("upperroo_parishes") or die(mysql_error());
$data = "SELECT * FROM address WHERE name ='$parish'"
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Name:</th> <td>".$info['Name'] . "</td> ";
Print "<th>Address:</th> <td>".$info['Address'] . " </td></tr>";
Print "<th>Pastor-In-Charge:</th> <td>".$info['Head'] . "</td> ";
Print "<th>Phone No:</th> <td>".$info['Contact'] . " </td></tr>";
}
Print "</table>";
?>
segebee (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #14 on: August 22, 2007, 04:14 PM »

$data = "SELECT * FROM address WHERE name ='$parish'"

remove the '' around parish and try it
'' converts variable to value and u have 2 already plus d one at the beginning
xanadu
Re: Php/mysql Programmers, Please Help Me Out !
« #15 on: August 22, 2007, 05:14 PM »

Quote
$data = "SELECT * FROM address WHERE name ='$parish'"

The issue here is: You MUST declare your variables. $parish has no value, because you have not declared it as a variable containing the user's selection - so your query simply is saying 'where $parish =NOTHING'.

Put this code above your select statement:

$parish=$_POST['parish'];

That should work now, because you have basically said: '$parish now contains whatever the user selected'.

Hope it works out for you.

Nb: Nothing wrong with your select statement - the apostrophes are in order. Just declare the $parish variable as above.
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #16 on: August 24, 2007, 12:21 PM »

Hi thanks for ur assistance but its still returning an error on

while($info = mysql_fetch_array( $data ))

any idea!
xanadu
Re: Php/mysql Programmers, Please Help Me Out !
« #17 on: August 25, 2007, 07:52 PM »

no worries - can u paste the actual error thrown up on your screen? Also, did u change the select statement from the one in your earlier post?
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #18 on: August 27, 2007, 10:30 AM »

thats is the error receieved :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/upperroo/public_html/parishlist2.php on line 123

and on checking line 123,it contains

while($info = mysql_fetch_array( $data ))

still beats me
thanks
xanadu
Re: Php/mysql Programmers, Please Help Me Out !
« #19 on: August 28, 2007, 12:32 AM »

Right, thanks for posting the error. Go back to your select statement, and change:

Quote
$data = "SELECT * FROM address WHERE name ='$parish'" or die(mysql_error());


to:

Quote
$data = mysql_query("SELECT * FROM address WHERE name ='$parish'") or die(mysql_error());

That should fix it - goodluck!
ade2kay (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #20 on: August 28, 2007, 09:35 AM »

That still won't work.
The $parish variable still won't work 'because the variable won't be substituted.

use

$data = mysql_query("SELECT * FROM address WHERE name ='{$_POST['parish']}'") or die(mysql_error());

instead of

$data = mysql_query("SELECT * FROM address WHERE name ='$parish'") or die(mysql_error());

that way, u won't need the $parish variable again and your code will work fine.

That error is too small to spend days on.

Hope this helps
xanadu
Re: Php/mysql Programmers, Please Help Me Out !
« #21 on: August 28, 2007, 09:55 AM »

??
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #22 on: August 28, 2007, 10:16 AM »

hi guys it worked like mad.I'm very greatful for u guys assistance.can u give me a link where i can get to read php tutorials online.
ade2kay (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #23 on: August 28, 2007, 11:47 AM »

 Cool Congrats, and keep practising. But i want to know which code worked, because there were many suggestions.
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #24 on: August 28, 2007, 01:34 PM »

Ade,unfortuntately i didnt use ur suggestion,i just edited it as suggested by xandu but i quite appreciate ur contirbution infact i have it written out and put in my collection of php scripts thou rite now i want to include polls on my web page and looking for the material .thanks a lot guys
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #25 on: August 30, 2007, 04:18 PM »

Hi guys,ive got this little challenge again.i created an online poll on my site.ive got two challenges,i want the form for voting to open on a small window while the main page i e the index page remains there ,a thing i want to look into later but right now when I'm running the scripts for the view results page,it returns an error

warning:division by zero on line 59,62,65.any way out.thanks
smartsoft (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #26 on: August 31, 2007, 08:30 PM »

still looking for solutions ?
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #27 on: September 04, 2007, 12:36 PM »

yeah any idea
jitguide
Re: Php/mysql Programmers, Please Help Me Out !
« #28 on: September 04, 2007, 03:49 PM »

can i see your code



Think World class Think Teng pro
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #29 on: September 04, 2007, 04:28 PM »

here is the code,it is for viewing the results of the polls

<?PHP
$question = '';
$answerA = '';
$answerB = '';
$answerC = '';

$imgTagA = '';
$imgWidthA = '0';

$imgTagB = '';
$imgWidthB = '0';

$imgTagC = '';
$imgWidthC = '0';

$imgHeight = '10';
$totalP = '';
$percentA = '';
$percentB = '';
$percentC = '';

$qA = '';
$qB = '';
$qC = '';

if (isset($_GET['Submit2'])) {

      $qNum = $_GET['h1'];

      $user_name = "upperroo_users";
      $password = "preacher";
      $database = "upperroo_surveytest";
      $server = "localhost";

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

      if ($db_found) {

         $SQL = "SELECT * FROM tblquestions, answers WHERE tblquestions.QID = answers.QID AND answers.QID = '$qNum'";
         $result = mysql_query($SQL);
         $db_field = mysql_fetch_assoc($result);

         $question = $db_field['Question'];
         $answerA = $db_field['A'];
         $answerB = $db_field['B'];
         $answerC = $db_field['C'];

         $qA = $db_field['qA'];
         $qB = $db_field['qB'];
         $qC = $db_field['qC'];

         $imgWidthA = $answerA;
         $imgWidthB = $answerB;
         $imgWidthC = $answerC;

$totalP = $answerA + $answerB + $answerC;

$percentA = (($answerA * 100) / $totalP);
$percentA = floor($percentA);

$percentB = (($answerB * 100) / $totalP);
$percentB = floor($percentB);

$percentC = (($answerC * 100) / $totalP);
$percentC = floor($percentC);

$imgWidthA = $percentA * 2;
$imgWidthB = $percentB * 2;
$imgWidthC = $percentC * 2;


         $imgTagA = "<IMG SRC = 'red.jpg' Height = " . $imgHeight . " WIDTH = " . $imgWidthA. ">";
         $imgTagB = "<IMG SRC = 'red.jpg' Height = " . $imgHeight . " WIDTH = " . $imgWidthB . ">";
         $imgTagC = "<IMG SRC = 'red.jpg' Height = " . $imgHeight . " WIDTH = " . $imgWidthC . ">";

         mysql_close($db_handle);


      }
      else {
         print "database error";
      }


}
else {
   print "no results to display";
}
?>
cheavroi (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #30 on: September 07, 2007, 10:00 AM »

Hi found the solution,it was in the way the database was created.thanks for all your contributions
cdeveloper (m)
Re: Php/mysql Programmers, Please Help Me Out !
« #31 on: September 17, 2007, 04:04 PM »

You seem to forget that you are using post as the method of your post and as such you must have to capture the variables at the server like this

$sex=$_POST['sex'];
$var2=$_POST['var2'];
$var3=$_POST['var3'];

then you clean it  for safe storage like this

$sex=strip_tags(trim($sex));
$var2=strip_tags(trim($var2));
$var3=strip_tags(trim($var3));

then you are on your way to storing it in the database

 My Squid Server Is Problem Please Give Me New Configuration  What's new in PHP 5 and PHP 6  The New Haitian Ipod: D  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Job Talk Jobs/Vacancies (2) Career Talk Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.