Jump to content

trouble selecting data and echoing


toolman

Recommended Posts

Hi there,

 

I am trying to select from my database and echo the result.

 

This is what I have:

 

$result = mysql_query("select * from website_settings");
$row = mysql_fetch_array($result);

 

and I am echoing using:

 

<input name="website_name" value="<?php echo $row['website_name']; ?>" type="text" class="input" />

 

But it is not echoing.

 

does anyone know what I have wrong?

Link to comment
https://forums.phpfreaks.com/topic/179095-trouble-selecting-data-and-echoing/
Share on other sites

I see. I noticed my top record is blank.

 

What I am trying to do is to only allow one record which can be updated. However, when I insert another record, it automatically adds a blank record to the top.

 

Any ideas whats going on?

Thank for your help.

I see. i am getting into a bit of a pickle.

 

This is now what I have, but it doesn't seem to be updating.

 

$website_name = $_POST['website_name'];
$sql = "INSERT INTO website_settings VALUES('$website_name')";
mysql_query($sql);


$update = mysql_query("UPDATE website_settings SET website_name = $website_name");

$result = mysql_query("select * from website_settings");
$row = mysql_fetch_array($result);

You should have a primary incrementing key field so that you can identify certain records. Then use a WHERE clause to make sure you're only updating one record (and remove that insert query..). Another problem I see if that you don't have quotes around $website_name in your UPDATE query.

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.