Jump to content

[SOLVED] I've changed the PHP code and now it doesn't work


Wizard4U

Recommended Posts

Hello everyone, I'm from Croatia:

Problem:

Before I've changed it was :

<? include('konekcija.php'); ?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';

while($red=mysql_fetch_array($rezultat)){
echo 'Ime: <input type="text" name="ime" value="'.$red['Ime'].'" /><br />
	Telefonski broj: <input type="text" name="tel" value="'.$red['Tel'].'" /><br />
	Broj mobitela: <input type="text" name="mobitel" value="'.$red['Mobitel'].'" /><br />
	Broja fax-a: <input type="text" name="fax" value="'.$red['Fax'].'" /><br />
	Email adresa: <input type="text" name="email" value="'.$red['Email'].'" /><br />
	Web adresa: <input type="text" name="web" value="'.$red['Web'].'" /><br />
	Poruka: <input type="text" name="poruka" value="'.$red['Poruka'].'" /><br />';

}

echo '<input type="submit" name="submit" value="Izmijeni!" />
</form>';

?> 


</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];

mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");


echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

 

And now  is:

 

<? include('konekcija.php'); 
include ('FCKeditor/fckeditor.php');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';



while($red=mysql_fetch_array($rezultat)){


	$ime=$red['Ime'];
	$tel=$red['Tel'];
	$mob=$red['Mobitel'];
	$fax=$red['Fax'];
	$email=$red['Email'];
	$web=$red['Web'];
	$poruka=$red['Poruka'];



?> 

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>">
<table border="0" width="700">
<tr>
<td>
	Ime:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $ime;?>"/>
</td>
</tr>
<tr>
<td>
	Telefonski broj:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $tel;?>"/>
</td>
</tr>
<tr>
<td>
	Mobitel:
</td>
<td>
<input type="text" name="naslov" value="<?php echo $mob;?>"/>
</td>
</tr>
<tr>
<td>
	Fax:
</td>
<td>
	<input type="text" name="datum_objave" value="<?php echo $fax;?>"/>
</td>
</tr>
<tr>
<td>
	E-mail:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $email;?>"/>
</td>
</tr>
<tr>
<td>
	Web stranica:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $web;?>"/>
</td>
</tr>
<tr>
<td>
	Poruka:
</td>
<td>

        
        
        <?php
	$editor=new FCKeditor('$poruka');
	$editor->BasePath='FCKeditor/';
	$editor->ToolbarSet='Default';
	$editor->Value=$poruka;
	$editor->Height='200';
	$editor->Create();
	?>
        
</td>
</tr>
<tr>
<td colspan="2">

        <input type="submit" name="submit" value="Izmijeni!" />

</td>
</tr>
</tr>
</table>
</form>
<? } ?>

</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];

mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");


echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

 

 

I've changed because I wanted: Not all HTML to be in PHP, and everything is OK but mow UPDATE doesn't work.

 

Please HELP ME

I am not sure if this helps, tried to look at the differences,

 

noticed

 

<input type="text" name="naslov" value="<?php echo $ime;?>"/>

 

could be changed to....

<?php echo "<input type='text' name='naslov' value='".$ime."' />"; ?>

 

similar to original, I think it might be your quotes "" '', check those

 

also instead of multiple updates run

 

mysql_query("UPDATE kontakti SET Ime='$Ime',Tel='$Tel',Mobitel='$Mobitel',Fax='$Fax'  WHERE id='$id'");

It doesn't work, can you PLEASE edit my code to be allright:

<? include('konekcija.php'); 
include ('FCKeditor/fckeditor.php');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';



while($red=mysql_fetch_array($rezultat)){


	$ime=$red['Ime'];
	$tel=$red['Tel'];
	$mob=$red['Mobitel'];
	$fax=$red['Fax'];
	$email=$red['Email'];
	$web=$red['Web'];
	$poruka=$red['Poruka'];



?> 

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>">
<table border="0" width="700">
<tr>
<td>
	Ime:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $ime;?>"/>
</td>
</tr>
<tr>
<td>
	Telefonski broj:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $tel;?>"/>
</td>
</tr>
<tr>
<td>
	Mobitel:
</td>
<td>
<input type="text" name="naslov" value="<?php echo $mob;?>"/>
</td>
</tr>
<tr>
<td>
	Fax:
</td>
<td>
	<input type="text" name="datum_objave" value="<?php echo $fax;?>"/>
</td>
</tr>
<tr>
<td>
	E-mail:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $email;?>"/>
</td>
</tr>
<tr>
<td>
	Web stranica:
</td>
<td>
	<input type="text" name="naslov" value="<?php echo $web;?>"/>
</td>
</tr>
<tr>
<td>
	Poruka:
</td>
<td>

        
        
        <?php
	$editor=new FCKeditor('$poruka');
	$editor->BasePath='FCKeditor/';
	$editor->ToolbarSet='Default';
	$editor->Value=$poruka;
	$editor->Height='200';
	$editor->Create();
	?>
        
</td>
</tr>
<tr>
<td colspan="2">

        <input type="submit" name="submit" value="Izmijeni!" />

</td>
</tr>
</tr>
</table>
</form>
<? } ?>

</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];

mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");


echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

your input names are being reused. you need to use different input names. Input names become the $_POST names.

Fixed code (I hope):

<? include('konekcija.php'); 
include ('FCKeditor/fckeditor.php');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Izmjena</title>
</head>

