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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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.

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.