Jump to content
Sign in to follow this  
oxy

Pertanyaan Php

Recommended Posts

saya nk tanya kawan kawan...saya nk buat buku tamu je...tapi pening yang ni le...

$connect = mysql_connect("localhost","root","");

mysql_select_db("ikc", $connect);

mysql_query("insert into pengunjung (nama, email, website)

values ('$nama', '$email', '$website')",$connect);

echo "Data telah dimasukkan";

mysql_connect dah oks dan .....mysql_select_db dah oks tapi ada error kat line ---- values ('$nama', '$email', '$website')",$connect);-----ape ek...kalau kawan tau...tolong tunjukkan k

Share this post


Link to post
Share on other sites

dalam linux payah skit . tapi bleh buat ..

kalau guna gini cammana ?

<?php

system ($ lp -d foo1 -o PageSize=Custom.20x30cm file.ps)

?>

wan79.. tlg bagi kod penuh . skali ngan db table ..

fryshadow.. aku rasa better guna webbrowser printer nye function dah la.. guna javascript. buat printerfriendly function.

Share this post


Link to post
Share on other sites

bab sql query tu aku advicekan ko masukkan dalam variable $sql ke baru ko buat mysql_query, senang detect

$sql = "INSERT INTO blabla" ....

echo kan ke browser $sql tu dan test kat terminal ke tengok apa problem dia kat query ke kat connection ke apa ke

Share this post


Link to post
Share on other sites

1.database mysql untuk IKC......mula...id,nama,email,homepage

2.mula-mula aku buat view buku tamu dia dulu...yang ni jadi:-masuk database

<?

$host = 'localhost';// alamat atau host

$user = 'root'; // username

$pass = ""; // password

$connect = mysql_connect("$host","user",$pass);

mysql_select_db("test",$connect);

$query = mysql_query("select * from ikc",$connect);

$jumlah = mysql_num_rows($query);

echo "<center>Daftar ikc</center>";

echo "Jumlah pengunjung : $jumlah";

while($baris

=mysql_fetch_array($query))

{

echo "<br>";

echo $baris[0];

echo "<br>";

echo "Nama : ";

echo $baris[1];

echo "<br>";

echo "Email : ";

echo $baris[2];

echo "<br>";

echo "Homepage :

";

echo $baris[3];

}

?>

3. patuh saya buat input.htm dia pulak

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>

<body>

<form method="post" action="input.php">

<pre>

Nama : <input type="text" name="nama">

Email: <input type="text" name="email">

homepage: <input type="text" name="homepage">

<input type="submit" name="submit" value="kirim"><input type="reset"

name="reset" value="reset">

</pre>

</form>

</body>

</html>

4. aku buat input.phplak....untuk ada link ngan input.htm

<?

$connect = mysql_connect("localhost","root","");

mysql_select_db("ikc", $connect);

mysql_query("insert into pengunjung (nama, email, homepage)

values ('$nama', '$email', '$situs')",$connect);

echo "Data telah dimasukkan";

?>

di sinila jem nya...ada error kat line 7...iaitu kat values ('$nama', '$email', '$situs')",$connect);

kalau view website dia kuar macam ni

Notice: Undefined variable: nama in c:\program files\easyphp1-8\www\blajar\input.php on line 7

Notice: Undefined variable: email in c:\program files\easyphp1-8\www\blajar\input.php on line 7

Notice: Undefined variable: situs in c:\program files\easyphp1-8\www\blajar\input.php on line 7

Data telah dimasukkan

Share this post


Link to post
Share on other sites

actually ko setkan display_errors ke OFF dalam php.ini, data tu dah masuk lerr tu bukan error tapi Notice : kat line 7 dalam code input.php tu ada satu variable takde valuy atau undefine ko check balik kat line 7 tu ...

antara variable tak kena define tu $nama, $email, $situs

Notice: Undefined variable: nama in c:\program files\easyphp1-8\www\blajar\input.php on line 7

Notice: Undefined variable: email in c:\program files\easyphp1-8\www\blajar\input.php on line 7

Notice: Undefined variable: situs in c:\program files\easyphp1-8\www\blajar\input.php on line 7

Edited by ed_thix

Share this post


Link to post
Share on other sites

dekat page yang input kan data ke dalan database should be mcm nie


<?php
//amik data dari form menggunakan method POST
$name = $_POST['name'];
$email= $_POST['email'];
$situs = $_POST['homepage'];

//then baru masuk dlm db

mysql_query ("INSERT INTO pengunjung (name, email, homepage) VALUES ('$name', '$email','$situs')");
?>
[/code] // ako nasihat kan command² nak connect ke databse tue ko buatkan satu file khusus cnth db.php // so nnt dalam page kat atas nie ko just include je cnth include 'db.php'; contoh :
[code]
<?

$host = "localhost";
$username = "root";
$password = "";
$database = "user"; //nama database ko


$new_connection = mysql_connect($host, $username, $password);

if(!$new_connection)
echo "Tak leh connect..";

$auto_db = mysql_select_db($database);

if(!$auto_db)
echo "tak leh connect database $database!";

?>

// disebabkan kuar error tue adalah ko nak guna variable tue $name and so on tapi ko tak declare pon just terus guna sbb tue dia error.

// harap dpat membantu

Edited by FryShadow

Share this post


Link to post
Share on other sites

ok wan79. ko buat dulu .. follow fryshadow punye code.. then kita buat validation plok..

so that bile user masukkan input yang tidak di kehendaki .. input.php akan paparkan error/ralat dan suruh user masukkan data yang betul..

Share this post


Link to post
Share on other sites

yaaa..itu kena wat error handling laks :D

psychoX ako rasa adalah patut gna javscript tue senang sket kan...

harap en.aku / psychoX dapat memberi sedikit tunjuk ajar :D

Share this post


Link to post
Share on other sites

wokey...terima kasih....semua...dah jadi...hehe...alhamdullilah dah paham dah skit skit pahal php ni...tq tq hehe

kena belajar dari kesilapan...dan kesalahan...baru nampak..dah paham....:)

Share this post


Link to post
Share on other sites

memandangkan aku terlepas plot yang menarik.. aku nak nulis gak hahaha (sibuk masukkan linux tadi)

<?
$connect = mysql_connect("localhost","root","");
mysql_select_db("ikc", $connect);
if(isset($nama) && isset($email) && isset($situs))
{
mysql_query("insert into pengunjung (nama, email, homepage)
values ('$nama', '$email', '$situs')",$connect);
echo "Data telah dimasukkan";
}
?>

aku tambah pernyataan if... ni bab error handling kot tak salah aku...

Share this post


Link to post
Share on other sites

halu. aku tgh blaja sprintf ... gune tutorial nih

http://www.zend.com/manual/function.sprintf.php

dan code aku guner ialah

<?php

// define a function
function getCircumference($radius) {
    echo "Circumference of a circle with radius $radius is ".sprintf("%4.2f", (2 * $radius * pi()))."<br />";
}

// call a function with an argument
getCircumference(10);

// call the same function with another argument
getCircumference(20);

?> 
aku cuma nak tau... ape tuh locale aware, dan non-locale aware dan apa beza kedua2 nyer? dan satu lagik yg tak susah
<?php
$n =  43951789;

printf("%%b = '%b'\n", $n); // binary representation

?>
sesapa leh tak explain apa fungsi printf kat atas nih? :rolleyes: pesal bila aku buat camnih (buang satu %) jadi error plaks?
<?php
$n =  43951789;

printf("%b = '%b'\n", $n); // binary representation

?>

Edited by hdr088

Share this post


Link to post
Share on other sites

aku pun tak paham non locale aware ngan locale aware nih.. ..

emm ed_thix, puteranetwork atau 1khz .. mintak sedikit penjelasan dari tuan semua.., sekiranya tuan tuan arif pasal nih..

rasa macam isu berkenaan dengan tanda . (titik) dan tanda , (comma)

Edited by psychoX

Share this post


Link to post
Share on other sites

adeh. aku pasnih kene gie matrik.. x dpt le aku nak sambung blaja php. anyway, thanks to all. so sesapa ada persoalan php yg technical bincang la sini. ada masa nanti leh aku log in putera review apa yang korang studi...

Share this post


Link to post
Share on other sites

adeh. aku pasnih kene gie matrik.. x dpt le aku nak sambung blaja php. anyway, thanks to all.

-sama-sama...

-kat matrix blaja leklok...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...