<body>
<p><a href="index.php">Početna</a></p>
<p><u><a href="ispis.php">Ispis</a></u></p>
<p><u><a href="izmjena.php">Izmjena</a></u></p>
<p> </p>
<p>  </p>
<?php

if(isset($_GET['id'])){
$id=$_GET['id'];
}
else{
echo "Niste odabrali kojeg kontakta želite izmijeniti!";
}
$rezultat=mysql_query("SELECT * FROM kontakti WHERE id='$id'");

echo '<form action="" method="post">';



while($red=mysql_fetch_array($rezultat)){


	$ime=$red['Ime'];
	$tel=$red['Tel'];
	$mob=$red['Mobitel'];
	$fax=$red['Fax'];
	$email=$red['Email'];
	$web=$red['Web'];
	$poruka=$red['Poruka'];



?> 

<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id;?>">
<table border="0" width="700">
<tr>
<td>
	Ime:
</td>
<td>
	<input type="text" name="ime" value="<?php echo $ime;?>"/>
</td>
</tr>
<tr>
<td>
	Telefonski broj:
</td>
<td>
	<input type="text" name="tel" value="<?php echo $tel;?>"/>
</td>
</tr>
<tr>
<td>
	Mobitel:
</td>
<td>
<input type="text" name="mob" value="<?php echo $mob;?>"/>
</td>
</tr>
<tr>
<td>
	Fax:
</td>
<td>
	<input type="text" name="fax" value="<?php echo $fax;?>"/>
</td>
</tr>
<tr>
<td>
	E-mail:
</td>
<td>
	<input type="text" name="email" value="<?php echo $email;?>"/>
</td>
</tr>
<tr>
<td>
	Web stranica:
</td>
<td>
	<input type="text" name="web" value="<?php echo $web;?>"/>
</td>
</tr>
<tr>
<td>
	Poruka:
</td>
<td>

        
        
        <?php
	$editor=new FCKeditor('$poruka');
	$editor->BasePath='FCKeditor/';
	$editor->ToolbarSet='Default';
	$editor->Value=$poruka;
	$editor->Height='200';
	$editor->Create();
	?>
        
</td>
</tr>
<tr>
<td colspan="2">

        <input type="submit" name="submit" value="Izmijeni!" />

</td>
</tr>
</tr>
</table>
</form>
<? } ?>

</body>
</html>
<?php
if(isset($_POST['submit'])){
$id=$_GET['id'];
$Ime=$_POST['ime'];
$Tel=$_POST['tel'];
$Mobitel=$_POST['mobitel'];
$Fax=$_POST['fax'];
$Email=$_POST['email'];
$Web=$_POST['web'];
$Poruka=$_POST['poruka'];
$sql = "UPDATE `kontakti` SET `Ime`='$Ime', `Tel`='$Tel', Mobitel='$Mobitel', Fax='$Fax', Email='$Email', Web='$Web', Poruka='$Poruka' WHERE id='$id' LIMIT 1;";
mysql_query($sql);
/*
mysql_query("UPDATE kontakti SET Ime='$Ime' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Tel='$Tel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Mobitel='$Mobitel' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Fax='$Fax' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Email='$Email' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Web='$Web' WHERE id='$id'");
mysql_query("UPDATE kontakti SET Poruka='$Poruka' WHERE id='$id'");
*/

echo '<script type="text/javascript">window.location="ispis.php"</script>';

}
?>

There are no php errors in the code, but you should make the query die if there is an error, perhaps you

have something wrong in your query, and you could write it as one query like this:

 

mysql_query("UPDATE kontakti SET Ime='$Ime', Tel='$Tel', Mobitel='$Mobitel', Fax='$Fax',  Email='$Email', Web='$Web', Poruka='$Poruka' WHERE id='$id'");

 

 

Note, before posting to the database you should use mysql_real_escape_string() on your variables too.

 

Mr. Wizard4U, can you please be so kind as to give us an update as to what you have tried to do, as far as fixing your code (other than shoving it at us and asking for a magic wand to be waved)?

 

Because at this point in time, based on your most recent comment, I would suggest seeking a freelancer (please go to freelance forum).  We aren't here to do your work for you. 

doh!. just realized. you need to sanitize the fckeditor output.  Because we are good, and you came to us, you must also be good, so I will let you figure out the code:

        $message_clean1 = str_replace("\'", "'", $_POST['Poruka']);
        $message_clean2 = str_replace('"', "'", $message_clean1);
        $message_clean3 = str_replace("\v", "", $message_clean2);
        $message_clean4 = str_replace("\'", "'", $message_clean3);
$Poruka = $message_clean4;

Mr. Wizard4U, can you please be so kind as to give us an update as to what you have tried to do, as far as fixing your code (other than shoving it at us and asking for a magic wand to be waved)?

 

Because at this point in time, based on your most recent comment, I would suggest seeking a freelancer (please go to freelance forum).  We aren't here to do your work for you. 

Also, I agree. From now on, if you want my help, you'll get it after I get my retainer fee.

Mr. Wizard4U, can you please be so kind as to give us an update as to what you have tried to do, as far as fixing your code (other than shoving it at us and asking for a magic wand to be waved)?

 

Because at this point in time, based on your most recent comment, I would suggest seeking a freelancer (please go to freelance forum).  We aren't here to do your work for you. 

Also, I agree. From now on, if you want my help, you'll get it after I get my retainer fee.

 

Sory but I don't understand this "you'll get it after I get my retainer fee." , can you please explain detailed please?!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.