Jump to content

[SOLVED] php wont add data to data mysql base


sandrine

Recommended Posts

hi everyone below are 3 scripts that i got of the internet. the purpose of the php scripts is to add data to mysql data base but it does not even when it says data added. i had the same prob with another php script so i got this new one thinking it was the script at fault but it seems not. can any one help pls. if i add data to the data base via mysql manually it all seems to be rosey but trying to insert data using the php scripts is not working even though the display script seems to work fine if there is data already in the data base.

 

show data display script:

 

<html>
<head>
<title>test php</title>
<head>
<body>
<?php

mysql_connect ("mysql6.000webhost.com", "a3848390_testuse", "sid503051") or die ('i cant conect to the database because: ' .mysql_error() );
mysql_select_db ("a3848390_test");

$query = mysql_query("SELECT * FROM testtable");

while ($row = mysql_fetch_array($query) ) {
echo "<br /> id: " .$row['id']. "<br /> first name: " .$row['fname'].
"<br /> lastname: " .$row['lname']."<br /> phone: " .$row['phone'].
"<br />";}

?>
</body>

 

input form script:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
  <title></title>
</head>
<body>
<form method="post" action="update.php">
first name:<br />
<input type="text" name="fname" size"30" /><br />
last name:<br />
<input type="text" name="lname" size"30" /><br />
phone number:<br />
<input type="text" name="phon" size"12" /><br />
<input type="submit" name="update database" />
</form>
<br>
</body>
</html>

 

 

 

update.php the insert data script:

 

 <?php
$fname = $_post['fname'];
$lname = $_post['lname'];
$phon = $_post['phon'];

mysql_connect("mysql6.000webhost.com", "a3848390_testuse", "sid503051")
or die  ('error: ' . mysql_error());
mysql_select_db ("a3848390_test");

$query="INSERT INTO testtable (id, fname, lname, phon)VALUES('NULL' ,'".$fname."', '".$lname."','".$phon."')";


mysql_query($query) or die ('error');

echo "data updated with: " .$fname. " ".$lname. " ".$phon ;

?>

 

 

one thing i have noticed is when you fill in some personal info on the input.php (input form script above) script and click "update database" i should be presented with a message saying for example "data updated with jo bloggs 0776958588"

but i only get first part of the message i.e "data updated with" and not the other bit with the firstname last name phone num.

 

hope sumone can help  thanks. ???

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.