Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Simple php program adding name, doesn't work

Codes here !

Moderators: macek, egami, gesf

Simple php program adding name, doesn't work

Postby ppasternak » Tue Jan 29, 2013 3:41 am

I have the following problem. I need to make a simple code adding name and surname to table. There is no syntax error, but when you click "Add it" page and databes don't change. I'm totally newbie, and i try to fix it for two days ;).
database adress mysql.cba.pl
database name ppasternak_cba_pl
user ppasternak
password podleska1
page ppasternak.cba.pl/mojkatalog/index1.html

There are pages "index1.html" and "index1.php" on ftp server.
<html>
 
 <head>
 <title>Moja pierwsza strona internetowa </title>
 </head>
 
 <body>

<form action="index1.php" method="post" >
<div>
<td>imie:<input type= "text"name="imie"
maxlength="10"size"10"></td>
</tr>
<td>iazwisko:<input type ="text"name="nazwisko"
maxlength="10"size="10"></td>
</div>
</form>
</tr>
<tr>
<td><input type="submit"value="Add it"></td>
</tr>
</table>
</form>
</body>

</html>


<?php

$imie=$_POST['imie'];
$nazwisko=$_POST['nazwisko'];
$polaczenie=@mysql_connect('mysql.cba.pl','ppasternak','podleska1') or die('Brak polaczenia'.mysql_error());
echo"<br/>";
$db =mysql_select_db('ppasternak_cba_pl',$polaczenie)or die ('Nie moge polaczyc sie z baza danych'.mysql_error());
echo"<br/>";
$zapytanie="INSERT INTO'Baza'('Imie','Nazwisko') VALUES('".$imie."','".$nazwisko."')";
$zapytaniea=mysql -query($zapytanie);
if($zapytanie)
{
echo"Dodano do bazy!";
} else{
echo "nie dodano do bazy"; }
mysql_close(polaczenie);
?>


$link = @mysql_connect('localhost', 'uzytkownik', 'haslo')
or die('Brak połączenia z serwerem MySql. <br> Błąd : '.mysql_error());

$db = @sqlect_mysql_db('nazwa_bazy', $link)
or die('Nie mogę połączyć się z bazą danych <br> Błąd : '.mysql_error());

mysql_connect($link);
ppasternak
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Jan 29, 2013 3:29 am

Re: Simple php program adding name, doesn't work

Postby php9 » Fri Feb 22, 2013 2:55 am

You say there's no syntax error in the code, but does mysql_error() show anything at all?
php9
New php-forum User
New php-forum User
 
Posts: 13
Joined: Fri Feb 22, 2013 2:20 am

Re: Simple php program adding name, doesn't work

Postby seandisanti » Fri Mar 01, 2013 12:31 pm

ok, step 1, remove your credentials from your post. you don't need to ever give any kind of username or password for example scripts, and if anyone asks for them, report them or ignore them.

2) what kind of output are you getting? are either of the result strings being echo'd?
3) view source on the index1.php page in your browser after submitting. sometimes errors end up inside of html tags and then don't make it to the page where you'd normally expect them.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 773
Joined: Mon Oct 01, 2012 12:32 pm

Re: Simple php program adding name, doesn't work

Postby NAPSTER35 » Fri Mar 01, 2013 4:17 pm

<!DOCTYPE HTML>
i'm a PHP beginner. What can I do to display Have a great day or Have a great night on my screen?

<html>
<body>

<?php
$x=date ("H");
if ($x<"20")
{
echo "Have a great day!";
}
if else
{
echo "Have a great night!";
}
?>
</body>
</html>
NAPSTER35
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Mar 01, 2013 4:01 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron